Hello friends,

I work as a software test engineer already more than 6 years. And during these 5 years, I understood one thing – if You want to start to learn something new from the beginning, then You will Google for it. And as a result – You will find a lot of information without examples and simple explanation or You will find nothing at all, except some raw documentation.

I found that topics about mobile automation sometimes scare the people. So, I want to reveal the myths about mobile automation.

This article describes the simplest way of how to setup and run Your first test. An example is based on Appium 1.5.3 and Android system. It’s not about advanced usage of the latest version, etc.

What You need for starting with mobile automation

There are few thing that You need to have.

  1. Computer. MacBook is preferable to perform automation testing for iOS also.
  2. Pre-installed Android SDK or Android Studio is even better. Download here.
  3. Configured environment like for Selenium WEB testing.
  4. Appium desktop application latest version (1.5.3). Download here.

Base configuration

After downloading of Android Studio and setup of Android SDK You need to add the path to the folder with android SDK to the PATH of environments.

Run 1st test

  1. Create simple maven project in Eclipse or IntelliJ
  2. Add Appium dependency:
    <dependency>
        <groupId>io.appium</groupId>
        <artifactId>java-client</artifactId>
        <version>2.2.0</version>
    </dependency>
  3. Download test application that is used as an example. You can find it here or on Play Store here
  4. Create test class based on JUnit test framework and past the code inside:
    public class PresentationTest {
    
        private static final String MYREACTIONS_ID = "com.denyszaiats.myreactions:id/";
        protected static DesiredCapabilities capabilities;
    
        @Test
        public void testPresentationTapGame() throws InterruptedException, MalformedURLException {
            capabilities = new DesiredCapabilities();
            capabilities.setCapability("platformName", "Android");
            capabilities.setCapability("platformVersion", "6.0");
            capabilities.setCapability("deviceName", "emulator-5554");
            capabilities.setCapability("app", {PATH_TO_APK_FILE});
            AppiumDriver driver = new AndroidDriver(
                    new URL("http://0.0.0.0:4723/wd/hub"),
                    capabilities
            );
            driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
            driver.findElementById(MYREACTIONS_ID + "imageLangEn").click();
            driver.findElementById(MYREACTIONS_ID + "skip_login_button").click();
            driver.findElementById(MYREACTIONS_ID + "buttonGuideOk").click();
            driver.findElementById("android:id/home").click();
            driver.findElementById("android:id/home").click();
            driver.findElementByXPath("//*[@text='Crazy Fingers']").click();
            driver.findElementById(MYREACTIONS_ID + "buttonGuideOk").click();
            driver.findElementById(MYREACTIONS_ID + "handButton").click();
            driver.findElementById(MYREACTIONS_ID + "imageRightHand").click();
            driver.findElementById(MYREACTIONS_ID + "fingerButton").click();
            driver.findElementById(MYREACTIONS_ID + "imageIndexFinger").click();
            driver.findElementById(MYREACTIONS_ID + "startButton").click();
            WebElement tapButton = driver.findElementById(MYREACTIONS_ID + "imageTapButton");
            int x = tapButton.getLocation().x + 50;
            int y = tapButton.getLocation().y + 50;
            for (int i = 0; i < 350; i++) {
                driver.tap(1, x, y, 1);
            }
            String result = driver.findElementById(MYREACTIONS_ID + "resultsFasterClicker").getText();
            assertEquals(result, "350");
        }
    }
  5. Open Android simulator. Or create a new Android simulator. Or connect  Your Android test device. Do not forget to enable developer mode on Your real device.
  6. Open Appium desktop app and start it. Wait few seconds before Appium is ready to use. Run the test with JUnit.

 

This is it. Just several simple steps to run the simplest scenario with Appium.

I hope that now You’re confident with mobile automation and You know how to start with it.

Thanks for reading this article!