iOS | Work with SFSafariViewController

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

Using Object Spy with SFSafariViewController

There are 4 possible combinations for objects retrieval in Perfecto:

  1. Non-instrumented, Framework: PerfectoMobile.
  2. Non-instrumented, Framework: Appium.
  3. Hybrid-Instrumented, Framework: Appium.
  4. Hybrid-Instrumented, Framework: PerfectoMobile.

Using options 1-3, the DOM objects will be injected to the appropriate location inside of the native objects tree.

Using option 4, the DOM objects will not be displayed - this is a limitation.

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.

Note:

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").

Caveats

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).

Note:

This functionality is only supported for 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 above, if an objects command (be it an automation or usage of object spy) was performed in an SFSafariViewController in an app which has not been signed with a developer certificate, a device reboot may be required to allow DOM objects interaction in SFSafariViewControllers on apps which have been signed correctly.