Remote webdriver is not working with safari from windows to mac

3,670 views
Skip to first unread message

sree

unread,
Apr 17, 2013, 10:42:29 AM4/17/13
to seleniu...@googlegroups.com
Hi

I am try to run my selenium scripts from windows to mac machine using Remote Driver. In this case driver will not return true using below code. so i am unable to run scripts in Mac os from Windows 7.

But i am able to run all scripts in Mac using local webdriver. 

jar: selenium-standalone-server-2.32.jar
java:jdk 1.7

This is the below code i am using in my script for running safari Remote driver:
if ("safari".equalsIgnoreCase(browser)) {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setBrowserName(browser);
capabilities.setJavascriptEnabled(true);
CommandExecutor executor = new SeleneseCommandExecutor(new URL("http://" + sysname+ ":4444/wd/hub"), new URL(url), capabilities);
return ((WebDriver) new RemoteWebDriver(executor, capabilities));
}

Sree Kumar

unread,
Apr 17, 2013, 11:02:29 AM4/17/13
to seleniu...@googlegroups.com
Hi

Please find the exception details when i am running from windows 7 to mac.

Apr 17, 2013 8:30:51 PM org.openqa.selenium.safari.SafariDriverServer start
INFO: Server started on port 40121
java.lang.IllegalStateException: The expected Safari data directory does not exist: C:\Users\u0145442\AppData\Roaming\Apple Computer\Safari
at com.google.common.base.Preconditions.checkState(Preconditions.java:176)
at org.openqa.selenium.safari.SafariDriverExtension.getInstallDirectory(SafariDriverExtension.java:149)
at org.openqa.selenium.safari.SafariDriverExtension.install(SafariDriverExtension.java:182)
at org.openqa.selenium.safari.SafariDriverCommandExecutor.start(SafariDriverCommandExecutor.java:84)
at org.openqa.selenium.safari.SafariDriver.startClient(SafariDriver.java:71)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:110)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:115)
at org.openqa.selenium.safari.SafariDriver.<init>(SafariDriver.java:57)
at org.openqa.selenium.safari.SafariDriver.<init>(SafariDriver.java:52)
at com.trta.cporange.test.Config.gSetUp(Config.java:95)
at com.trta.cporange.test.Config.gLogin(Config.java:148)
at com.trta.cporange.test.SECPlus.SEC122(SECPlus.java:1626)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:128)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.access$0(SuiteRunner.java:333)
at org.testng.SuiteRunner$SuiteWorker.run(SuiteRunner.java:368)
at org.testng.internal.thread.ThreadUtil$2.call(ThreadUtil.java:64)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

Thanks
Sreekumar


--
You received this message because you are subscribed to a topic in the Google Groups "Selenium Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/selenium-users/x-hZ-BH10sc/unsubscribe?hl=en-US.
To unsubscribe from this group and all its topics, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/yx2WGF9fujcJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Thanks and regards
Sreekumar
9492330784

Mark Collin

unread,
Apr 17, 2013, 11:53:04 AM4/17/13
to seleniu...@googlegroups.com
You are telling OSX to use a windows style directory which of course does not exist on OSX, see the helpful message at the start of the stack trace:

The expected Safari data directory does not exist: C:\Users\u0145442\AppData\Roaming\Apple Computer\Safari:
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.

To post to this group, send email to seleniu...@googlegroups.com.

David

unread,
Apr 17, 2013, 7:17:04 PM4/17/13
to seleniu...@googlegroups.com
Good observation Mark. But more information is needed to debug the problem.

In the initial post, I see no mention by the OP/code that indicates we specify running Safari on Windows nor specifying a specific data directory for Safari. The code is pretty generic.

So what I would look into is:

How was the server JAR and/or Grid & node started up? To run Safari on Mac remotely from Windows, you either need a Grid setup (Grid on any machine, node must be on Mac and registered to grid), or have server JAR started on Mac for RemoteWebDriver use (non-grid deployment). And if using Grid, how was the node browser support specified. For WebDrivers, you need to supply a capability JSON input file to specify which browsers a node will support so the Grid knows, described here:


and also, why use SeleneseCommandExecutor? Is WebDriverBackedSelenium required? Otherwise, I would just use RemoteWebDriver as is w/o command executor, the simpler way:

capabilities = DesiredCapabilities.safari();
driver = new RemoteWebDriver(new URL("http://" + machine.ip + ":" + machine.port + "/wd/hub" ), capabilities);

my guess to the problem is that either the command executor for remote web driver instantiation is causing problem, or that the grid/node config is incorrect leading grid to think test is requesting Safari on Windows.

Sree Kumar

unread,
Apr 18, 2013, 3:36:43 AM4/18/13
to seleniu...@googlegroups.com
@David:

The below  bat files are using for  my grid setup (IE,FF,Chrome).
HUB:
java -jar D:\workspace\cporange_selenium\lib\selenium-server-standalone-2.32.0.jar -role hub
NODE:
java -jar D:\workspace\cporange_selenium\lib\selenium-server-standalone-2.31.0.jar -Dwebdriver.chrome.driver="D:\Selenium\chromedriver.exe" -Dwebdriver.ie.driver="D:\Selenium\IEDriverServer.exe" -role node -hub http://localhost:4444/grid/register -browser "browserName=internet explorer,platform=WINDOWS" -browser "browserName=chrome,platform=WINDOWS" -browser "browserName=firefox,platform=WINDOWS" browser "browserName=opera,platform=WINDOWS"


But how i have to add safari driver in the 'NODE' bat file. There is no safaridriver.exe like chromedriver.exe or iedriver.exe.

I found that "SafariDriver.safariextension". Do i have to give the path of this folder in node bat like:

NODE(for safari):

java -jar D:\workspace\cporange_selenium\lib\selenium-server-standalone-2.31.0.jar -Dwebdriver.safari.driver="D:\Selenium\SafariDriver.safariextension-2.21.0\SafariDriver.safariextension\extension.js" - -role node -hub http://localhost:4444/grid/register -browser "browserName=safari,platform=Mac"




To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/LsioSKENBv4J.

For more options, visit https://groups.google.com/groups/opt_out.
 
 

Mark Collin

unread,
Apr 18, 2013, 4:48:18 AM4/18/13
to seleniu...@googlegroups.com
The point is that you are still specifying Windows paths When you are loading up the Safari node.  OSX will not understand "D:\Selenium\SafariDriver.safariextension-2.21.0\SafariDriver.safariextension\extension.js" its file system doesn't have the concept of a D drive

Sree Kumar

unread,
Apr 18, 2013, 4:51:20 AM4/18/13
to seleniu...@googlegroups.com
@Mark
Can you give me suggestion how to give the grid setup command to invoke safari browser from windows to mac machine.

David

unread,
Apr 19, 2013, 2:00:48 AM4/19/13
to seleniu...@googlegroups.com
sree,

Read http://code.google.com/p/selenium/wiki/SafariDriver for details on how to use SafariDriver remotely.

Basically you want something like this:

java -jar /Users/yourUsername/Documents/yourPathTo/selenium-server-standalone-2.31.0.jar -Dwebdriver.safari.driver="/yourMacPathTo/SafariDriver.safariextz" - -role node -hub http://IpAddressOfGrid:4444/grid/register -browser "browserName=safari,platform=Mac"

but a few things to note, you misunderstand how to use grid/node w/ Mac Safari support and how to use SafariDriver as well.

1. You can't run the Mac Safari node on Windows. The node that supports Mac Safari must be run/started on a Mac. Which means no batch file. You'll need to write a Linux/Mac shell script, an Applescript, or use Python/Perl/Ruby to create a script to launch the node. Otherwise, you can just run the command manually on the Mac terminal. You can't use batch files on a Mac.

2. Based on #1 above, you can either start the Mac node to register to a grid running on Windows, in which case the localhost value will be changed to the IP address or hostname of the Windows grid machine. Or you can run the grid on Mac, in which case you can use localhost as the grid value to connect to.

3. you do not need to provide SafariDriver path like IE or Chrome. With version 2.30+, it now works like Firefox, it just works. You can optionally provide path if needed, just like how you define FF binary path if needed, but by default you don't need to. In the case of SafariDriver, default is to auto-install the driver extension packaged inside the server JAR at test runtime and auto-uninstall at end of test. Same design as with FF driver.

4. If you specify SafariDriver path, it is path to the (compiled) extension, not the Safari executable. And not the example path you specify. You should be able to find the extension file inside the server JAR file if you treat it like a zip file and extract it with WinRAR or 7-zip. It has a filename similar to "SafariDriver.safariextz" the ".safariextz" indicates the extension is like a compiled binary file for installing into Safari. It's not like a normal zip file with a different file extension. You only need to do this if you want to install your own custom SafariDriver extension rather than use the default included with the JAR.

5. If you have used SafariDriver before version 2.30, you can still use same old method, which is, you have to manually install SafariDriver (extension), and manually maintain/upgrade SafariDriver for each new release. To keep the old way, you use the command line parameter (or system property):  "-Dwebdriver.safari.noinstall=true" which tells Selenium that SafariDriver extension is assumed to be already installed and just launch Safari.

6. Using the -browser, browsername method to define browsers a node supports may not be ideal to manage if the node supports many browsers. as mentioned in my previous post w/ links, the suggested JSON input file approach to specify browsers & platforms is more preferable IMHO for management & readability.

7. If you don't need to specifically test/support Safari on Mac or Safari 6, you can run Safari 5 on Windows, which means you can then use Windows paths and the batch file approach and also launch both grid & node together in same batch file if you wanted to. But in this case, you should still consider #3-5. This #7 also assumes you have Safari 5 installed on Windows (or an installer for it). Apple no longer provides download for Safari 5.

Sree Kumar

unread,
Apr 19, 2013, 2:18:02 AM4/19/13
to seleniu...@googlegroups.com
@David:

As per your mail we have to separate selenium setup for  each operating system like Windows,Mac. We are not able to invoke or run selenium scripts in Mac OSX through windows setup.

is it correct?




To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/b-F0hgcdYcAJ.

For more options, visit https://groups.google.com/groups/opt_out.
 
 

David

unread,
Apr 22, 2013, 2:14:41 AM4/22/13
to seleniu...@googlegroups.com
Yes that is mostly correct. There is one case where you can have Windows batch files start up Selenium server on Mac:

Windows batch files executes SSH command to Mac (i.e. remote command execute from Windows to Mac) start up the Selenium server on Mac (locally).

But that's sometimes messy and not a good choice for everyone to do. I'd rather keep my startup scripts separate between machines, unless you have a master that controls & kicks off everything.

Starting up Selenium servers centrally from one master machine to remote machines isn't much of an issue, but what if you want to restart or kill Selenium server sessions? That's more of a pain to then manage, grid or no grid.
Reply all
Reply to author
Forward
0 new messages