Apart from the capability I have mentioned above, some more things can be done by you.
Here is what you need to do:
Set autoAcceptAlerts
to true
. This capability will automatically accept any alerts from the app. However, the alert that the user is getting is from the native app (i.e., Safari browser). This pop-up needs to be handled with a different logic, which is described in the next point.
This is what his capabilities should look like:
capabilities.setCapability("deviceName", "iPhone.*"); capabilities.setCapability("platformVersion", "15"); capabilities.setCapability("platformName", "ios"); capabilities.setCapability("isRealMobile", true); capabilities.setCapability("video", true); capabilities.setCapability("visual", true); capabilities.setCapability("network", true); capabilities.setCapability("devicelog", true); capabilities.setCapability("autoAcceptAlerts", true);
Handling location (i.e., allow once)
pop-up from the Safari browser.
Since this pop-up is a part of the web view, you need to first switch the context in the Appium script & then accept the pop-up.
Below is the solution that also worked:
Step 1 - [Mandatory] Get all the contexts
Set<String> contextNames = driver.getContextHandles(); for (String contextName : contextNames) { System.out.println("Available contexts: " + contextName); }
Step 2 - [Optional] - Print the current context
Step 3 - [Mandatory] Switch to Native App context
driver.context((String) contextNames.toArray()[0]); String nativeContext = driver.getContext(); System.out.println("Switched to context: " + nativeContext);
Step 4 - [Mandatory] Now accept the pop-up by locating using the appropriate locator (User needs to change as per the requirement, though this should ideally work :))
// Change to XCUIElementTypeButton if XCUIElementTypeAlert does not work! driver.findElement(By.xpath("//XCUIElementTypeAlert[@name='Allow Once']")).click();
Step 5 - [Mandatory] Switch back to the older context
driver.context((String) contextNames.toArray()[1]); String webviewContext = driver.getContext();
You can refine the code as per the requirements.
Hope this helps @saanvi.savlani