iOS | Work with SFSafariViewController

Automating SFSafariViewController components is supported on iOS devices running iOS 10 and later while using the XCUITest automation infrastructure. 

Use of Object Spy with SFSafariViewController

Perfecto offers the following combinations for object retrieval:

  1. Non-instrumented, framework: PerfectoMobile

    DOM objects will be injected to the appropriate location inside of the native objects tree.

  2. Non-instrumented, framework: Appium

    DOM objects will be injected to the appropriate location inside of the native objects tree.

  3. Hybrid-instrumented, framework: Appium

    DOM objects will be injected to the appropriate location inside of the native objects tree.

  4. Hybrid-instrumented, framework: PerfectoMobile

    Limitation with this option: DOM objects will not be displayed.

Hybrid instrumentation in Perfectois required for retrieving DOM objects from Webviews that are embedded within the application. However, due to the way SFSafariViewControllers are constructed, DOM objects are retrieved differently.

Hybrid instrumentation is not required for working with SFSafariViewControllers, and in fact will impair the automation abilities of SFSafariViewControllers (as explained in the caveats section below).

SFSafariViewController automation

To interact with SFSafariViewController objects as DOM objects, make sure to switch to the WEBVIEW context by first executing the command driver.context("WEBVIEW").

Considerations

Only one kind of Webview, either traditional or SFSafariViewController, can be automated given the selected instrumentation option.

  • If the application is hybrid-instrumented:
    • Traditional hybrid objects can be accessed as DOM objects.
    • SFSafariViewController objects might be accessible as native objects (only when using the Appium framework)
  • If the application is not hybrid-instrumented:
    • SFSafariViewController objects can be accessed as DOM objects.
    • Traditional hybrid objects might be accessible as native objects.

Starting from iOS 12.2, due to changes imposed by Apple, automating SFSafariViewControllers requires the app to be signed with a developer certificate. When installing the application, use the "re-sign" functionality to automatically sign the application with an applicable certificate (see Re-sign an application | iOS). Re-signing an application is only supported in hosted clouds.

An alternative to the re-sign option is to add the device's UDID to your application's provisioning profile and install it without the re-signing functionality.

On iOS 12.2 and later, if an object's command (be it an automation or usage of object spy) was performed in a SFSafariViewController in an app that has not been signed with a developer certificate, a device reboot may be required to allow DOM objects interaction in SFSafariViewControllers in apps that have been signed correctly.