Downloading file from the AUT in a device (iOS/Android)
To access native Visual UI elements in the web application, this command is recommended and vice versa. In this example, you can see storage access alert populating on trying to download any file within the web application in mobile devices. To handle such kind of popups, you need to switch the context from the web (OS) to native and perform click on the "allow" button and then switch the context back to the web browser to continue with the automation of web application.
Solution:
# | Command | Target | Value |
---|---|---|---|
Click on Download button | |||
1 | click | //button[text()="Download PDF"] | |
Switch the context to Native | |||
2 | switchContext | NATIVE_APP | |
Click on Continue on Storage access Popup | |||
3 | click | //android.widget.Button[@text='CONTINUE'] | |
Click on allow on Storage access Popup | |||
4 | click | //android.widget.Button[@text='allow'] | |
Switch the context to Web | |||
5 | switchContext | CHROMIUM | |
Verify the element present in the webpage | |||
6 | assertElementPresent | //h2[@id='headingthree']//i |
Tips, Tricks, Gotchas & Best Practices:
- You can get the context by using the storeContext command to get the context either by storing it in a variable or by giving the direct values. You can use "CHROMIUM" to access the web application elements and "NATIVE_APP" for accessing the native app elements.