Appium only shows NATIVE_APP context on a Cordova App

前端 未结 2 810
忘掉有多难
忘掉有多难 2020-12-30 18:05

I\'m running Appium on Windows to test a Cordova app directly on an Android device. However, when I try to fetch the contexts and switch to the one containing WEBVIEW<

相关标签:
2条回答
  • 2020-12-30 19:05

    Its working. I tried with a different combinations of capabilities and at-last I found the working combination. Use automationName and dont put platformVersion in capabilities.

    final File app = new File(appDir, "HybridSample.apk");
    final DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
    capabilities.setCapability("deviceName", "Android Emulator");
    // capabilities.setCapability("platformVersion", "4.4");
    capabilities.setCapability("automationName", "Selendroid");
    capabilities.setCapability("platformName", "Android");
    capabilities.setCapability("app", app.getAbsolutePath());
    capabilities.setCapability("appPackage", "com.mcc.hybrid"); // Optional
    capabilities.setCapability("appActivity", ".HybridSample"); // Optional
    

    If you inspect server logs, you can also see this. Available contexts: NATIVE_APP,WEBVIEW_0

    That means, you have to switch context as follows.

    for (final String contextName : contextNames) {
      System.out.println(contextName);
      if (contextName.contains("WEBVIEW_0")) {
        driver.context(contextName);
      }
    }
    

    Please note that above settings are for Android version older than 4.4. If you have KitKat or later, just remove automationName. With automationName, it will not work correctly as it returns only NATIVE_APP as available context.

    0 讨论(0)
  • 2020-12-30 19:06

    Did you try to force select of webview? For example in JAVA:

    driver.switchTo().window("WEBVIEW");
    

    I'm also testing cordova app and it is working well.

    0 讨论(0)
提交回复
热议问题