BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Apple Adds Native W3C WebDriver Support to iOS

Apple Adds Native W3C WebDriver Support to iOS

With the release of iOS 13, Apple now includes native iOS W3C WebDriver support. Beyond previous support for WebDriver added in Safari 10, WebDriver can now easily be used for testing mobile Safari web applications efficiently.

While it was previously possible to use WebDriver with iOS Safari via the iOS simulator or various cloud-based testing providers, the native WebDriver support provides additional testing features as well as a better mobile UI testing experience.

The native WebDriver API provides safeguards against malicious code as well as flaky tests. The Safari WebDriver implementation restricts browsing in WebDriver sessions. Tests get isolated within a separate set of windows, tabs, preferences, and persistent storage, existing tabs get hidden, and a distinctively-colored WebDriver window gets shown with an orange Smart Search field. This approach helps both with security and privacy, as well as ensuring that tests do not get influenced by previous sessions. Upon test completion, any local state such as cookies get deleted.

To prevent unintended user interaction during automated test sessions, Safari adds a pane over the automation browser window, blocking any interactions. If a running test gets stuck or fails, the developer can tap on the screen and choose to end the WebDriver session. WebDriver-initiated navigations cannot be handled outside of Safari. For example, clicking an app store link will not redirect to the App Store.

To begin working with the WebDriver support on macOS devices running Safari 13 or newer versions, developers need to run safaridriver --enable and authenticate as an administrator. Then on the iOS devices for testing, developers need to enable Remote Automation (Settings → Safari → Advanced → Remote Automation). Developers then need to plug in their iOS device into the macOS host, trust the host, and unlock the iOS device when starting a WebDriver session.

The WebDriver configuration should include 'platformName': 'ios'; to differentiate between running iOS simulator or the native macOS test. To use the iOS simulator for testing, add the capability 'safari:useSimulator': true.

WebDriver for iOS is available with iOS 13 and newer versions and requires a macOS host running Safari 13 or later.

Rate this Article

Adoption
Style

BT