In this post we will see how to write an automated test for Android using Appium in JAVA. We presume you have all the necessary setup already done. If NOT, you can get the setup done and then continue writing the test.
Before writing our first test, you should have the following prerequisite in place
- JDK Installed
- Android SDK Installed
- Appium Server
- Eclipse IDE and maven plugin installed
- Actual Android app to be tested.
- Start eclipse (by double clicking the eclipse.exe in the eclipse folder or by the desktop shortcut, you might have created!)
- Click on File > New > Other >
- Select Maven > Maven project in the wizard (If you don’t see Maven, it means your maven plugin is NOT properly installed)
- Select the Workspace location (if you want a particular Workspace) or let it be default and click Next
- Select Artifact Id = maven-archetype-quickstart and click Next
- Enter Group Id and Artifact Id (Artifact Id will be your project name) and click Finish
- You will see your project in Eclipse
- In your project, open pom.xml and add the following dependencies
- Right click on your project name and select New > Folder and name it as “apps”
- Copy the android application you downloaded and paste it in the apps folder, you just created.
- Delete the default “AppTest.java” file under src/test/java
- Right click package name and select New > class
- Name the class “FirstAppiumTest” and click “Finish”
- Paste the following content to the newly created class
- Start and launch your AVD (emulator) that you have created
- Start and launch your Appium Server
- Right click on newly created class “FirstAppiumTest” and Select Run As > Java Application
- If you have configured everything properly you will see that in a few seconds, the app will be launched in the emulator and after 5 seconds the app closes itself.
Congratulations!! You have successfully written and executed your first test using Appium!
There will be a lot of activity going on in your Appium console window. We will understand about it in more details in coming posts.
Each line of code is explained with a proper comment above it. If the code doesn’t load here, you can see it here – https://gist.github.com/anonymous/89de52e0339bc28c25a4
In coming posts we will add some more meaningful tests and take this first test to next leve.
Hope you enjoyed the article. If you liked the article, don’t forget to share or comment.