我正在为使用 WKWebviews 显示一些数据的 iOS 应用程序创建自动化测试。用户在本机文本字段中键入查询,结果将显示在 web 视图中。问题是在检查 HTML 中的某些预期结构时,我的行为不一致。
这是我期待的 HTML:
<div id="results">
<div class="frame">
<div class="card">
// here my data
</div>
</div>
</div>
在Appium
我检查这三个 div 存在的非常简单的情况下,如下所示:
it("should display results inside the web view", function () {
return driver
.waitForElementByName("Address and Search")
.sendKeys("search query")
.sleep(1000)
.contexts().then(function (contexts) { // get list of available views. Returns array: ["NATIVE_APP","WEBVIEW_1"]
return driver.context(contexts[1]); // choose the webview context
})
.waitForElementById("results", 60000)
.waitForElementByCss(".frame", 60000)
.waitForElementByCss(".card", 60000)
.sleep(3000)
});
每次运行测试时,我都会得到不同的结果:有时它会找到所有元素,有时它只找到第一个元素 ( waitForElementById
),然后找不到任何其他元素。
这是我的配置:
exports.ios93 = {
browserName: '',
'appium-version': '1.4.13',
platformName: 'iOS',
platformVersion: '9.3',
deviceName: 'iPhone 6',
app: undefined // will be set later
};
我尝试通过执行以下操作来解决问题:
切换后添加延迟WEBVIEW
如下:
.context('WEBVIEW_1')
.sleep(25000)
改变窗口如下:
.context('WEBVIEW_1')
.windowHandles()
.then(function(handles) {
driver.window(handles[handles.length-1])
})
但这没有任何效果。
请注意,应用程序的 Android 版本在使用Appium
.