【问题标题】:Webview context doesn't show up anymore when testing using Appium使用 Appium 进行测试时,Webview 上下文不再显示
【发布时间】:2021-06-27 22:37:01
【问题描述】:

我正在使用Appiumwebdriverio 创建一个自动化测试:

const wdio = require("webdriverio");

const opts = {
    path: "/wd/hub",
    port: 4723,
    capabilities: {
        platformName: "Android",
        platformVersion: "11",
        deviceName: "Android Emulator",
        app: "/path/to/myapk.apk",
        automationName: "UiAutomator2",
        autoGrantPermissions: true
    }
};

async function main() {
    const driver = await wdio.remote(opts);

    const contexts = await driver.getContexts();
    console.log("Contexts:", contexts);

    await driver.deleteSession();
}

main();

问题

在运行测试时,我可以看到我曾经有两个上下文:

  • NATIVE_APP
  • WEBVIEW_chrome(或类似的,我不记得这里的确切值)

然后我做了一个更改,将上下文切换到 webview,我收到一个关于找不到 chrome 驱动程序的错误。那是我安装它的时候:npm install "appium-chromedriver"

我不知道这是否是让一切都变成babanas的原因,但从那以后,每次我测试时,我只能看到本机上下文,没有更多的webview上下文:(

更多信息

需要指出的是,我已经修改了我的 Android 应用以包含以下内容:

@Override
public void onCreate() {
    super.onCreate();

    WebView.setWebContentsDebuggingEnabled(true);
}

我也可以启动 chrome://inspect 并查看 webview 并检查它。但是在运行测试时,驱动程序看不到 webview 上下文。

为什么?如何解决这个问题?

【问题讨论】:

    标签: selenium-webdriver webdriver selenium-chromedriver appium appium-android


    【解决方案1】:

    原来我需要等待 webview 出现在应用程序中,所以这可行:

    async function main() {
        const driver = await wdio.remote(opts);
    
        // Wait a few seconds so the webview properly loads
        await new Promise(resolve => setTimeout(resolve, 5000));
    
        const contexts = await driver.getContexts();
        console.log("Contexts:", contexts);
    
        await driver.deleteSession();
    }
    

    【讨论】:

      猜你喜欢
      • 2019-06-28
      • 2020-03-07
      • 2014-09-28
      • 1970-01-01
      • 2017-07-19
      • 1970-01-01
      • 2016-12-08
      • 2015-01-04
      • 2015-01-08
      相关资源
      最近更新 更多