Hi,
as a beginner this has me somewhat confused as to how to solve:
Environment: Mac OS X
Appium Version: 1.14.0
WDIO: 5.11.11
Testing against an Android 8.1 simulator
Packages used:
“devDependencies”: {
“@babel/cli”: “^7.4.3”,
“@babel/core”: “^7.4.3”,
“@babel/preset-env”: “^7.4.3”,
“@babel/register”: “^7.4.0”,
“@babel/traverse”: “^7.4.3”,
“@babel/types”: “^7.4.0”,
“@wdio/appium-service”: “^5.11.4”,
“@wdio/cli”: “^5.11.6”,
“@wdio/cucumber-framework”: “^5.11.12”,
“@wdio/jasmine-framework”: “^5.7.8”,
“@wdio/local-runner”: “^5.11.6”,
“@wdio/sauce-service”: “^5.11.1”,
“@wdio/spec-reporter”: “^5.11.6”,
“@wdio/sync”: “^5.7.9”,
“babel-eslint”: “^10.0.1”,
“chai”: “^4.2.0”,
“eslint”: “^5.16.0”,
“eslint-config-standard”: “^12.0.0”,
“eslint-plugin-import”: “^2.14.0”,
“eslint-plugin-node”: “^7.0.1”,
“eslint-plugin-promise”: “^4.1.1”,
“eslint-plugin-standard”: “^4.0.0”,
“eslint-plugin-wdio”: “^5.7.8”,
“node-fetch”: “^2.3.0”,
“webdriverio”: “^5.7.12”
}
I’ve been using the Appium-boilerplate repository to determine rewrite some the tests using cucumber JS (they were in Jasmine form) so that I can get used to writing things that way.
Now I am starting on our company’s mobile application which is implemented using React Native. The majority of user interaction is through the native app but a login is implemented as a Chrome/Safari window for Android and iOS respectively. So at the start of our native app the Welcome screen has a couple of buttons which open a login URL or register URL on the Chrome/Safari browser. When the username and password are submitted the native app gets an authorisation token posted back to it that allows it to carry on (and dismisses the Chrome browser app at the same time).
If I call driver.getContexts() I see something like [‘NATIVE_APP’, ‘WEBVIEW_chrome’, ‘WEBVIEW_com.blahfoo.blahbar’] but if I subsequently try and driver.setContext() with either of the web views then the automation code just sits at this point and times out. It does not always show these three contexts returned; sometimes WEBVIEW_chrome or WEBVIEW_com.blahfoo.blahbar only but most of the time both are returned in addition to NATIVE_APP.
If I don’t driver.setContext() but instead attempt to interact with the Chrome page directly (which is the app that has focus now) I can see that driver.getCurrentActivity() returns org.chromium.chrome.browser.customtabs.CustomTabActivity but when I try and interact with the browser page in an attempt to interact with the Email ID on the Chrome browser login page using:
const user = browser.findElement(‘xpath’, ‘/html/body/div/div/div[2]/div/div[2]/div/div/form/div[1]/div/input’);
I get the following error:
[0-0] 2019-08-09T01:49:18.545Z INFO webdriver: COMMAND findElement(“xpath”, “/html/body/div/div/div[2]/div/div[2]/div/div/form/div[1]/div/input”)
[0-0] 2019-08-09T01:49:18.545Z INFO webdriver: [POST] http://127.0.0.1:4723/wd/hub/session/34e7b3fe-ba3f-49e3-b5f1-5d8883f6b933/element
[0-0] 2019-08-09T01:49:18.546Z INFO webdriver: DATA { using: ‘xpath’,
value:
‘/html/body/div/div/div[2]/div/div[2]/div/div/form/div[1]/div/input’ }
[0-0] 2019-08-09T01:49:19.085Z INFO webdriver: RESULT { error: ‘no such element’,
message:
‘An element could not be located on the page using the given search parameters.’,
stacktrace:
‘NoSuchElementError: An element could not be located on the page using the given search parameters.\n at AndroidUiautomator2Driver.helpers.findElOrEls (/usr/local/lib/node_modules/appium/node_modules/appium-android-driver/lib/commands/find.js:75:11)’ }
What is the accepted approach to automating this kind of behaviour? It doesn’t appear to behave as a webview that is embedded in an app so it doesn’t sound like switching from native to web to native context is the way to do it.
What am I missing here?
Thanks for any hints or insights.
Derek Wong.
PS - for the same React Native app this will eventually need to work on iOS as well although I’d be keen just to get this going on Android right now.