Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Safari browser gets closed immediately after launching the browser #636

Closed
perwez123 opened this issue Jun 9, 2015 · 11 comments
Closed

Comments

@perwez123
Copy link

Safari browser opens up and gets closed immediately . I am getting the following error in the console .
As i understood from they error message is it says Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure. Bu the address is absolutely right . In the same address chrome browse works fine .

Version : Selenium 2.46
Selenium Server : 2.46
OS :OS: Mac OS X 10.9.5 x86_64
Browser :Safari

Starting GRID node in Mac machines
18:14:23.311 INFO - Launching a Selenium Grid node
18:14:23.602 INFO - Java: Oracle Corporation 24.71-b01
18:14:23.602 INFO - OS: Mac OS X 10.9.5 x86_64
18:14:23.606 INFO - v2.46.0, with Core v2.46.0. Built from revision 87c69e2
18:14:23.641 INFO - Driver provider org.openqa.selenium.ie.InternetExplorerDriver registration is skipped:
registration capabilities Capabilities [{platform=WINDOWS, ensureCleanSession=true, browserName=internet explorer, version=}] does not match the current platform MAC
18:14:23.641 INFO - Driver class not found: com.opera.core.systems.OperaDriver
18:14:23.641 INFO - Driver provider com.opera.core.systems.OperaDriver is not registered
18:14:23.674 INFO - Selenium Grid node is up and ready to register to the hub
18:14:23.692 INFO - Starting auto registration thread. Will try to register every 5000 ms.
18:14:23.692 INFO - Registering the node to the hub: http://10.98.1.30:4444/grid/register
18:14:23.704 INFO - The node is registered to the hub and ready to use
18:14:44.669 INFO - Executing: [new session: Capabilities [{platform=ANY, browserName=safari, version=, safari.options={port=0, cleanSession=true}}]])
18:14:44.675 INFO - Creating a new session for Capabilities [{platform=ANY, browserName=safari, version=, safari.options={port=0, cleanSession=true}}]
18:14:44.728 INFO - Server started on port 47355
18:14:44.736 INFO - Launching Safari
18:14:44.744 INFO - Waiting for SafariDriver to connect
18:14:46.106 INFO - Connection opened
18:14:46.107 INFO - Driver connected in 1363 ms
18:14:46.117 INFO - Shutting down
18:14:46.117 INFO - Closing connection
18:14:46.118 INFO - Stopping Safari
18:14:46.171 INFO - Stopping server
18:14:46.171 INFO - Stopping server
18:14:46.175 INFO - Shutdown complete
18:14:46.400 WARN - Exception thrown
java.util.concurrent.ExecutionException: org.openqa.selenium.WebDriverException: java.lang.reflect.InvocationTargetException
Build info: version: '2.46.0', revision: '87c69e2', time: '2015-06-04 16:16:47'
System info: host: 'CHENNMW-0YVF8J5.local', ip: '10.98.5.239', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9.5', java.version: '1.7.0_71'
Driver info: driver.version: unknown
at java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.util.concurrent.FutureTask.get(FutureTask.java:188)
at org.openqa.selenium.remote.server.DefaultSession.execute(DefaultSession.java:183)
at org.openqa.selenium.remote.server.DefaultSession.(DefaultSession.java:119)
at org.openqa.selenium.remote.server.DefaultSession.createSession(DefaultSession.java:95)
at org.openqa.selenium.remote.server.DefaultDriverSessions.newSession(DefaultDriverSessions.java:137)
at org.openqa.selenium.remote.server.handler.NewSession.handle(NewSession.java:58)
at org.openqa.selenium.remote.server.handler.NewSession.handle(NewSession.java:1)
at org.openqa.selenium.remote.server.rest.ResultConfig.handle(ResultConfig.java:111)
at org.openqa.selenium.remote.server.JsonHttpCommandHandler.handleRequest(JsonHttpCommandHandler.java:174)
at org.openqa.selenium.remote.server.DriverServlet.handleRequest(DriverServlet.java:202)
at org.openqa.selenium.remote.server.DriverServlet.doPost(DriverServlet.java:164)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.openqa.selenium.remote.server.DriverServlet.service(DriverServlet.java:130)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.openqa.jetty.jetty.servlet.ServletHolder.handle(ServletHolder.java:428)
at org.openqa.jetty.jetty.servlet.ServletHandler.dispatch(ServletHandler.java:680)
at org.openqa.jetty.jetty.servlet.ServletHandler.handle(ServletHandler.java:571)
at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1526)
at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1479)
at org.openqa.jetty.http.HttpServer.service(HttpServer.java:920)
at org.openqa.jetty.http.HttpConnection.service(HttpConnection.java:820)
at org.openqa.jetty.http.HttpConnection.handleNext(HttpConnection.java:986)
at org.openqa.jetty.http.HttpConnection.handle(HttpConnection.java:837)
at org.openqa.jetty.http.SocketListener.handleConnection(SocketListener.java:243)
at org.openqa.jetty.util.ThreadedServer.handle(ThreadedServer.java:358)
at org.openqa.jetty.util.ThreadPool$PoolThread.run(ThreadPool.java:537)
Caused by: org.openqa.selenium.WebDriverException: java.lang.reflect.InvocationTargetException
Build info: version: '2.46.0', revision: '87c69e2', time: '2015-06-04 16:16:47'
System info: host: 'CHENNMW-0YVF8J5.local', ip: '10.98.5.239', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9.5', java.version: '1.7.0_71'
Driver info: driver.version: unknown
at org.openqa.selenium.remote.server.DefaultDriverProvider.callConstructor(DefaultDriverProvider.java:95)
at org.openqa.selenium.remote.server.DefaultDriverProvider.newInstance(DefaultDriverProvider.java:79)
at org.openqa.selenium.remote.server.DefaultDriverFactory.newInstance(DefaultDriverFactory.java:62)
at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:222)
at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:1)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at org.openqa.selenium.remote.server.DefaultSession$1.run(DefaultSession.java:176)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.openqa.selenium.remote.server.DefaultDriverProvider.callConstructor(DefaultDriverProvider.java:85)
... 9 more
Caused by: org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '2.46.0', revision: '87c69e2', time: '2015-06-04 16:16:47'
System info: host: 'CHENNMW-0YVF8J5.local', ip: '10.98.5.239', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9.5', java.version: '1.7.0_71'
Driver info: driver.version: SafariDriver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:242)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:128)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:141)
at org.openqa.selenium.safari.SafariDriver.(SafariDriver.java:58)
at org.openqa.selenium.safari.SafariDriver.(SafariDriver.java:51)
... 14 more
Caused by: java.lang.ClassCastException: com.google.gson.JsonObject cannot be cast to java.lang.String
at org.openqa.selenium.remote.JsonToBeanConverter.convert(JsonToBeanConverter.java:111)
at org.openqa.selenium.remote.JsonToBeanConverter.convert(JsonToBeanConverter.java:42)
at org.openqa.selenium.safari.SafariDriverCommandExecutor.execute(SafariDriverCommandExecutor.java:191)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:578)
... 19 more
18:14:46.404 WARN - Exception: com.google.gson.JsonObject cannot be cast to java.lang.String

@ddavison
Copy link
Member

ddavison commented Jun 9, 2015

how are you trying to run these tests? via nodes, or locally.. i see "node", but my gut tells me you are just trying to run these locally?

@nirp1981
Copy link

nirp1981 commented Jun 9, 2015

I have the same issue since updating selenium to 2.46.
I installed the 2.46 safari web-driver extension manually , got it from :
http://repo1.maven.org/maven2/org/seleniumhq/selenium/selenium-safari-driver/2.46.0/

I installed the .xtz file thats inside the selenium-safari-driver-2.46.0.jar.

when I run a test ,safari opens but immediately gets shut down.
this is the extension log before it gets shut down:
17:41:04.18 [safaridriver.extension] Creating global session...
17:41:04.20 [safaridriver.extension.TabManager] Registering new tab
17:41:04.20 [safaridriver.extension.TabManager] Tab closed
17:41:04.20 [safaridriver.extension.TabManager] Attempting to delete an unknown tab.
17:41:04.20 [safaridriver.extension.TabManager] Ignoring close window event
17:41:04.23 [safaridriver.extension.TabManager] Set command tab to 7bg3h99fxzv5
17:41:04.23 [safaridriver.extension] Creating debug driver...
17:41:04.23 [safaridriver.extension] Waiting for connect command...
17:41:06.76 [safaridriver.extension.TabManager] Registering new tab
17:41:06.76 [safaridriver.extension.TabManager] Tab opened: 4r8luvi5wrq0
17:41:06.85 [safaridriver.extension.TabManager] Ignoring open window event
17:41:06.85 [safaridriver.extension.TabManager] Deleting entry for tab 4r8luvi5wrq0

*I looked at the code and it seems that in the class SafariDriverCommandExecutor ,
connection = server.getConnection(10, TimeUnit.SECONDS);
the connection value is empty ( "[]"), and then the stop(); method is called.

the stacktrace:
org.openqa.selenium.remote.UnreachableBrowserException: Failed to connect to SafariDriver after 13849 ms
Build info: version: '2.46.0', revision: '87c69e2', time: '2015-06-04 16:17:10'
System info: host: 'eyals-Mac-mini', ip: '10.0.0.1', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.10.3', java.version: '1.8.0_31'
Driver info: driver.version: SafariDriver
at org.openqa.selenium.safari.SafariDriverCommandExecutor.start(SafariDriverCommandExecutor.java:121)
at org.openqa.selenium.safari.SafariDriver.startClient(SafariDriver.java:72)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:116)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:141)
at org.openqa.selenium.safari.SafariDriver.(SafariDriver.java:58)
at org.openqa.selenium.safari.SafariDriver.(SafariDriver.java:51)

Thanks!

@barancev
Copy link
Member

barancev commented Jun 9, 2015

Duplication of #631

@barancev barancev closed this as completed Jun 9, 2015
@dprantl03
Copy link

This is not the same issue as #631 and the commit for it does not fix or affect this issue at all. In this issue if the loading of the safari browser and initialization of the browser extension takes more than 10 seconds, Selenium gives up and shuts it down. This 10 second value is hard-coded in SafariDriverCommandExecutor.java as has been mentioned in a previous comment above:

...
try {
log.info("Waiting for SafariDriver to connect");
connection = server.getConnection(10, TimeUnit.SECONDS);
...

and it is not possible to change it. In an environment where many virtual machines are running OS X on shared storage and depending on the total load on the overall system, it is pretty easy to run into a situation where a session doesn't load within 10 seconds and gets shut down.

In the past, and all the way up to Selenium v2.42.2, the code looked like this:

...
try {
log.info("Waiting for SafariDriver to connect");
connection = server.getConnection(45, TimeUnit.SECONDS);
...

Starting with v2.43.0, it was changed to 10 seconds and is still like that now. An excerpt from the v2.43.0 changelog:

  • Safari is flaky. Reducing timeout to fail faster when we're going to fail.

Here is the commit and message:

Aug 18, 2014
963f64c
Safari is flaky. Reducing timeout to fail faster when we're going to fail.
When it starts successfully, it always does in 4 seconds on some modest
machines.

So now even when Safari is not flaky but takes too long to load it will fail, making Safari automation even more flaky. And it has been determined by one person that in their specific environment, Safari never takes more than 4 seconds to load. Other browser drivers have similar 45 second timeouts today, so I don't see why Safari would be as small as 10 seconds. Searching around, I see other people have encountered this problem as well.

@dprantl03
Copy link

Did some more investigation and there is a new problem with Safari 9.0.1 running on MacOSX El Capitan that exacerbates this problem. The sessions have a habit of timing out on this browser platform. I have tested this with two Safari 9 VMs and two Safari 8 VMs in parallel (all running 2.48.2 jars and 2.48.0 extensions), and the 8's almost never time out sessions whereas the 9's do it almost always. All four VMs run on the same host, same subnet and same shared storage. Even when downgrading the 9's to the 2.42.2 jar, they just time out after 45 seconds instead of 10. I have the browser initialization on a 20 count retry loop, and occasionally the 9's will catch and run the tests after many retries.

@cjamago
Copy link

cjamago commented Dec 3, 2015

pls use the links below to add Safari extention https://itisatechiesworld.wordpress.com/2015/04/15/steps-to-get-selenium-webdriver-running-on-safari-browser/
This is how I resolve the issue. Make sure that if there is any wait for browser to load is bypass for safari

@cjamago
Copy link

cjamago commented Dec 3, 2015

Safari does not like any wait

@sethetter
Copy link

@cjamago Seems like Apple wants me to purchase a developer license for $99 to go through this process, which I'm not willing to do.

Anyone have any other suggestions? I'm experiencing the same issue here.

@bhuvanbdev
Copy link

Hi cjamago,

'Make sure that if there is any wait for browser to load is bypass for safari'. Can you pls write a line of code to show that.

@shahulprofile
Copy link

Its very common issue in Mac with Safari. Try to workout in Chrome browser.

@knreddy036
Copy link

Is it possible to launch multiple instances of safari browsers in Mac and running scripts ?

@lock lock bot locked and limited conversation to collaborators Aug 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants