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
Writing first Android test using Appium-Creating project
    1. You will see your project in Eclipse
    2. In your project, open pom.xml and add the following dependencies
        <dependencies>
            <dependency>
      1. <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>
    3. Right click on your project name and select New > Folder and name it as “apps
    4. Copy the android application you downloaded and paste it in the apps folder, you just created.
    5. Delete the default “AppTest.java” file under src/test/java
    6. Right click package name and select New > class
    7. Name the class “FirstAppiumTest” and click “Finish
    1. Paste the following content to the newly created class
Loaded using https://gist.github.com/anonymous/89de52e0339bc28c25a4
    1. Start and launch your AVD (emulator) that you have created
    2. Start and launch your Appium Server
    3. Right click on newly created class “FirstAppiumTest” and Select Run As > Java Application
  1. 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.

3 thoughts on “Writing first Android test using Appium

  1. Unknown Reply

    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

Leave a Reply

Your email address will not be published. Required fields are marked *