I am creating automated tests for an iOS app that uses WKWebviews to display some data. The user types a query into a native text field and results are displayed inside the webview. The problem is that I got inconsistent behaviour when checking some expected structure in the HTML.
Here is the HTML I am expecting:
<div id="results">
<div class="frame">
<div class="card">
// here my data
</div>
</div>
</div>
In Appium
I check the very simple case that these three divs exist as the follows:
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)
});
Every time I run the test I get different results: sometimes it finds all elements, and sometimes it find only the first element (waitForElementById
), then fails to get any further elements.
Here is my configuration:
exports.ios93 = {
browserName: '',
'appium-version': '1.4.13',
platformName: 'iOS',
platformVersion: '9.3',
deviceName: 'iPhone 6',
app: undefined // will be set later
};
I tried to solve the problem by doing the following:
Adding delay after switching to WEBVIEW
as follows:
.context('WEBVIEW_1')
.sleep(25000)
Changing the window as follows:
.context('WEBVIEW_1')
.windowHandles()
.then(function(handles) {
driver.window(handles[handles.length-1])
})
but this didn't have any effect.
Note that the Android version of the app does not have all these problems when testing with Appium
.