priyanka srivastava
priyanka srivastava

Reputation: 57

selenium web driver Unreachable browser exception with Safari on Mac

I have written simple code to open safari web browser in eclipse with selenium web driver on mac .also where to look for safari exe and where to place it on mac plzz help.thanks

package sanityTest;
  import org.openqa.selenium.WebDriver;
  import org.openqa.selenium.safari.SafariDriver;

  public class AdminLogin {
     public static void main(String[]args){
        WebDriver driver=new SafariDriver();
        //driver.close();//close the browser
    }

}

I am getting this error

strong textError below

Sep 24, 2016 1:22:31 AM org.openqa.selenium.safari.SafariDriverServer start INFO: Server started on port 3897 Sep 24, 2016 1:22:31 AM org.openqa.selenium.safari.SafariDriverCommandExecutor start INFO: Launching Safari Sep 24, 2016 1:22:31 AM org.openqa.selenium.safari.SafariDriverCommandExecutor start INFO: Waiting for SafariDriver to connect Sep 24, 2016 1:22:41 AM org.openqa.selenium.safari.SafariDriverCommandExecutor stop INFO: Shutting down Sep 24, 2016 1:22:41 AM org.openqa.selenium.safari.SafariDriverCommandExecutor stop INFO: Stopping Safari Sep 24, 2016 1:22:41 AM org.openqa.selenium.safari.SafariDriverCommandExecutor stop INFO: Stopping server Sep 24, 2016 1:22:41 AM org.openqa.selenium.safari.SafariDriverServer stop INFO: Stopping server Sep 24, 2016 1:22:41 AM org.openqa.selenium.safari.SafariDriverCommandExecutor stop INFO: Shutdown complete Sep 24, 2016 1:22:41 AM org.openqa.selenium.safari.SafariDriverCommandExecutor stop INFO: Shutting down Sep 24, 2016 1:22:41 AM org.openqa.selenium.safari.SafariDriverCommandExecutor stop INFO: Stopping server Sep 24, 2016 1:22:41 AM org.openqa.selenium.safari.SafariDriverCommandExecutor stop INFO: Shutdown complete Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Failed to connect to SafariDriver after 10080 ms Build info: version: 'unknown', revision: 'c7b525d', time: '2016-09-01 14:52:30 -0700' System info: host: 'Vishals-MacBook-Pro.local', ip: '192.168.0.26', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.11.5', java.version: '1.8.0_101' Driver info: driver.version: SafariDriver at org.openqa.selenium.safari.SafariDriverCommandExecutor.start(SafariDriverCommandExecutor.java:118) at org.openqa.selenium.safari.SafariDriver.startClient(SafariDriver.java:116) at org.openqa.selenium.remote.RemoteWebDriver.startClient(RemoteWebDriver.java:284) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:117) at org.openqa.selenium.safari.SafariDriver.(SafariDriver.java:78) at org.openqa.selenium.safari.SafariDriver.(SafariDriver.java:58) at sanityTest.AdminLogin.main(AdminLogin.java:10)

Upvotes: 1

Views: 1863

Answers (2)

Khyati Sehgal
Khyati Sehgal

Reputation: 375

I was also facing issues in initiating safari browser on mac machine, and below solution helped me. Everytime I was calling driver init, browser was getting opened but the URL was not getting hit. I am using Page object factory, with selenium , Java , maven and testng.

if (browserType.equals("safari")) {
            // System.setProperty("webdriver.safari.driver", workingDir +
            // "//driver//SafariDriverServer.exe");
            System.setProperty("webdriver.safari.driver",
                    "/driver/SafariDriver.safariextz");
            System.setProperty("webdriver.safari.noinstall", "true");
            DesiredCapabilities desiredCapabilities = DesiredCapabilities
                    .safari();
            SafariOptions safariOptions = new SafariOptions();
            safariOptions.setUseCleanSession(true);
            safariOptions.getUseCleanSession();
            safariOptions.setUseCleanSession(true);
            desiredCapabilities.setCapability(SafariOptions.CAPABILITY,
                    safariOptions);

            // deleteCookies();
            driver = new EventFiringWebDriver(new SafariDriver());

            ThreadDriver.set(driver);
            // driver.manage().window().setSize(new Dimension(1024, 850));
            getDriver().manage().timeouts().implicitlyWait(3,
                    TimeUnit.SECONDS);
            wait = new WebDriverWait(driver, 30);
        }

Upvotes: 0

Matt McCarragher
Matt McCarragher

Reputation: 21

The Safari WebDriver on Mac OS currently requires that you compile, sign, and install a specific WebDriver browser extension as detailed here. This requires that you sign up for a free Apple developer account and get a test key to sign the extension.

Fortunately, this method of remotely automating the Safari browser is currently undergoing a transition. With the upcoming release of Safari 10, the Webkit developers are building in native WebDriver support to the Safari browser itself. In my opinion, the easiest way to currently automate Safari is to download the Safari Technology Preview and then use the current snapshot version of Selenium to launch the WebDriver. You can find instructions on how to use Safari's new WebDriver features here.

Upvotes: 1

Related Questions