Search

Setting up Grid2 and working with it!

Since setting up a grid and a webdriver node is something that I have been seeing as a Frequently Asked Question, I thought why not start off my “so-called” technical blog with that.

So here’s how it can be done.

I will be using a WINDOWS 7, 64 bit machine for this blog, and have chosen to work with JDK 1.6 (32 bit). Incase you are wondering why am I running a 32 bit JDK on a 64 bit Machine, the reason is simple. From my random browsing learnings, I understand that IE 64 bit doesnt have a big fan club which is why by default in a Windows 7 machine, the moment you click on IE icon, you spin off a 32 bit IE version and not the 64 bit version. But if you use 64bit JDK to spawn your Grid or your Web Driver node for that matter, it ends up spawning the 64 bit IE which is not something that we desire. This should explain why I have chosen to use 32 bit JDK.

You would need a copy of the standalone jar for selenium. It can be downloaded from http://code.google.com/p/selenium/downloads/list. At the time of me writing up this blog, the version that was available was 2.17.0. So I will be referring to this particular version through-out this post.

Now we would need a copy of the chrome driver so that our grid can support chrome executions as well. The chrome driver also can be downloaded from the link mentioned in Step (1).

After downloading both the above mentioned artifacts from the internet, I have chosen to organize them in a way such that I can easily figure out things. Here’s a screenshot of how my directory to which I unzipped all of these things look like.

So now that you know how my folder structure looks like (with some pretty naive arrow mark indicators 🙂 ) lets get started.

For my convenience I chose to write a simple batch file, which contains all the instructions that are needed to spawn a webdriver node as well as the grid hub. So lets dive into seeing how exactly does my “so-called” batch file looks like. (The contents of grid-startup-batch.bat file)

Assumptions :

The current directory as denoted by %CD% DOS environment variable, should have the JDK available. If not feel free to modify this environment variable to the actual location where your Java Installation is available.

This batch now has all the things that I need to kick start my Grid environment. To start the grid, all that I would need to do is, double click this batch file and voila! The grid and a webdriver node is now running.

You should see two command windows open up as below :

To open the Grid console, open a web browser of your choice and type :

What if I wanted to test against a specific version of a browser say “Firefox 8” in my grid ?

You will follow the same approach, but now you would set the browser version also in your DesiredCapabilities object as below :

capabilities.setVersion("8");

then modify the webconfig.txt file, add version parameter to it as below

"version":"8"

restart your Grid and you should get it done!

Some points to remember :

Grid2 will not let you set custom values to “browser name” and “platform”. But you can set whatever values you want to the browser version parameter and it has got nothing to do with your actual browser version.

Hope that de-mystifies to some extent on the basics required on how to work with Grid2.

can you extend this article by example how to run tests parallel ( can be one test but executed on more then one node at the same time). it would be great to find this information in one place (next to great article about configuration of grid).

Hi Krishnan,
I was trying to test parallelly using testng. I have a virtualization software called cameyo and I have prepared multiple firefox executables and registered multiple firefoxes in same node. But while running I’m getting “Unable to bind to locking port 7054 within 45000 ms” error. Could you pls tell me what i need to do this. Running those firefoxes with FirefoxDriver is working fine.I’m using selenium2.22.0 version

Nice article, but what about when using the old fashion RC code? To my understanding, the capabilities cannot be set when using the DefaultSelenium constructor to instantiate a selenium object, correct?

Of course, there always is the option to refactor from RC to WebDriver style, but that requires a lot of time and resources, which is not always available for QA teams.

Do you have a tutorial to run RC code against Grid 2 and multiple versions of a same browser (ff 10, 17, etc.)?

It is very useful article. Thanks for that. I have configured exactly i way said, but i am facing below mentioned error. I tried all possible ways.
error is :
The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see etc etc.
facing same error when i try to run through ie as well.

The batch files contents are :
set HERE=%CD%
set JAVA_HOME=%HERE%\jdk1.6.0_21
set PATH=%JAVA_HOME%\jre\bin;%JAVA_HOME%\bin;%PATH%

set SELENIUM_VERSION=2.28.0
set CHROME_VERSION=chromedriver_win_23.0.1240.0
set HUB_URL=http://localhost:4444/grid/register
set CHROME_DRIVER_LOC=%HERE%/%CHROME_VERSION%/chromedriver.exe
set IE_DRIVER_LOC=D:/selinium/IEDriverServer_Win32_2.28.0/IEDriverServer.exe

can i know how it should be done. Because i tried adding the below line of code
capabilities.setCapability(“chrome.binary”, “C:/Users/u0142168/AppData/Local/Google/Chrome/Application”); and run it to set chrome driver settings but failed to execute successfully, facing the same error. Same is the case with IE aswell. Please guide me.

Great info krishnan, Can you create a blog for integrating grid with Jenkins? I am confused how i can start up batch and node from Jenkins. I tried to use pre-build steps for starting batch and nodes, however the jenkins hung after kicking off the batch command.

Sushmita,
You seem to have a problem in your node configuration file. Please use an online JSON validator [ something like http://jsonformatter.curiousconcept.com/ ] to check if your nodeconfig.txt file is a valid JSON file.

i am new to the selenium grid and was trying to set it up with your detailed explanation above. while executing i got the same error.
Exception in thread “main” org.openqa.selenium.WebDriverException:

Error 500 Server Error

HTTP ERROR: 500
Problem accessing /grid/register/session. Reason:

Server Error
Powered by Jetty://
i have checked the Json file in the online validator, it gives an error only for the “host”: ip, that has to be in string. i changed it to string. Still i receive the same error. Your help is highly appreciated.

I am getting the following error.I have tried the same way as given in this blog.Please help on resolving this,

java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Map
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:143)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:95)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:103)
at library.Alerts.testAlert(Alerts.java:38)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:691)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:883)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1208)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:753)
at org.testng.TestRunner.run(TestRunner.java:613)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:335)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:330)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:292)
at org.testng.SuiteRunner.run(SuiteRunner.java:241)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1169)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1094)
at org.testng.TestNG.run(TestNG.java:1006)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:107)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:199)

I configured everything as you said in the post. Its working very fine on firefox, i created many scripts. But now I need to run test cases on IE and chrome and both the browser are giving me exception.

Exception in thread “main” org.openqa.selenium.WebDriverException: The path to the driver executable must be set by the webdriver.ie.driver system property;

I have downloaded the drivers for both.
Location for IE driver is : C:\Users\Administrator\Downloads\IEDriverServer_x64_2.31.0\IEDriverServer.exe
I have also set enabled Protected mode true for all zones in IE

// And now use this to visit Google
driver.get(“https://www.google.com”);

Exception I am getting :

Exception in thread “main” org.openqa.selenium.WebDriverException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see http://code.google.com/p/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://code.google.com/p/chromedriver/downloads/list
Command duration or timeout: 608 milliseconds
Build info: version: ‘2.29.0’, revision: ‘58258c3’, time: ‘2013-01-17 22:47:00’
System info: os.name: ‘Windows Server 2008 R2’, os.arch: ‘amd64’, os.version: ‘6.1’, java.version: ‘1.7.0_13’
Driver info: org.openqa.selenium.remote.RemoteWebDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:187)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:533)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:216)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:111)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:129)
at test.Test.main(Test.java:32)
Caused by: java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see ….

Hi Krishnan,
Until now, I haven’t had any chance to run selenium grid on two machines and VM. So when i try to run my hub in my local machine and node in VM, it’s not working as it seems like it’s not registering to the hub. However, if i run hub and node in local machine, it just works fine.

Since my selenium scripts along with selenium server jar files are in C: of my local machine, i don’t think i can navigate to that folder from VM. So do i need to copy my selenium folder to the VM as well. If yes, won’t that be a duplicate work?

Great post! I learned a lot the first time that I read it 🙂 But after install FF and IE I have a problem after launch google chrome;
When I execute a test calling google chrome (*googlechrome), selenium wedriver opens the browser and start to launch the test cases but it doesn’t charge anything. I had the same problem with firefox and IE but I solved them opening the proxy’s/adding user sessions. I don’t know if it’s the same problem for Chrome or what’s happening.

I work with Selenium grid 2, jenkins and a java interface. Paths for chrome.exe and chromedriver.exe are added in my environment (instances of *googlechrome appear in my grid2), in fact as I said Selenium webdriver opens the browser but doesn’t charge, I have searched for a solution during days in the web but nothing…

Someone can help me? I have chromedriver and the references to it in my environment path.

1. I have launched the hub as below and it works as expected.
java -jar selenium-server-standalone-2.33.0.jar -role hub
2. now, i have registered a node with below config to the hub it successfully registers
java -Dwebdriver.chrome.driver=”E:\chromedriver.exe” -jar selenium-server-standalone-2.33.0.jar -role node -hub http://localhost:4444/grid/register -maxSession 10 -browser “browserName=chrome,platform=WINDOWS”,maxInstances=2 *-port 5555*
3. now, when i try to register a node for either firefox/Ie to the hub in the similar fashion to point to 2 with a different port number, the batch file opens the cmd prompt and closes immediately.

at a point of time im able to sync only one node either chrome, ff, ie to hub. Could you please let me where the issue could be.

Great post…I have a question
I am using Grid 2 with testng and I have set
in my testng xml.when I run from eclipse with running as testng suite then my suite runs parallel.however If I want to run parallel using batch file using ant build.xml.

How did you get it to work in parallel execution using testng.xml and Grid 2? I am getting java heap space error. I am only executing 3 tests in parallel with 3 threads and I am seeing the Java heap space error. This is the response:

Error 500 java.lang.OutOfMemoryError: Java heap space

HTTP ERROR: 500
Problem accessing /wd/hub/session. Reason:

java.lang.OutOfMemoryError: Java heap space

Powered by Jetty://

Not sure if I am doing anything wrong. It works fine if I don’t execute in parallel. Here is my testNG.xml

I am facing a challenge with setting up a grid for mobile web pages. I need to open the browsers in nodes with specified user agent strings. How to achieve this? When I do new RemoteWebDriver(), I dont have an option to set user agent. If you could shed some light on this, that would be helpful. Thanks in advance.

I am new to selenium grid . i have configured hub and node in a machine . But when running the test , i am facing the issue .”Error forwarding a new Session ” . As you mentioned in the Post above , i have tried using the configuration file in the same folder and executed the test .But the result is same .

I don’t know if this a right place to post my question here. I have worked with you earlier and I know you are the best in test framework development and what not..
My question is:
I have to validate a html file using selenium. The html file is part of my project workspace. I use absolute path to retrieve the url, and it works well locally something like this:
String inputFilePath = “src/main/java/elementspkg/fixtures/responsive.html”;
String url = new File(inputFilePath).getAbsolutePath();
driver.get(“file:///”+url);
driver.get(“file:////Users/aspiringqa/Desktop/javatests-travis-ci-poc/src/main/java/elements‌​pkg/fixtures/responsive.html”);

I set up travis CI to run my tests on a sauce labs machine.
Now my test fails because the ‘url’ isn’t correct. It pulls up the travis CI absolute path like this:
driver.get(“file:////home/travis/build/xxx/javatests-travis-ci-poc/src/main/java/elementspkg‌​/fixtures/responsive.html”);

My Sauce lab VM doesn’t find this html file and it says page not found and my test cant proceed.

Is there a way I can launch this html file through selenium on a sauce machine?