Home United States USA — software How To Run Test On macOS Using Selenium Safari Driver

How To Run Test On macOS Using Selenium Safari Driver

227
0
SHARE

The latest versions of Safari come with safaridriver, an in-built option to carry out websites’ debugging. See how to test on macOS using Selenium Safari’s …
Join the DZone community and get the full member experience. We all know that Google Chrome is the most popular browser in the world. But do you know, with 17.24% of the overall browser market share, Safari is the second most popular one? The reason behind Safari’s strong presence is that it is the default web browser for all Apple devices. And we know how much developers and coders love macOS, making it absolutely necessary to ensure that our websites’ are tested and optimized for all Safari versions. The latest versions of Safari (10 and above) come with safaridriver, an in-built option to carry out websites’ debugging. However, the earlier versions of Safari required you to install the Safari WebDriver extension, which is no longer supported in the latest versions. Safari browser instead uses the safari driver to implement WebDriver protocol. In this blog, we will see how to use the Selenium safari driver to perform testing on the Safari browser. Note: You need to have Safari on the Mac machine, as Apple has withdrawn the support of SafariDriver from Safari browsers on Windows. To use the Selenium framework for automation testing, you should have a corresponding Selenium WebDriver (e.g., Chrome WebDriver for Chrome, Geckodriver for Firefox, etc.) installed on the machine. However, in Selenium automation testing with Safari on macOS, there is no need to download Safari driver for Selenium WebDriver separately. Starting from Safari 10 on OS X El Capitan and macOS Sierra, the browser provides native support for the Selenium WebDriver API. As the Selenium Safari Driver for mac is preloaded on the OS, you need not mention the executable path for creating the Selenium WebDriver object. As already discussed, we don’t have to download Safari’s driver for Selenium WebDriver. Instead, Safari’s in-built driver called safaridriver is presently available in most Selenium client libraries. The safaridriver is maintained by the web developer experience team at Apple. Apple’s safaridriver executable path is /usr/bin/safaridriver. As Safari Technology Preview also provides its own executable safaridriver, it is a path of the application’s bundled contents. The safaridriver from Safari and safaridriver from Safari Technology Preview can run simultaneously, as each safaridriver only launches the Safari browser it is associated with. The legacy SafariDriver which was maintained by the Selenium project is deprecated and should not be used. In any case, Safari throws the error ‘Safari no longer supports unsafe extensions’ if you even attempt to install the deprecated Selenium WebDriver for Safari. For using the Selenium safaridriver for automation testing, you only require Safari 10 (or later) installed on the machine since there is native support for Selenium WebDriver API in those Safari versions. Starting from Selenium 3.0.0 release, Python and Java Client libraries offer support for native driver implementation of Safari. Even though native support for the Selenium WebDriver API is available in Safari 10 (and above), the WebDriver support is turned off by default. Follow the below-mentioned steps for enabling WebDriver support in Safari: Step 1: Run the following command on the terminal: /usr/bin/safaridriver –enable Note: You may need to do so in case you are upgrading from a previous macOS release. Step 1: Enable the ‘Show Developer’ menu in Safari through Safari > Preferences > Advanced > Select ‘Show Develop menu in menu bar’ (if it is not checked). Step 2: Choose Develop > Allow Remote Automation. Step 3: Now, authorize safaridriver to launch the XPC service that hosts the local webserver. For this, run /usr/bin/safaridriver once and follow the authentication prompt. As we would be using Apple’s safaridriver for Selenium test automation on macOS Catalina, we would be only executing /usr/bin/safaridriver –enable (or safaridriver –enable) once on the terminal.

Continue reading...