How to automate UI tests for Safari View Controller?

Hi all!

We have been using appium for testing both iOS as well as Android applications.

Regarding iOS, is there some work being done to handle Safari View Controller? Or is there some pre-existing way to automate stuff for them? (Similar to Mobile Safari)

Your help would be extremely appreciated.

Thanks in advance.

I would be interested in learning more about this well. I’ve currently hit a snag in automating an iOS app. It appears to be an error happening because the app has opened a Safari View Controller.

I have exactly the same issue. Has anyone solved this matter?

Hi Everyone,

Did anyone manage to find a solution to this. If so please suggest.

@Appium team, we are currently implementing tests in a big application with several Safari View Controllers. Why is there no support yet?

Hi there, although testing of safari view controllers might not be officially supported by Appium, I managed to create a filthy workaround for Xcode 8 AND Xcode 9 safari view controller.

Let’s say I want to fill in a UITextField in bei safariVC:

Xcode 8 / iOS 10: you can actually retrieve the coordinates of the requested element from the view tree like this (for example by xpath) and send

MobileElement myTextField = (MobileElement)driver.findElementByXpath(“myXpathToElement”);
Point elementPoint = myTextField.getCoordinates().inViewPort();
(new TouchAction(driver)).tap(elementPoint.x + 10, elementPoint.y + 10).perform();
myTextField.sendKeys(“Hello World”);

Xcode 9 / iOS 11: you have no access to the desired UI element in the view tree, therefore you need to have
to hardcode the coordinates of the desired mobile element for every device screen type and send the keys to a XCUIElementTypeOther element, with which interactions are available. It is recommended to try out all XCUIElementOther-candidates in Appium inspector mode in order to find the “correct one”. If it works in inspector, it will work in your step defintion :wink:

MobileElement otherElement = (MobileElement) driver.findElementByXpath("//XCUIElementTypeApplication[@name=“MyApplicationName”]/XCUIElementTypeWindow[2]/XCUIElementTypeOther);
(new TouchAction(driver)).tap(200, 250).perform();
otherElement.sendKeys(“Hello World”);

Happy coding!