We all know that Google Chrome is the most popular browser in the world. But did you know that Safari is the second most popular, with 17.24% of the overall browser market share?
Safari’s strong presence is because it is the default web browser for all Apple devices. Since developers and coders love macOS, ensuring that Safari for browsers websites are tested and optimized for all Safari versions is essential.
The latest versions of Safari (10 and above) include Safari Driver, an in-built tool for website debugging. However, earlier versions required the Safari WebDriver extension, which is no longer supported. Safari now uses Safari Driver to implement the WebDriver protocol. Those preparing for interviews can learn more through Selenium interview questions.
In this blog, we will explore how to use Selenium safaridriver to perform testing on the Safari browser online.
To use the Selenium framework for automation testing, you must have the corresponding Selenium WebDriver installed on your machine (e.g., Chrome WebDriver for Chrome, Geckodriver for Firefox). Learn more about what Selenium is and its importance. However, when performing Selenium automation testing with Safari on macOS, there’s no need to download the Safari driver separately.
Starting with Safari 10 on OS X El Capitan and macOS Sierra, the browser provides native support for the Selenium WebDriver API. Since the Selenium Safari driver for macOS is preloaded, you don’t need to specify the executable path when creating the Selenium WebDriver object.
Safari’s built-in driver, safaridriver, is now available in most Selenium client libraries and is maintained by Apple’s web developer experience team. The path for Apple’s safaridriver executable is /usr/bin/safaridriver. Safari Technology Preview also has its safaridriver executable within the application’s bundled contents.
Both the safaridriver from Safari and Safari Technology Preview can run simultaneously, as each one only launches the specific Safari browser it is associated with.
The legacy SafariDriver, maintained by the Selenium project, is deprecated and should not be used. Attempting to install the deprecated Selenium WebDriver for Safari will result in the error ‘Safari no longer supports unsafe extensions.’
For automation testing using Selenium safaridriver, you only need Safari 10 (or later) installed on your machine, as these versions natively support the Selenium WebDriver API.
Starting with the Selenium 3.0.0 release, the Python and Java Client libraries support Safari’s native driver implementation.
Although Safari 10 and later versions natively support the Selenium WebDriver API, this support is disabled by default. To enable WebDriver support in Safari, follow these steps:
Since we will use Apple’s safaridriver for Selenium test automation on macOS Catalina, we need to execute /usr/bin/safaridriver –enable (or safaridriver –enable) once in the terminal.
To support WebDriver while maintaining user privacy and security, additional safeguards are in place to ensure that Selenium test execution is fully isolated from regular browsing data and other test runs.
Here are some key features of the Selenium Safari driver on macOS:
Apple’s web developer team has designed safaridriver to ensure that test execution and Selenium test automation scenarios are restricted to special automation windows. This means that tests run using safaridriver are separated from regular browsing windows, user settings, and preferences.
Similar to automation testing with geckodriver (for Firefox), Safari windows used for tests can be identified by their orange Smart Search field.
Automation tests using Apple’s safaridriver begin like a private browsing session in Safari, starting fresh each time to ensure that the previous test session’s persistent state does not affect the newly initiated Selenium test automation scenario.
The Web Inspector (or Inspect) tool can be utilized during and after the execution of Selenium WebDriver tests. Features like locating details about web elements, monitoring network performance, and recording performance are fully functional in Web Inspector when running Selenium test automation scenarios.
The Develop > Show Web Inspector menu item launches the inspection tool during Selenium WebDriver tests.
The Selenium Safari driver on macOS allows you to specify WebDriver capabilities in a New Session for debugging.
When the Safari capability is included in a New Session request, safaridriver preloads Web Inspector and the JavaScript debugger in the background. Like the Inspect tool, you can pause test execution to check execution details in the Debugger tab of Web Inspector.
When the Safari capability is included in a New Session request, safaridriver preloads Web Inspector and begins timeline recording in the background. The details can be viewed in the Timeline tab of the Web Inspector.
A Glass Pane is placed over the Safari window where the automation test is running. This glass pane is designed to block any manual interactions, such as mouse movements, keyboard inputs, resizing, closing, or minimizing, that could interfere with the test in the Automation Window.
However, if the test gets stuck, fails, or you need to inspect something manually, you can break the glass pane. Doing so interrupts the Selenium test automation session, and the automation window remains open for further inspection until it is manually closed.
Below is the popup window that appears when attempting to break the WebDriver Session:
Turn off All Automation: This option disables ‘Develop > Allow Remote Automation,’ which is necessary for using the Selenium Safari driver on macOS to run automation tests. If you want to run tests in the Safari browser again, you will need to rerun the command safaridriver –enable in the terminal.
Stop Session: This option stops the current WebDriver session, allowing you to interact with the browser.
Continue Session: This option resumes the session, continuing the test from where it was paused. Once selected, you will not be able to interact with the browser.
Only one WebDriver session can be attached to a single instance of the Safari browser at any given time. Consequently, during automation testing, only one Safari instance and its attached WebDriver session can be active.
According to Apple’s official blog, these constraints prevent tests from competing internally for resources such as window focus, keyboard events, and keyboard focus. This setup mirrors the capabilities of a macOS windowing environment.
You can leverage a cloud-based platform to run your tests not only on Safari for iOS but also on Safari for Windows, with various browsers and OS combinations. One such platform is LambdaTest, It is an AI-Powered test execution platform that allows you to perform cross-browser testing across 3000+ browsers and OS combinations.
Setting up Apple’s safaridriver on a Mac is simple since it doesn’t require a separate installation. However, despite the ease of using the Selenium Safari driver on macOS, issues can arise with events like click, which may not function correctly in Selenium automation testing. If you don’t have a macOS device, you can install macOS on a virtual machine to use Apple’s Safari driver for Selenium test automation.
Problems encountered with Apple’s Safari driver on a local macOS copy are not present when using Selenium test automation on a cloud-based Selenium Grid like LambdaTest. This platform not only provides accurate results but also speeds up the automation testing process.
You can also conduct tests on macOS Catalina to verify your website’s cross-browser compatibility. Test for free on both the latest and older versions of macOS Catalina to ensure compatibility across different browsers.
The most commonly used framework for performing automation testing is Selenium. To begin with, it's…
Developed by Google, Espresso is a popular Android automation testing framework known for its high…
The cyberspace is buzzing with curio and surmise border the historic period of British knocker…
The prediction and upheaval palisade the upcoming 2nd season of the pop reality TV appearance,…
Natalie Grant and Amy Grant : Explore the Joining Natalie Grant and Amy Grant are…
Intromission : Nia Peeples , a illustrious American actress, Isaac Bashevis Singer, and dancer, has…