Search code examples
javamacosseleniumsafarisafaridriver

Unable to launch Safari 12 browser in Mac OSX using Selenium and Java


Recently I updated mac OS to "Mojave version 10.14" and "safari version 12.0" after that i am unable to lunch safari browser. Earlier it was running fine. I am selenium "3.0.0" here is my code:

Scenario 1:

case "safari":
DesiredCapabilities cap = DesiredCapabilities.safari();
driver = new SafariDriver(cap);
break;

Error:

org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. desired capabilities = Capabilities [{browserName=safari, safari.options=org.openqa.selenium.safari.SafariOptions@10eff, version=, platform=MAC}], required capabilities = Capabilities [{}]
Build info: version: '3.0.0', revision: '350cf60', time: '2016-10-13 10:48:57 -0700'
System info: host: 'xxxx-MacBook-Pro.local', ip: 'xxxxx', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14', java.version: '1.8.0_131'
Driver info: driver.version: SafariDriver

Scenario 2:

SafariOptions options = new SafariOptions();
options.setUseTechnologyPreview(true);
WebDriver driver = new SafariDriver(options);
driver.get("http://www.google.com");
driver.quit();

Error:

Exception in thread "main" org.openqa.selenium.WebDriverException: SafariDriver requires Safari 10 running on OSX El Capitan or greater.
Build info: version: '3.0.0', revision: '350cf60', time: '2016-10-13 10:48:57 -0700'
System info: host: 'xxxx-MacBook-Pro.local', ip: 'xxxxx', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14', java.version: '1.8.0_131'
Driver info: driver.version: SafariDriver
    at org.openqa.selenium.safari.SafariDriver.getExecutor(SafariDriver.java:75)
    at org.openqa.selenium.safari.SafariDriver.<init>(SafariDriver.java:62)

In both cases i am unable to run my test cases please someone help me. Thanks .


Solution

  • This error message...

    org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. desired capabilities = Capabilities [{browserName=safari, safari.options=org.openqa.selenium.safari.SafariOptions@10eff, version=, platform=MAC}], required capabilities = Capabilities [{}] Build info: version: '3.0.0', revision: '350cf60', time: '2016-10-13 10:48:57 -0700' System info: host: 'xxxx-MacBook-Pro.local', ip: 'xxxxx', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14', java.version: '1.8.0_131'
    

    ...implies that the SafariDriver was unable to initiate/spawn a new WebBrowser i.e. Safari Browser session.

    Your main issue is the incompatibility between the version of the binaries you are using as follows:

    • Your Selenium Client version is 3.0.0 of 2016-10-13 10:48:57 -0700 which is almost 2 years older.
    • Your JDK version is 1.8.0_131 which is pretty ancient.

    So there is a clear mismatch between the JDK v8u131 , Selenium Client v3.0.0

    Solution

    • As an initial step you need to fulfil the following requirement ...SafariDriver requires Safari 10 running on OSX El Capitan or greater...
    • Upgrade JDK to recent levels JDK 8u181.
    • Upgrade Selenium to current levels Version 3.14.0.
    • Upgrade SafariDriver to current level.
    • Upgrade Safari Browser to current level.
    • Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
    • If your base Web Browser/Client version is too old, then uninstall it through Revo Uninstaller and install a recent GA and released version of Web Client.
    • Execute your @Test.