Using Appium to Automate Hybrid App

12,446

Solution 1

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);
        }
    }
}

Solution 2

You can use the inspector (Appium GUI) and use the record although it only supports the native parts of your app.

You should look up sample test scripts from the archives: https://github.com/appium/tutorial/tree/master/projects/java_android/src/test/java/appium/tutorial/android this can be helpful tho it is in Java.

Solution 3

For hybrid apps you can use android version above 4.4 in appium mode and for lesser versions you can use "selendroid mode" of appium. For inspecting in selendroid mode use "selendroid inpector" by switching to debug mode of coding and and hitting the URL "yourlocaldomain:8080/inspector" For appium mode you can use the GUI appium on windows or mac for locating the elements.

Share:
12,446
logeyg
Author by

logeyg

musician / software developer

Updated on June 04, 2022

Comments

  • logeyg
    logeyg almost 2 years

    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.

  • logeyg
    logeyg almost 10 years
    ok, sounds good. I'll definitely look into using the inspector. so say I found the elements. Where can I find documentation for what code to use to interact with them?
  • logeyg
    logeyg almost 10 years
    so the syntax for that testing would apply to the hybrid app I want to test? thanks!
  • logeyg
    logeyg almost 10 years
    thanks, this has been the most helpful so far. new problem, have you had any luck with touch actions? I simply need to tap the middle of the screen to dismiss an alert, but am running into a lot of problems. I've been following directions here: github.com/appium/python-client
  • Tim Rasim
    Tim Rasim over 7 years
    I'm attempting the same endeavour and succeed in using xpath. However I want to address elements with a unique identifier (xpath might change when editing the view thus creating maintenance needs in the future) and also avoid opening chrome so the test can be started fully automatic. Do you have new insights into this since last year?