Writing first Android test using Appium

 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
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.
  1. Start eclipse (by double clicking the eclipse.exe in the eclipse folder or by the desktop shortcut, you might have created!)
  2. Click on File > New > Other >
  3. Select Maven > Maven project in the wizard (If you don’t see Maven, it means your maven plugin is NOT properly installed)
  4. Select the Workspace location (if you want a particular Workspace) or let it be default and click Next
  5. Select Artifact Id = maven-archetype-quickstart and click Next
  6. Enter Group Id and Artifact Id (Artifact Id will be your project name) and click Finish
  7. You will see your project in Eclipse
  8. In your project, open pom.xml and add the following dependencies
    1. <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>
  9. Right click on your project name and select New > Folder and name it as “apps
  10. Copy the android application you downloaded and paste it in the apps folder, you just created.
  11. Delete the default “AppTest.java” file under src/test/java
  12. Right click package name and select New > class
  13. Name the class “FirstAppiumTest” and click “Finish
  14. Paste the following content to the newly created class
  15. Loaded using https://gist.github.com/anonymous/89de52e0339bc28c25a4 ...
  16. Start and launch your AVD (emulator) that you have created
  17. Start and launch your Appium Server
  18. Right click on newly created class “FirstAppiumTest” and Select Run As > Java Application
  19. 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.

Comments

  1. Hi and thanks for this tutorial!

    Should pom.xml tags and be replaced with and ?

    ReplyDelete
  2. Hi,

    Thanks 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

    ReplyDelete
    Replies
    1. Can you please share your test script? I will be able to help, once I see what you have done so far.

      Delete

Post a Comment

Popular posts from this blog

Start & Stop Appium Server Programmatically using Java (MAC OSX)

Sending keyboard input via ADB to your android device