Reputation: 17340
I am using WdAndroid to run automation test on appium for Android. The part where I am getting stuck is that when the app is installed first time, it pops up permission dialog (location permission). I am using below code to accept the permission.
driver.elementById('com.android.packageinstaller:id/permission_allow_button').click()
Once the dialog is gone, I want to click the button of the activity to perform the desired action, using below snippet to achieve that.
const intervalObj = setInterval(() => {
driver.elementById('com.testpackage.testapp:id/testClickButton').click();
clearInterval(intervalObj);
}, 3000);
But above action does not work and I am getting following error in the appium log
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding 'com.testpackage.testapp:id/testClickButton' using 'ID' with the contextId: '' multiple: false [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=com.testpackage.testapp:id/testClickButton] [debug] [AndroidBootstrap] Received command result from bootstrap [HTTP] <-- POST /wd/hub/session/88f58979-f7ff-4d52-b840-e930d4a04804/element 500 116 ms - 164 [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":7,"value":"No element found"}
The automation flow is to accept permission and wait for 3 secs to perform click on button. But this is not happening.
However if I remove the permission alert dialog and then use above snippet to get click on button it works fine. Issue is only happening when dialog is dismissed and automation is not finding the button.
I am writing the automation source code in Node.JS.
Upvotes: 0
Views: 82
Reputation: 578
Can you try sending your app to background just after accepting the dialog? With this you will get focus back for your app
driver.elementById('com.android.packageinstaller:id/permission_allow_button').click()
driver.runAppInBackground(0)
After this you could search again for an element.
There is also a capability for your driver that will auto accept your permissions
capabilities.setCapability("autoGrantPermissions", "true");
Another capability I want to suggest is 'noReset' so those permissions won't be asked everytime you launch the app, just the first time:
capabilities.setCapability("noReset", "true");
Upvotes: 1