Driver-based Appium architecture for testing on iOS

For testing web and hybrid applications, Perfecto supports the driver-based Appium architecture introduced in Appium 1.10. This architecture is fully aligned with local Appium testing.

Benefits

The driver-based Appium architecture comes with the following benefits:

  • Full compatibility with Appium standard

  • Bug fixes and enhancements

  • Unique Perfecto features, such as sensor injection, to complement the Appium feature set

Prerequisites

The driver-based Appium architecture requires the following:

  • XPATH 1.0. Regular expression matching with the matches() function is not supported.

  • Appium client 6.1.0 or later.

Limitations

The following limitations apply:

  • Cross-domain scripting is not supported.

Enable the driver-based Appium architecture

During the transition phase from pre-driver-based Appium architecture (prior to Appium 1.10) to driver-based architecture, you need to select the driver-based architecture explicitly on a per-script basis using the following designated capabilities. These capabilities control the architecture used for both web and hybrid.

If this architecture is already the default in your cloud, you can omit the new capabilities shown in red below. 

Copy

New capabilities for web

capabilities.setCapability("useAppiumForWeb", true);
capabilities.setCapability("browserName","Safari");
Copy

New capabilities for hybrid

capabilities.setCapability("iOSResign", true);
capabilities.setCapability("useAppiumForHybrid", true);
Important: To allow hybrid testing on a cloud device, the app is re-signed with a Perfecto development certificate. Apps using special entitlements that require the original author's certificate may not work as intended after the re-signing process.

Quantum capabilities

When working with a Quantum project, add the following capabilities.

Copy

Quantum | New capabilities for web

<parameter name="perfecto.capabilities.useAppiumForWeb" value="true" />
<parameter name="perfecto.capabilities.browserName" value="Safari" />
Copy
Quantum | New capabilities for hybrid
<parameter name="perfecto.capabilities.useAppiumForHybrid" value="true" />
<parameter name="perfecto.capabilities.iOSResign" value="true" />
Important: To allow hybrid testing on a cloud device, the app is re-signed with a Perfecto development certificate. Apps using special entitlements that require the original author's certificate may not work as intended after the re-signing process.

Alternatively, use the following syntax.

Copy
Quantum | Alternative syntax
<parameter name="perfecto.additional.capabilities" value="{'useAppiumForWeb':true, 'useAppiumForHybrid':true, 'iOSResign':true}" />

Migrate existing Perfecto hybrid scripts to the driver-based architecture

How you migrate existing Perfecto hybrid app automation scripts to the driver-based architecture depends on whether you work with a single WebView or multiple WebView apps.

Single WebView apps

Due to open tabs in Safari, the driver might identify several WebView contexts. However, the implementation automatically uses the old WebView names when looking for a single active WebView, so the commands driver.context("WEBVIEW") and  driver.context("WEBVIEW_1") both work as before. There is no need to search for the correct WebView.

To migrate scripts for single WebView apps:

  1. Change the value of the automationName capability from PerfectoMobile to its default value, Appium. Alternatively, because Appium is the default value, you can remove this capability.

  2. Cancel the instrumentation (there is no need to instrument the tested app). Then fix object locators, if needed, because the tree seen by the script is slightly different.

  3. Add the following capabilities with a value of true (as described above):

    • useAppiumForHybrid

    • iOSResign

Multiple WebView apps

Working with multiple WebView apps requires the use of the Appium capability fullContextList. Getting a list of all  WebViews  using the getContextHandles()  command returns a list similar to the following:

["NATIVE_APP", "WEBVIEW_2", "WEBVIEW_3"]

where each WebView is appended with a non-descriptive number and the order is not guaranteed to be the same with every test run.  When setting the  value of the desired capability fullContextList to true, the  getContexts() command returns the contexts as a JSON string. When parsed, each context is an object that includes:

  • The ID of the WebView
  • The URL that the WebView currently displays
  • The title of the page 

The fullContextList capability is only supported when testing on iOS devices using the driver-based architecture.

To migrate scripts for multiple WebView apps:

  1. Add  the fullContextList capability to the driver and set it to true.

  2. Retrieve the contexts via the getContextHandles() command (in Java, you can then cast each context to Map<String,Object>).

  3. Select the required context by URL or title key and execute a context switch, as shown in the following example: 

    Copy

    WebView selection

    Set<Map<String, Object>> contexts = driver().getContextHandles(); 
    Optional<Map<String, Object>> webView; 
                
    webView = contexts.stream().filter(c -> !c.get("id").equals("NATIVE_APP"))
                        .filter(c -> c.get("title").equals(“EXPECTED_WEBVIEW_TITLE”))
                        .findFirst(); 

    driver().context(webView.get().get("id").toString());