Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 975
logeyg Avatar asked Jan 10 '23 02:01

logeyg


2 Answers

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);
        }
    }
}
like image 119
user3000021 Avatar answered Jan 18 '23 13:01

user3000021


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.

like image 36
SthQA Avatar answered Jan 18 '23 15:01

SthQA