【发布时间】:2020-07-14 19:04:59
【问题描述】:
我在尝试测试 iOS 应用程序时遇到了 webdriverio/appium 的一个奇怪问题。该应用程序有一个带有标记为“刷新”的按钮的 WebView。当我尝试测试此按钮时,我收到“未显示”错误(请参阅下面的代码)。
it('should have the Refresh button', () => {
WebViewScreen.waitForWebsiteLoaded();
// Verify that Refresh button is displayed
WebViewScreen.switchToContext(CONTEXT_REF.WEBVIEW);
const button = $('button=Refresh');
expect(button).toBeDisplayed();
WebViewScreen.switchToContext(CONTEXT_REF.NATIVE);
});
请注意,在测试按钮之前,我将上下文切换到 WEBVIEW。查看 Appium 日志,查找按钮 ($('button=Refresh')) 的请求返回 404。尝试了不同的选择器:['button[data-test="refresh-button"]'],但没有成功。我什至放了一个 browser.debug() 并在 REPL 中查询 - 仍然是 404 - 虽然我可以在屏幕上实际看到按钮!
我知道我的 webdriverio/appium 设置很好,因为完全相同的代码适用于另一个带有 WebView 和按钮的 iOS 屏幕 - 唯一的区别是按钮名称。
我还通过转到独立网页并测试该按钮排除了我的选择器不正确的可能性 - 在这种情况下没有错误!这是独立的网页代码 - 唯一的区别是没有上下文切换调用:
it('should have the Refresh button', () => {
browser.url('https://example.site.com/');
// Verify that Refresh button is displayed
const button = $('button=Refresh')
expect(button).toBeDisplayed();
});
关于如何调试它的任何想法?切换到 WEBVIEW 上下文是否有我遗漏的任何细微差别?
【问题讨论】:
标签: appium webdriver-io appium-ios