3

I wanted some help on running my automation scripts on Safari.

Im running my selenium webdriver scripts on Mac OS(High Sierra) and Safari 11.1.2

I have WebDriver Extension has been added to safari browser and I have enabled the 'Allow Remote Automation'

Here is the way i'm trying to invoke selenium webdriver:

   SafariOptions safariOptions = new SafariOptions();
    safariOptions.useCleanSession(true);
    safariOptions.setUseTechnologyPreview(true);
    WebDriver driver = new SafariDriver(safariOptions);

I have also installed Safari technology preview on my machine.

When I run my scripts, it throws below error:

    org.openqa.selenium.SessionNotCreatedException: Could not create a session: A browser with name 'safari' version '(null)' could not be found on the system.
Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:26:55.152Z'
System info: host: 'Meghas-MacBook-Pro.local', ip: 'fe80:0:0:0:1c74:d309:2877:bd09%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13.4', java.version: '1.8.0_171'
Driver info: driver.version: InitiateWebDriver
remote stacktrace: 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$new$0(W3CHandshakeResponse.java:57)
    at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$getResponseFunction$2(W3CHandshakeResponse.java:104)
    at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:123)
    at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
    at java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)
    at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126)
    at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:498)
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
    at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:152)
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:464)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:126)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:73)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:545)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:209)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:132)
    at org.openqa.selenium.safari.SafariDriver.<init>(SafariDriver.java:78)
    at org.openqa.selenium.safari.SafariDriver.<init>(SafariDriver.java:60)

So when I uninstall the Safari technology preview, and change the code to

org.openqa.selenium.WebDriverException: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:24147
Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:26:55.152Z'
System info: host: 'Meghas-MacBook-Pro.local', ip: 'fe80:0:0:0:1c74:d309:2877:bd09%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13.4', java.version: '1.8.0_171'
Driver info: driver.version: InitiateWebDriver
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:92)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:545)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:209)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:132)
    at org.openqa.selenium.safari.SafariDriver.<init>(SafariDriver.java:78)
    at org.openqa.selenium.safari.SafariDriver.<init>(SafariDriver.java:60)

Inbetween it also said that "Safari driver requires safari 10 running on OSX EL Capitan or greater"

Andrei Suvorkov
  • 5,191
  • 4
  • 17
  • 37

1 Answers1

0

As occurs with other selenium webdrivers you should specify where is the binary of Safari to run it.

System.setProperty("webdriver.safari.driver", "/mypath/binary");

The path usually is /System/Library/CoreServices/SafariSupport.bundle/Contents/MacOS/safaridriver. And do it before your example lines.

And activate the Safari automation:

enter image description here

j.barrio
  • 881
  • 1
  • 8
  • 30
  • Thank you for your response. I tried specifying the path of safaridriver Eg:System.setProperty("webdriver.safari.driver", "/user/bin/safaridriver"); It did not work. Here is what I tried: System.setProperty("webdriver.safari.driver", "/user/bin/safaridriver"); SafariOptions safariOptions = new SafariOptions(); safariOptions.useCleanSession(true); // safariOptions.setUseTechnologyPreview(true); driver = new SafariDriver(safariOptions); – Megha Vinay Jul 30 '18 at 07:05
  • And here is the response: org.openqa.selenium.WebDriverException: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:26940 Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:26:55.152Z' System info: host: 'Meghas-MacBook-Pro.local', ip: 'fe80:0:0:0:1c74:d309:2877:bd09%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13.4', java.version: '1.8.0_171' – Megha Vinay Jul 30 '18 at 07:08
  • do you have the preview software downloaded? from the store. – j.barrio Jul 30 '18 at 07:15
  • It worked for me a few months ago, but you are right. With the latest version of selenium and preview is not working, right now. – j.barrio Jul 30 '18 at 11:43