简体   繁体   中英

Can't switch context with Appium for Cordova hybrid app on Android 7

[Appium 1.7.1] [Android 7.0] [Java] [Hybrid App] [Cordova] I tried with following logic to switch context, it's working with another Android OS like 5.1.1 but it's not useful for android 7.0. I am not able to focus on native app after context from webview.

Set<String> availableContexts = driver.getContextHandles();

// switch to Web-view
   for(String context : availableContexts) {
     if(context.contains("WEBVIEW")){
        logger.info("Context Name is " + context);
        driver.context(context);
        break;
     }
   }

// switch to Native app
    for(String context : availableContexts) {
        if(context.contains("NATIVE")){
            logger.info("We are Back to " + context);
            driver.context(context);
            logger.info("Context Switched");
        }
    } 

There is not much to say without seeing appium server logs.

When you face such kind of issues (stopped working with new OS version update, new Appium server release, etc.) I recommend to print output of driver.getContextHandles() and see what you get.

Its not the first issue with Appium+Cordova and not available to switch context. If you will find out that you don't get NAVIVE_APP context, then you better report issue to appium server project

After switching from web-view, I have kept the application in background for a while as per following, and then resumes execution:

driver.runAppInBackground(Duration.ofSeconds(1)); 

This is now resolved for issue faced while switching context view from web-view to native view.

please suggest someone have the better approach.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM