Reputation: 16845
I am creating an automation test using Appium and webdriverio:
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();
When running tests I could see that I used to have two contexts:
NATIVE_APP
WEBVIEW_chrome
(or similar, I do not remember exactly the value here)I then made a change which switched contexts to the webview, there I got an error about the chrome driver not being found. That is when I installed it: npm install "appium-chromedriver"
.
I do not know if this is what made everything go babanas, but since then, everytime I test, I can only see the native context, no more webview context :(
It is important to point out that I have modified my Android app to include this:
@Override
public void onCreate() {
super.onCreate();
WebView.setWebContentsDebuggingEnabled(true);
}
I can also start chrome://inspect
and see the webview is there and even inspect it. But when running tests, the driver cannot see the webview context.
Why? How to fix this?
Upvotes: 0
Views: 1417
Reputation: 16845
Turns out that I need to wait for a webview to show up in the app, so this works:
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();
}
Upvotes: 1