Since this topic has not been well documented on the net and I struggled myself to get Selenium tests running on Safari browser, here are the complete set of steps to get Selenium tests up and running on Safari browsers. :-
Creating “Safari Extension” Developer Certificate
- Create an Apple developer account.
- Go to https://developer.apple.com/
- Click on “Member Center” on top panel.
- Select “Create Apple ID”.
- Go through the sign up forms and provide valid fields for a succesful sign up
2. Login to created Apple account.
- You will be redirected to https://developer.apple.com/membercenter/index.action
3. Sign up for “Safari Extensions” developer
- Click on “Certificates, Identifiers & Profiles”
- In the “Safari Extensions’ section, click on “Join Now”
- Go through the following steps and provide valid fields to successfully sign up for the “Safari Extensions” program
4. Create “Developer Certificate”
- Now inside “Certificates, Identifiers & Profiles” > “Click on Create/Add Safari Certificate”
- You will see the following page – “About Creating a Certificate Signing Request (CSR)”
- Click on “Continue”
You will see the following page :-
- Upload the CSR file and Click on ‘Generate’ to generate the certificate
- Now download the certificate once it is generated.
5. Download the certificate and install in the machine
- Download the certificate in the download tab.
- The certificate is downloaded as “safari_extension.cer”.
- Double-click on the file to install the certificate in the Mac client/OSX.
6. We have installed the safari extensions certificate for developers. Now we need to install the Safari Webdriver extension for the Safari Browser.
Installing the Safari Webdriver extension in the Safari Browser
- Download latest Selenium Safari extension.
- Go to http://selenium-release.storage.googleapis.com/index.html
- Select the Selenium Webdriver version. For latest 10.10 Mac OSX, Safari 8 , I selected the 2.45 folder.
- In http://selenium-release.storage.googleapis.com/index.html?path=2.45/ select the “SafariDriver.safariextz” file.
2. Install the Safari Extension
- Double-click on the “SafariDriver.safariextz” file.
- You will get a prompt asking “Are you sure you want to install the extension “WebDriver”?“.
- Click on “Install”
3. Provide the default setting for the Selenium Webdriver Extension.
- Click on “Safari” > “Preferences” > “Extensions” > You will find Selenium extension
- Select “Enable Webdriver”
Now all the settings are done and now we should be able to launch our Selenium scripts using Safari Webdriver.
Launching Safari Webdriver
Webdriver driver = new SafariDriver();
driver.get( “http://www.google.co.in” );
builder = new Actions(driver);
This should launch your safari browser with the Safari Webdriver Extension 🙂
Hope this article comes of use to you all.
UPDATE (18th June,2015): With the latest update of Yosemite 10.10.3 & Safari 8.0.6, the execution on Safari Browsers has become unstable & unreliable.
Selenium Scripts work best on 10.10.2 , Safari 8.0.3 & Selenium 2.45.0 combination.
So if OSX prompts you for updates, please DO NOT install them if you want to run automation on Safari Browser
Regards,
VJ
I can’t find a link to download Safari 8.0.3. Can you share?
LikeLike
Hey I’m sorry about this.. But it’s very difficult to get dmg files of previous Safari browser version… This is part of Apple’s strategy of ensuring security to the OS… They don’t want users to be on older versions of the browser as later versions might have some critical security enhancing features..
LikeLike
You cannot downgrade. It’s the way WebKit works, you’d have to restore your OS to an earlier version.
LikeLike
Hi ,
This post was very help full in guiding me to start WebDriver for safari.
However, I am trying the same for Grid setup. Being novice, could you please provide me some basic on how to start hub and java remote web driver code.
Any assistance will be grateful.
LikeLike
Hi Bala,
Glad that you found this post helpful. However I’ve not worked on Selenium Grid uptil now. Java remote web driver is nothing but a webdriver jar which is installed which can be invoked when scripts are being scheduled from remote locations. You should get more info about this as you browse through more articles. It’s been a while since I’ve worked on Selenium, so….
LikeLike
This blog post was very useful. i was struggling for few hours . thanks
LikeLike
Hi,
Is there any way we can execute Selenium tests on Safari in Mac.
Mac OS : OS X El Capitan 10.11.6
Safari version : 9.1.3
Selenium Webdriver used: 2.48 for C#
I have added selenium webdriver extension (2.48) to Safari browser.
The safari browser is launched after executing the code “driver= new SafariDriver();” and then this error throws up.
The error is”Specified cast is not valid” at OpenQA.Selenium.Remote.RemoteWebDriver.
I have used RemoteWebDriver, IWebDriver and SafariWebDriver but still the same issue is thrown. Can you please help.
Regards,
Aditya
LikeLiked by 1 person
I have this problem too. Did you find a solution by any chance? Our team have been having a lot of issues with Safari in general recently.
LikeLike
Did you get a resolution for this?
LikeLike
Pingback: Preparing Jenkins to Do QA Testing Automation – rezasetiadi
Is there away to prevent Safari from starting in private mode?
LikeLike
I am getting the error when I ran on Yosemite 10.10.5 and Safari verion 10 as
” Exception in thread “main” org.openqa.selenium.WebDriverException: SafariDriver requires Safari 10 running on OSX El Capitan or greater.
Build info: version: ‘3.0.1’, revision: ‘1969d75’, time: ‘2016-10-18 09:48:19 -0700’
System info: host: ‘chetans-MacBook-Pro.local’, ip: ‘192.168.2.8’, os.name: ‘Mac OS X’, os.arch: ‘x86_64’, os.version: ‘10.10.5’, java.version: ‘1.8.0_121’
Driver info: driver.version: SafariDriver
at org.openqa.selenium.safari.SafariDriver.getExecutor(SafariDriver.java:75)
at org.openqa.selenium.safari.SafariDriver.(SafariDriver.java:62)
at org.openqa.selenium.safari.SafariDriver.(SafariDriver.java:42)
at excel.SafariTest.main(SafariTest.java:9)
Can anyone help me out.
LikeLike