Friday, March 5, 2010

Setting up Selenium-Grid on your System

In this blog I will tell you how to set-up Selenium Grid on your system.


  1. Check that Java is installed in your system by using the command “java -version”. If Java is installed it will give the output about Java Version that is installed in your system. Else download the Java from Java website (http://www.java.com/en/download/index.jsp).

  2. Check ANT is installed in your system by using the command “ant -version”.If Ant is installed it will give the output about Ant Version that is installed in your system. Else download the Apache Ant from Apache website (http://ant.apache.org/).

  3. Download Selenium Grid from Selenium Grid website(http://selenium-grid.seleniumhq.org/download.html) and unpack it.

  4. Go to the Unpacked directory of the Selenium grid using command prompt and type the command “ant launch-hub”. This will launch the Selenium Grid Hub on a default port “4444” to check whether the selenium grid is running. Type the URL “http://localhost:4444/console ” on your browser and check that you are able to see the selenium hub console on the browser.

  5. Now go to the same Selenium Grid directory using command prompt and type the command “ant launch-remote-control”. This will start the Selenium Grid Remote control on default port “5555” and environment “*firefox” and register it to the Hub which you had earlier started.

  6. Now after starting the selenium remote control we will test the example provided with Selenium Grid for sequence testing in single machine. For this go to the Selnium grid folder from command prompt and type the command “ant run-in-demo-sequence”. This will execute the test example provided with selenium grid to be executed in sequence.


Now you may had noticed in the setting up steps that I am running the test in sequence. You may think in your mind that, what's special in that? The same things can be achieved when we use a Selenium RC.Then here comes the important part of Selenium Grid.


Setting up Parallel execution on a single machine

  1. Start the hub and one remote control in the same way as in the earlier setting up steps.

  2. Now go to the Selenium Grid folder using command prompt and type the command

“ant -Dport =5556 launch-remote-control”

This will start another remote control on port “5556” and register it to the local hub. If you want to register more remote control to the Hub. You can do that by starting multiple remote control but with different ports.

  1. To know the no. of registered remote control onto a hub go to the URL “http://localhost:4444/console”. It will give you a view as follows:


  1. Now to run the test in parallel. Go to the selenium grid directory using command prompt and type the command “ant run-demo-in-parallel”. This will run the example tests given with selenium grid in parallel.


Setting up parallel execution for different machines and different environments

In this case start the Hub normally as you do in any of the system.

For starting the remote control use the following command.


ant -Dport=<port> -Dhost=<hostname> -DhubURL=<hub> -Denvironment=<environment> launch-remote-control


Here

“-Dport” should be used to set the port of the remote control.

“-Dhost” should be used to set the host(where the remote control has been started) IP. This is the IP which the hub will use to talk to the remote control.

“-DhubURL” should be used to set the Hub Url where the current remote control will register itself.

“-Denvironment” should be used to set an environment name that remote control represents to the hub.

Now start 4 different remote controls from 2 different machines and register them to the hub.

After this check the Hub console. It will look similar to the table as shown below depending upon the remote control that are registered to the Hub.


Then to verify your set-up go to the Selenium Grid folder from the command prompt and type the command “ant run-demo-in-parallel”


This will run an example test accompanied with the Selenium Grid to run in parallel.


Advantages of Selenium Grid

  1. Remote Execution of the selenium tests can be done using Selenium Grid without actually copying your test code to to remote system.

  2. Selenium Grid can be used to save time by executing independent testcases in parallel.

  3. Load Testing can be done if we register a lot of remote control to a single hub and execute testcase in parallel to simulate multiple transactions at a single timeperiod.

25 comments :

Unknown said...

Hi there,

Just tried to follow the example using the command:
ant -Denvironment='*firefox' -Dport=5555 -Dhost=10.112.4.203 -DhubURL=192.168.100.126:4444 -Denvironment="Firefox on Windows" launch-remote-control
and got the following exception:
Exception in thread "main" java.lang.IllegalStateException: unsupported protocol '192.168.100.126'

Any suggestion?

thanks in advance

Antonio

Varun Menon said...

Try using -DhubURL=http://192.168.100.126:4444 in your argument.

Unknown said...

It worked!!!

Thanks

Daniel said...

Any Idea how you can set this up as a windows service?

Varun Menon said...

@Daniel: I never tried it as a service. But you can try creating a batch file and putting that batch file to the "Startup" folder under the programs menu of windows.
I tried this thing for something else long back.

Unknown said...

any idea how to use maven instead of ant with selenium grid

dinu1025 said...

while working with grid, remote machine are not opening the browser or means there is no response from remote machine. Although console shows the remote machine as available host, but when we are running scripts, then in active host remote machine is not listed.can u help us y so??

Varun Menon said...

Hi @dinu,
The above thing can be used when you are using the selenium 1 api.
If you are using the same and having the problem You can send a mail to me at mr.varun.menon@gmail.com directly with the details on how you are instantiating the selenium object and all. I will reply to it.

Regards
Varun

balakrishna said...

i tried following command:
ant -Dport=5555 -Dhost=xx.xx.xx.xx -Denvironment="*firefox" launch-remote-control

Result - able to see the settings in grid console

Again
ant -Dport=5556 -Dhost=xx.xx.xx.xx -Denvironment="*firefox" launch-remote-control

Result -
BUILD FAILED
Target "ûDport" does not exist in the project "Selenium Grid Distribution".

Pls suggest me. thanks in advance

-balakrishna

balakrishna said...

i configured remote controls in selenium grid successfully. Now i want to how to remove available and remote controls and also how to stop the hub.

pls suggest me. waiting for your reply

Varun Menon said...

Just press Ctrl+C on the cmd prompt where the RC were started using ant.

balakrishna said...

thanks alot

balakrishna said...

Hi am facing the following issue when is use "ant run-demo-in-parallel"

[java] Feb 17, 2012 5:48:39 PM com.thoughtworks.selenium.grid.tools.ThreadS
afeSeleniumSessionStorage closeSeleniumSession
[java] INFO: Closing Selenese session: com.thoughtworks.selenium.DefaultSel
enium@e28b9
[java]
[java] ===============================================
[java] Selenium Grid Demo In Parallel
[java] Total tests run: 4, Failures: 4, Skips: 0
[java] ===============================================
[java]

BUILD FAILED
C:\Program Files\selenium-grid-1.0.8\build.xml:137: Java returned: 1

Total time: 0 seconds

pls suggest me sir!
thanks in advance!.

balakrishna said...
This comment has been removed by the author.
balakrishna said...
This comment has been removed by the author.
madhusudhanareddy MV said...

Hi Varun I successfully installed selenium grid.By following your step.But how to run my test cases in other machine which r having in ecilips.

Varun Menon said...

You are using selenium RC or webdriver? For selenium RC DefaultSelenium class to create selenium object and pass the remote system URL.
For WebDriver use RemoteWebDriver class.

Unknown said...

Hi Varun So far I have installed grid and also able to launch different servers to different port. But I am confused with script execution.
After setting up every thing How to run scripts.
Currently I have two scripts created and wanted to run in Parallel on same machine and with same browser. So my question how to run this.

Varun Menon said...

Can you try with the new setup of webdriver mentioned in the following link

http://blog.varunin.com/2011/10/selenium-grid-with-webdriver.html

Unknown said...

Thanks Varun for Reply but I have scripts created in JUnit and for batch execution I am using Ant and build.xml.
Is there any way to execute using ant.

mahesh said...
This comment has been removed by the author.
mahesh said...

Hi,
We have requirement like as soon as the application build deployment has been done, need to execute my jenkin jobs automatically.
Please suggest me on this.

Thanks,
Mahesh

Varun Menon said...

Add the said automation job as a dependent job of your build deployment.
Look at post build task in jenkins

mahesh said...

Thank you for response.
As per my understand for "post build task" plugin build deployment also need to done with Jenkins(to execute a shell/batch task depending on the build log output), but we have tool for build deployment, build information will store in log file, how do I map build log file to Jenkins to execute shell/batch.

mahesh said...
This comment has been removed by the author.

Post a Comment