Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any way to automate SFSafariViewController in UI tests?

Is there any way to automate SFSafariViewController? I like the Xcode 7 UI test feature, but it seems it does not support SFSafariViewController automation. Some of the UI flows I am testing require a web browser so the app uses SFSafariViewController to make it safer vs a web view.

like image 230
Bryant Luk Avatar asked Sep 24 '15 13:09

Bryant Luk


1 Answers

If it's similar to launching extensions (currently broken with direct interactions), try tapping the screen at the point where the element you're looking for is:

Example of tapping an action sheet which launches an extension:

func tapElementInActionSheetByPosition(element: XCUIElement!) {
    let tableSize = app.tables.elementBoundByIndex(0).frame.size
    let elementFrame = element.frame

    // get the frame of the cancel button, because it has a real origin point
    let CancelY = app.buttons["Cancel"].frame.origin.y

    // 8 is the standard apple margin between views
    let yCoordinate = CancelY - 8.0 - tableSize.height + elementFrame.midY

    // tap the button at its screen position since tapping a button in the extension picker directly is currently broken
    app.coordinateWithNormalizedOffset(CGVectorMake(elementFrame.midX / tableSize.width, yCoordinate / app.frame.size.height)).tap()
}

Note: You must tap at the XCUIApplication query layer. Tapping the element by position doesn't work.

like image 73
Chase Holland Avatar answered Nov 03 '22 19:11

Chase Holland