Due to the issue in detecting element visibility in the current version of Safari and safaridriver, as mentioned here, I attempted to launch our tests using Safari Technology Preview. The call is here:
return new SafariDriver("/Applications/Safari Technology Preview.app/Contents/MacOS/");
This seems to work, as it launches Safari Technology Preview when the test begins. However, after it is launched, nothing happens and I receive the following:
Error: ConnectFailure (Connection refused)
The full stacktrace is here:
1) Error : TESTNAME
OpenQA.Selenium.WebDriverException : A exception with a null response was thrown sending an HTTP request to the remote WebDriver server for URL http://localhost:62221/session. The status of the exception was ReceiveFailure, and the message was: Error getting response stream (ReadDone2): ReceiveFailure
----> System.Net.WebException : Error getting response stream (ReadDone2): ReceiveFailure
----> System.Exception : at System.Net.WebConnection.HandleError (System.Net.WebExceptionStatus st, System.Exception e, System.String where) [0x00000] in <5071a6e4a4564e19a2eda0f53e42f9bd>:0
at System.Net.WebConnection.ReadDone (System.IAsyncResult result) [0x00000] in <5071a6e4a4564e19a2eda0f53e42f9bd>:0
at System.Net.Sockets.SocketAsyncResult+<Complete>c__AnonStorey0.<>m__0 (System.Object _) [0x00000] in <5071a6e4a4564e19a2eda0f53e42f9bd>:0
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () [0x00000] in <8f2c484307284b51944a1a13a14c0266>:0
at System.Threading.ThreadPoolWorkQueue.Dispatch () [0x00000] in <8f2c484307284b51944a1a13a14c0266>:0
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () [0x00000] in <8f2c484307284b51944a1a13a14c0266>:0
TearDown : System.NullReferenceException : Object reference not set to an instance of an object
at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse (System.Net.WebRequest request) [0x000ce] in <1d3f371c7d3240a69d2057d5d4e507e9>:0
at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute (OpenQA.Selenium.Remote.Command commandToExecute) [0x000bd] in <1d3f371c7d3240a69d2057d5d4e507e9>:0
at OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute (OpenQA.Selenium.Remote.Command commandToExecute) [0x00038] in <1d3f371c7d3240a69d2057d5d4e507e9>:0
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute (System.String driverCommandToExecute, System.Collections.Generic.Dictionary`2[TKey,TValue] parameters) [0x00014] in <1d3f371c7d3240a69d2057d5d4e507e9>:0
at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession (OpenQA.Selenium.ICapabilities desiredCapabilities) [0x0001e] in <1d3f371c7d3240a69d2057d5d4e507e9>:0
at OpenQA.Selenium.Remote.RemoteWebDriver..ctor (OpenQA.Selenium.Remote.ICommandExecutor commandExecutor, OpenQA.Selenium.ICapabilities desiredCapabilities) [0x0001e] in <1d3f371c7d3240a69d2057d5d4e507e9>:0
at OpenQA.Selenium.Safari.SafariDriver..ctor (OpenQA.Selenium.Safari.SafariDriverService service, OpenQA.Selenium.Safari.SafariOptions options, System.TimeSpan commandTimeout) [0x0000e] in <1d3f371c7d3240a69d2057d5d4e507e9>:0
at OpenQA.Selenium.Safari.SafariDriver..ctor (System.String safariDriverDirectory, OpenQA.Selenium.Safari.SafariOptions options, System.TimeSpan commandTimeout) [0x00007] in <1d3f371c7d3240a69d2057d5d4e507e9>:0
at OpenQA.Selenium.Safari.SafariDriver..ctor (System.String safariDriverDirectory, OpenQA.Selenium.Safari.SafariOptions options) [0x00000] in <1d3f371c7d3240a69d2057d5d4e507e9>:0
at OpenQA.Selenium.Safari.SafariDriver..ctor (System.String safariDriverDirectory) [0x00007] in <1d3f371c7d3240a69d2057d5d4e507e9>:0
at Core.Selenium.SafariDriverFactory.CreateDriver (Core.Selenium.BrowserProfileManager profileManager) [0x00001] in <a2c49999051b4e8fb6c51d2ee4bca4b5>:0
at Core.Selenium.DriverController.CreateWebDriver (Core.Enums.DriverType type) [0x00078] in <a2c49999051b4e8fb6c51d2ee4bca4b5>:0
at Core.Selenium.DriverController..ctor (Core.Enums.DriverType type, System.DateTime creationTime, System.Boolean useProfile) [0x00045] in <a2c49999051b4e8fb6c51d2ee4bca4b5>:0
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00038] in <8f2c484307284b51944a1a13a14c0266>:0
--WebException
at System.Net.HttpWebRequest.EndGetResponse (System.IAsyncResult asyncResult) [0x00064] in <5071a6e4a4564e19a2eda0f53e42f9bd>:0
at System.Net.HttpWebRequest.GetResponse () [0x0000e] in <5071a6e4a4564e19a2eda0f53e42f9bd>:0
at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse (System.Net.WebRequest request) [0x00008] in <1d3f371c7d3240a69d2057d5d4e507e9>:0
--Exception
at System.Net.WebConnection.HandleError (System.Net.WebExceptionStatus st, System.Exception e, System.String where) [0x00044] in <5071a6e4a4564e19a2eda0f53e42f9bd>:0
NOTE: I do not get this error if I use the current release version of Safari.
I have implemented code in dotnet using Selenium 3.0.1. I am using Safari Technology Preview v. 22, macOS Sierra 10.12.3. Allow Remote Automation is checked in the Develop menu. I have ran /Applications/Safari Technology Preview.app/Contents/MacOS/safaridriver once manually.
Any ideas on how to get this working?
In Python, here is what I did:
driver = webdriver.Safari(port=0, executable_path="/Applications/Safari Technology Preview.app/Contents/MacOS/safaridriver")
driver.get("https://www.google.com")
You may also want to look at: https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/safari/SafariOptions.html
And here: https://github.com/SeleniumHQ/selenium/issues/3506 where lmtierney said:
That would depend on the language bindings you're using. You should be able to pass the executable path somewhere and it would be /Applications/Safari Technology Preview/Contents/MacOS/safaridriver. Some language bindings allow a flag to automatically use the tech preview safaridriver.
I hope this is helpful. :)