Search code examples
androidcordovaautomated-testshybrid-mobile-appappium

Using Appium to Automate Hybrid App


I am attempting to use Appium to run some automated tests on a hybrid mobile device built using PhoneGap. I am currently trying to get the android version automated.

I am successful at getting the tests to install the .apk onto the emulator, and the application is opened. I am doing this by running a node server (not sure if there are other ways). This is as far as I have been able to get. I am unsure of the next steps I have to take to find elements within my app and assert against them.

I currently am using a python test script because I found an example using python. However, I am up for any language as long as there are resources out there for running tests.

At this point I'm just confused on where to look. The Appium website does not seem to have thorough documentation on commands to use for testing.


Solution

  • I am currently automating a hybrid app using Appium, and there is very little documentation available. However, I have figured out how to get this done by trial and error.

    Prerequisites:

    1) Debug build of your Hybrid App

    2) Use Chrome browser > Tools > Inspect devices - to expose the webview component of the app

    3) You need to use xpath to identify the object at console

    4) While executing your script use switch context as shown below

    if(browser.equalsIgnoreCase("android")){
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability(CapabilityType.BROWSER_NAME,"");
        capabilities.setCapability("deviceName","Android");
        capabilities.setCapability("device","Android");
        capabilities.setCapability("takesScreenshot","true");
        capabilities.setCapability("platformName","Android");
        capabilities.setCapability("platformVersion","4.4.2");
        capabilities.setCapability("appPackage","uk.co.ee.myee");
        capabilities.setCapability("appActivity","uk.co.ee.myee.Launcher");
    
        capabilities.setCapability("udid","989fb005");
    
        driver = new AppiumDriver(new URL("http://0.0.0.0:4723/wd/hub"),capabilities);
        //driver = new AppiumSwipeableDriver(new URL("galaxy_s5_scl23.appkitbox.com:50305"),capabilities);
    
        touch = new TouchAction(driver);
        Set<String> contextNames = driver.getContextHandles();
        for (String contextName : contextNames) {
            System.out.println(contextName);
            if (contextName.contains("WEBVIEW")){
                driver.context(contextName);
            }
        }
    }