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
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.
You don’t have a test app? Don’t worry! Appium provides
pre-compiled test apps for you to get started. You can download the Android app(“api.apk”) from here.
Just note down the location where you download the test app,
you will need it later on.
- 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.
- <dependencies>
- <dependency>
- <groupid>org.seleniumhq.selenium</groupid>
- <artifactid>selenium-java</artifactid>
- <version>2.46.0</version>
- </dependency>
- <dependency>
- <groupid>io.appium</groupid>
- <artifactid>java-client</artifactid>
- <version>3.1.0</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
Loaded using https://gist.github.com/anonymous/89de52e0339bc28c25a4 ...
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.
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.
Hi and thanks for this tutorial!
ReplyDeleteShould pom.xml tags and be replaced with and ?
Hi,
ReplyDeleteThanks for tutuorial. I followed all the steps and when I run this i dont see app on my emulator. Also i run on actual device it didnt show any app here as well. But on console its printing "Hello world".
so what i am doing wrong. I am new to appium/selenium.
Thanks in advance
Can you please share your test script? I will be able to help, once I see what you have done so far.
Delete