javanode.jsseleniumappiumselendroid

Steps to run web application automation using Appium


I am having a lot of trouble trying to get my automated tests to run through a physical Android device using appium. I am not so good with using cmd and configuring and there are very little tutorials on setting it up to run web apps. Heres what i have

  1. Intellij automation project coded in Java. Tests are ran through testng xml files and synced up to browserstack.
  2. I have downloaded Appium.
  3. I have set up ANDROID_HOME variable in my path
  4. I have hooked up a device and can see it when I enter adb devices

I think I have most everything I need, but I dont know the steps to take or how to alter the desired capabilities to run it through my phone! Please, I know this is a broad question but if someone can shed some insight as to how to make this happen I would be forever grateful. Thanks! Below is an example of how I have my tests set up in the xml file.

<test name="Standard Ad Regression">
    <parameter name="browserName" value="Android"/>
    <parameter name="device" value="Samsung Galaxy S5"/>
    <parameter name="emulator" value="true"/>
    <parameter name="browser_version" value=""/>
    <parameter name="platform" value="ANDROID"/>
    <parameter name="local" value="true"/>
    <parameter name="baseUrl" value="https://mywebsite.com/"/>
    <parameter name="os" value="os"/>
    <parameter name="os_version" value="4.4"/>
    <parameter name="resolution" value="1024x768"/>
    <parameter name="bsAccount" value="http://myusername:BcB9786AAvEoa45Fj@hub.browserstack.com/wd/hub"/>
    <classes>
        <class name="com.testsuites.regression.TestThis"/>
    </classes>
</test>

Solution

  • This is a pretty general question, but I have done pretty much exactly what you are attempting to do.

    1. Add Selenium and Appium Jars to Java Project
    2. Write your Java test scripts and initialise AndroidDriver:

    I'm using a separate method to get the driver. The reason I did this is so when I expanded my testing to run in parallel I did not need to redesign.

        public static AndroidDriver getDriver(String udid) throws MalformedURLException{
    
        String URL = "XXXX";
        ThreadLocal<AndroidDriver> driver = null;  
    
        DesiredCapabilities capabilities = new DesiredCapabilities();       
        capabilities.setCapability("device", udid);
        capabilities.setCapability("deviceName", udid);
        capabilities.setCapability("udid", udid);
        capabilities.setPlatform(Platform.ANDROID);
        capabilities.setCapability("browserName", "Chrome");    
    
        try {
            driver = new ThreadLocal<AndroidDriver>();
            driver.set(new AndroidDriver(new URL(URL),
                    capabilities));
        } catch (MalformedURLException e) {
            System.out.println("Tackle Issue with RemoteDriverSetup");
        }
        driver.get().manage().timeouts()
                .pageLoadTimeout(20L, TimeUnit.SECONDS);
        driver.get().manage().timeouts()
                .implicitlyWait(20L, TimeUnit.SECONDS);
    
        return driver.get();
        }
    
    1. Create your testNG.xml

    I am only passing the device's UDID through this file, I see you are using multiple parameters which is also fine.

    <?xml version="1.0" encoding="UTF-8"?>
        <suite name="Suite" parallel="false">
            <test name="Nexus 7">
                <parameter name="udid"  value="XXXX" />
                <classes>
                    <class name="testNG.TestOne"/>
                </classes>
            </test> <!-- Test -->
       </suite> <!-- Suite -->
    
    1. Start Appium Server

    Using the GUI you just need to press the button, make sure the URL used is the same one used to initialise the AndroidDriver.

    1. Right click on testNG and run as Test Suite.

    If you have any problems, run Appium doctor and make sure everything is installed correctly.

    Hope this helps,

    Liam