首页 > 解决方案 > UnsupportedCommandException:使用 Appium 的混合 Android 应用程序尚未实现方法错误

问题描述

我正在使用 Appium 为混合 Android 应用程序编写自动化测试用例。我正在使用下面的代码行将光标设置在下拉/弹出窗口上:

Set<String> stringSet =  webDriver.getWindowHandles();

但是,这会产生以下错误:

org.openqa.selenium.UnsupportedCommandException: Method has not yet been implemented.

webdriverAppiumDriver的对象。

这是一个混合(Cordova)移动应用程序

我的堆栈跟踪:

Apr 03, 2019 4:20:21 PM org.openqa.selenium.remote.ErrorCodes toStatus
INFO: HTTP Status: '404' -> incorrect JSON status mapping for 'unknown method' (405 expected)

org.openqa.selenium.UnsupportedCommandException: Method has not yet been implemented
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'VIKSHAH-M-F1AR', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.3', java.version: '1.8.0_152-release'
Driver info: io.appium.java_client.AppiumDriver

更新:更新 JDK 后

Apr 10, 2019 12:47:45 PM org.openqa.selenium.remote.ErrorCodes toStatus
INFO: HTTP Status: '404' -> incorrect JSON status mapping for 'unknown method' (405 expected)

org.openqa.selenium.UnsupportedCommandException: Method has not yet been implemented
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'VIKSHAH2-M-F1AR', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.3', java.version: '1.8.0_202'
Driver info: io.appium.java_client.android.AndroidDriver

有没有人遇到过类似的问题?有没有其他方法可以使用 Appium 测试下拉?

标签: javaseleniumappiumhybrid-mobile-appappium-android

解决方案


下面是我用来从可用上下文切换到第一个 Web 视图(非本机视图)的代码。如果您不确定上下文文本实际包含什么,请编写代码来捕获数组并显示所有值。

@Nullable
private String getWebContext() {
    ArrayList<String> contexts = new ArrayList<String>(driver.getContextHandles());
    for (String context : contexts) {
        if (!context.equals("NATIVE_APP")) {
            return context;
        }
    }
    return null;
}

推荐阅读