Accelerating Digital Initiatives

Using Hudson as Selenium Grid for Continuous Integration

In my last post about Hudson integration with Selenium RC,I talked about how to use Hudson to drive your Selenium RC tests.This configuration would work fine in most scenarios.However this is not a optimized configuration if you want to take advantage of executing your tests in parallel.For e.g if you have two machines in your lab with FF 35,you might want to run RC tests on both machines at same time.

Selenium Grid offers this capabilities.Below I will discuss how to take advantage of this in a continuous integration process.

I strongly recommend that you try to setup Selenium Grid on your local machine first if you had no prior experience with Selenium Grid.There are some very good Selenium Grid demos available here

Step 1

Download and Install Selenium Grid plugin for Hudson.You should see a small icon on your Hudson home page.Clicking on which you would see the RC’s registered to this Selenium Grid

Step 2

Important before this step,make sure that you are able to ping the RC server from Hudson and viceversa.If they cannot see each other it will not work

Registering your RC to Selenium Grid.This took me quite a while to figure out,but the trick is in the way you register this RC.

ant -Denvironment=”/qalab_01/windowsxp_1/:*firefox”   -Dport=5555 -Dhost=10.63.87.192 -DhubURL=http://myhudson.com:4444 launch-remote-control

Let’s go through the parameters one by one,you should be familiar with the parameters if you did a local setup of Selenium Grid.

environment=Machine Name/Label Name:browerCommand (Look at my earlier post about Selenium Hudson Integration to understand how to setup machine names and label names)

port=Available port on the machine where you are launching RC

host=IP address of your RC machine

hubURL=location of your Hudson server (which also doubles up as Selenium Grid now)

Step 3

Repeat similar process for another RC and when you click on the Selenium icon on your Hudson page,you should see that there are two RC’s registered to this Selenium Grid.

Step 4

Configure your Hudson job to run on master(i.e Selenium Grid) and it will take care of assigning the jobs to correct RC

Some important resources that helped me during the setup are

Amit Easow’s post on Hudson integration

Unregistering the Selenium RC command by this Selenium Blog.The command is lifesaver and I am repeating a example here

http://localhost:4444/registration-manager/unregister?host=locahost&port=5556&environment=*iexplore

To give a recap,I used ANT,TestNG,Selenium Grid,Hudson to accomplish this.

One last thing,The Selenium server jar is part of the Selenium Grid plugin bundle.You might want to replace it with a version of Selenium server you like on the Hudson server.

Follow us on @infostretch

VN:F [1.9.10_1130]
Rating: 7.8/10 (13 votes cast)
Using Hudson as Selenium Grid for Continuous Integration, 7.8 out of 10 based on 13 ratings

SharePost

0Likes

43 Comments

Sara

June 7, 2010 at 9:11 am

The release notes for the Selenium Plug-in for Hudson by Kawaguchi at http://weblogs.java.net/blog/2009/05/16/hudson-selenium-grid-plugin mention that “Once you install this plugin from the update center, Hudson master will become the Selenium Grid hub, the center of the Selenium Grid system. […] each slave that you have in your cluster will now run Selenium RCs. The whole process happens completely automatically, without any additional configuration.”

However, I’m having trouble having the RCs launch so autimatically when using even the demo. I have to launch them on each of the slaves, one by one. Is there any documentation on this anywhere? There are quite a few people that can’t seem to do this and posting questions about it online in various userGroups, just no solutions.

rutvik

June 8, 2010 at 5:25 pm

The complete setup does require some tweaks.There is no configuration required.However since there are multiple moving parts,tweaks are required.If you explain me what is the usecase you are trying to achieve,I might be able to help you out.

How do I integrate my Selenium RC tests integrate with Hudson

July 7, 2010 at 4:22 pm

[…] you want how to convert your hudson cluster to Selenium Grid ,this post should help […]

skuleguy

August 24, 2010 at 11:57 am

Hey rutvik,
First of all, thanks for the very detailed tutorial. I have a question though.
In part 2 above, you mentioned the command “ant -Denvironment=”/qalab_01/windowsxp_1/:*firefox” …”. From what I understand, Hudson is supposed to launch the RC automatically for, so why do we still need this command? Did you mean one must go to each node and manually launch RCs ?
Right now hudson does launch a # of RCs for me. But the “environment” shown on the http://hubURL:4444/console is very weird: /129lucidlynx/ (which is my node name) instead of “*firefox”, Additionally, the RC on the node is responsive but unable to launch any browser …

Regards,

Tung

rutvik

August 24, 2010 at 12:16 pm

Can you tell me a bit about your architecture
a)Are you trying to use the “Selenium Grid plugin for Hudson” where your Hudson instance is also your Selenium Grid instance
b)or do you have a lab machine acting as “Selenium Grid”

skuleguy

August 24, 2010 at 1:02 pm

Hi Rutvik,
Thank you for your reply. I am trying to set up option (a). After installing the “Selenium Grid (SG) plugin for hudson”, the Hudson master becomes SG hub and Hudson dumb slaves’s executors become SG RCs.
What I have got to so far:
– Set Up: I have
1. [name=tnguyen-lucidlynx-aug-16;
label=tnguyen-lucidlynx-aug-16]
A Hudson master running on a ubuntu 10.04 machine

2. [name=ll129hudson;
label=tnguyen-lucidlynx-aug-15]
A Hudson dumb-slave node running on another 10.04 machine. The node has 2 executors, the setup is quite similar to what you showed in the blog.

– When I start Hudson on apache, the Hudson master becomes the SG hub and successfully starts 2 RCs on my node, which I can verify in the http://hubURL:4444/console page:

Available Remote Controls
————————————————————————————–
Host | Port | Environment
————————————————————————————–
tnguyen-lucidlynx-aug-16.local | 48662 | /ll129hudson/tnguyen-lucidlynx-aug15/
tnguyen-lucidlynx-aug-16.local | 33924 | /ll129hudson/tnguyen-lucidlynx-aug15/
————————————————————————————–

When I run a test, the RCs do appear to move to Active RC section, however they can’t launch any browser …. The Console Output in Hudson master pauses indefinitely at:
INFO: Processing ‘1 => “*firefox”, 2 => “http://www.google.ca”, 3 => “”, cmd => “getNewBrowserSession”‘

Regards,

Tung

rutvik

August 25, 2010 at 12:51 am

The setup seems to be correct.If you haven’t already debugged ,can you try the following

1)Install Selenium grid and start RC on your machine(just one machine is fine) that are currently one of the slave node and see if this works correctly.(This is without Hudson into the picture).This will confirm that your Selenium Grid + RC execution works fine

2)This is slightly low possibility that something’s wrong with the selenium server version that is bundled with selenium grid.You can try to swap the selenium server jar and see if this fixes the issue (Hudson restart required)

skuleguy

August 25, 2010 at 1:47 pm

Hey Rutvik,
Thank you for your reply. I had been playing with Selenium Grid for a while before trying to integrate it with Hudson, so I can verify that Selenium Grid (without Hudson) on its own works as expected (hub on 1 machine, RCs on different machines).
I tried swapping the selenium server jar but I didn’t get any further with that.

Before I go over my setup in more details, I have a question about the “Configured Environments” on the “4444” selenium grid console page. In the standalone selenium grid installation, I would see a bunch of browsers listed. However, when the selenium grid plugin is in action, the list is empty …. I looked at the grid_configuration.yml in Hudson master’s home directory and it looks identical to the one in the standalone version. I’m not sure if this is why things are not clicking for me. …

Right now, what I have is, which Selenium grid plugin running on top of Hudson:
1. RCs registered correctly on the hub, as seen “4444 console”.
2. What I tried today is:
a) Machine [192.168.64.131] runs Hudson master and 1 Hudson dumb slave with 1 RC. (let’s call this 131)
b) Machine [192.168.64.129] runs 1 dumb slave with 1 RC (let’s call this 129)
c) Machine [192.168.64.134] runs 1 dumb slave with 1 RC (let’s call this 134)
When I tried launching a junit selenium grid test:
– If the RC on 131 (same machine as Hudson master) happened to be picked, the RC would try to launch the browser but hangs indefinitely.
– If the RC on either 129 or 134 (outside the happened to be picked), the test would crash, the RC would become “released/available” again, the Hub would log:

25-Aug-2010 1:18:16 PM com.thoughtworks.selenium.grid.HttpClient request
INFO: Remote Control replied with ‘200 / ‘Failed to start new browser session: Error while launching browser’
25-Aug-2010 1:18:16 PM com.thoughtworks.selenium.grid.hub.HubServlet forward
INFO: Responding with 200/ ‘ERROR: Could not retrieve a new session’

I’m not sure what to do about this because there isn’t enough information to find out why RCs cannot launch firefox.
Please let me know if you have any suggestions, I’m gonna try out a couple more configurations in the mean time.
Thanks,

Tung

rutvik

August 25, 2010 at 2:34 pm

The grid configuration yml might be different because you might be using a latest version of selenium grid when running independently and the “Hudson Selenium Grid plugin” uses a specific version of selenium grid.

I am not sure if it’s trivial to swap the selenium grid jar with the latest version on the Hudson plugin,but it’s worth a try since you are pretty close to your setup.Also check with the Hudson Selenium Grid plugin author if he can throw some light on it.I would also post this question on twitter.

Unfortunately both the errors that you are seeing is something that I haven’t experiencced before.

skuleguy

August 27, 2010 at 1:45 pm

Hi rutvik,

I have made some progress with Hudson-SeleniumGrid. I did what you suggested and swapped the selenium-server-1.x.x.jar with the latest selenium-server-1.0.3-standalone.jar (with renaming after, of course) and the slave remote controls are now able to launch browser and perform selenium tests.
The problem I’m having now is that my Windows slave is unable to become a Selenium slave. Unlike the Ubuntu slaves whose “Remote FSS folder”, upon connecting, would have the following files:
1. selenium-grid
2. maven2.1-interceptor.jar
3. maven-agent.jar
4. maven-interceptor.jar
My Windows slave’s Remote FSS folder only receives the last 3:
2. maven2.1-interceptor.jar
3. maven-agent.jar
4. maven-interceptor.jar
And, as you may have guessed, the hub Hudson master does not even bother launching RC on the Windows slave (even though Hudson acknowledges the status and existence of the build executors on the Windows slave)

Do you have any suggestion on what I should try, rutvik?

Thanks,

Tung

P.S.
I recommend anyone planning to do the file swap to do it only 1 time inside the plugin “selenium.hpi”. What I did was:
– Extract the hpi plugin file, it’s actually a zip file, so any extractor will do.
– Once everything in is extracted into a folder, you need to replace selenium-server-1.x.x.jar in the following 2 locations:
– First, go to:
/WEB-INF/classes/hudson/plugins/selenium/ and look for a file called “selenium.tgz”, extract this file, go inside it, replace the selenium-server-1.x.x.jar inside “vendor” with the newer selenium-server-x.x.x.jar that you like. Now, compress it back into “tgz” file again, name it “selenium.tgz”.

– Second, go to:
/WEB-INF/lib, replace the selenium-server-1.x.x.jar inside with the newer selenium-server-x.x.x.jar that you like.

-Thirdly, compress the mothership folder back into its original zipped “.hpi” plugin format, and install the plugin as if nothing has happened.

rutvik

August 28, 2010 at 11:33 am

I think that’s good progress.So If I understand correctly your

Hudson–>Ubuntu machines config is now working ,but
Hudson–>Windows machines cconfig is not working.

Let me check my environment when I am back at work on Mon.

skuleguy

August 30, 2010 at 8:49 am

Yes, my windows machines config is not working, for some reason I get this error on the Windows Slave:
“Unable to determine the host name. Skipping Selenium execution.”
And the selenium bundle was not copied onto the Slave’s Remote FS root (local directory on Slave).
My Windows Slaves are WinXP 32-bit.
Thanks,

Tung

rutvik

August 30, 2010 at 11:46 pm

Couple of places to look at

a)Look at the Hudson master logs and see if there is anything diff compared to Ubuntu
b)Check out the selenium grid logs/selenium server logs and see if you see anything

Vijay CK

December 15, 2010 at 2:25 am

Hi ,

This is a very Nice Plugin …..
When i start the hudson … it by default starts 2 RC’s

i wanted only one RC’s ….. Is there any way we would be able to reduce the RC’s in Selinum Plugin Configuration…..

Thanks and Regards,
Vijay.C.K

rutvik

December 15, 2010 at 2:07 pm

Vijay,
This is indeed a strange behavior.Did you post this query on the official plugin page(Selenium Grid Hudson Plugin)

seven

July 13, 2011 at 1:41 am

Why can’t i run it in my remote pc for run the test? It always run on muster and did not run the rcs?

jhone

July 13, 2011 at 3:45 am

I don’t know why the rc always show the status as idle. Only the the master run the tests? Does it support Junit?

rutvik

July 13, 2011 at 8:00 pm

Can you elaborate a bit about your setup?

Seven

July 14, 2011 at 3:16 am

Hi rutvik,
Thank you for your reply. I changed the setup today. By now i still can not run the suite on differents machines but same browser.The setup is as below:

1. I want to make my test cases run below a) Machine [192.168.203.116] runs Hudson master and 1 Hudson dumb slave with 1 RC.
b) Machine [192.168.203.119] runs 1 dumb slave with 1 RC

Both them can run on safari before i intergrated them into hudson.
2.
(1)After i run a job on hudson, i can see the available Remote Controls on http://192.168.203.116:4444 are showed as below:
[192.168.203.116] [5553 ] [/qa_local/windownsxp_2/:*safari]
[WEBTEST] [2654] [/qa_local/windownsxp_2/]
[WEBTEST ] [2646] [/master/]
the computer-192.168.203.116 ‘s name is Webtest.
(2)The active rc is only [192.168.203.119 5558 /QA_119/windowsxp_3/:*safari].And the safari did not be opened on 119.
By the way i also try to instead the selenium-server-1.0 in hudson plugin to selenium-server-2.0(changed name to selenium-server-1.0 ),then i try to run a job,it did not have any change.

Seven

July 14, 2011 at 3:21 am

We use ant to build files and JUnit is our base framework.

Seven

July 14, 2011 at 6:23 am

Oh,I found a trange issue thant I can not excute this command [ant -Denvironment=”/qa_local/windownsxp_2/:*safari” -Dport=5558 -Dhost=192.168.203.119 -DhubURL=http://192.168.203.116:4444 launch-remote-control]
on the husdon plugin root for selenium grid(C:\HUDSON\selenium-grid):
Buildfile: C:\HUDSON\selenium-grid\build.xml
[taskdef] Could not load definitions from resource testngtasks. It could not b
e found.

launch-remote-control:
[java] java.lang.NoClassDefFoundError: com/thoughtworks/selenium/grid/remot
econtrol/SelfRegisteringRemoteControlLauncher
[java] Caused by: java.lang.ClassNotFoundException: com.thoughtworks.seleni
um.grid.remotecontrol.SelfRegisteringRemoteControlLauncher
[java] at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
[java] at java.security.AccessController.doPrivileged(Native Method)
[java] at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
[java] at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
[java] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)

[java] at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
[java] Could not find the main class: com.thoughtworks.selenium.grid.remote
control.SelfRegisteringRemoteControlLauncher. Program will exit.
[java] Exception in thread “main”

BUILD FAILED

Then i try to run as this setup:
(1)only have 1 machine, this is 192.168.203.116.It runs Hudson master and 1 Hudson dumb slave with.
(2)Then I used the selenium-gird (not the the Selenium Grid plugin ) it can only run on [192.168.203.116 5557 /qa_local/windownsxp_2/:*safari].
192.168.203.116 runs Hudson master and 1 Hudson dumb slave with 1 RC.

rutvik

July 18, 2011 at 9:28 pm

the first part error seems to come due to your ant script and not finding the dependencies.what about the 2nd setup.it’s not clear whether it worked or not.here are some things to try

a)use an earlier version of selenium grid and see if it works
b)are you able to run the example setup that is mentioned on selenium grid without any issues.

Seven

July 19, 2011 at 2:31 am

rutvik,
Thank you for your replay. I change the selenium grid version to 1.0.8 on the RC, then i can run the test on it. But it still did not run on parallel.The setup is as below:
a)hudson run on 192.168.203.116.
b)i create 1 slave (192.168.203.114)on hudson, but i did not make it connected(it means that i did not run slave-agent.jnlp )
c)Then on that machine((192.168.203.114) I register it on selenium hub.
[ant -Denvironment=”/qa_ie9-pc/windownsxp_1/:*safari” -Dport=5556 -Dhost=192.168.203.114 -DhubURL=http://192.168.203.116:4444 launch-remote-control]
c)run the job on hudson, it can run on 114.
d)then register another rc:
[ant -Denvironment=”/qa_local/windownsxp_2/:*safari” -Dport=5555 -Dhost=192.168.203.116 -DhubURL=http://192.168.203.116:4444 launch-remote-control
]
e)then the test only run on 116 not paralleled run on 114.
I have serval questions are as below:
1)Should i do some cofiguration on code side. I can run the demo on selenium grid. I found the demo used testng but i did not. Should i also use it ?And if i did not use it ,what should i do ?
2)It seems that even i did not make the slave connect to master machine. The rc can still run the test. Maybe i did not very understand for the slave connection and rc connection. Could you give me some more information?
Thanks!

rutvik

July 19, 2011 at 9:00 pm

Seven,
First of all I think you are making some progress.
a)You don’t need to use TestNG
b)I think what is happening here is that Master is also a slave,whether you do the slave setup or not.

Try doing this on your 114 machine ,try running two RC’s (one Safari and one IE).register them to the hub(116) and

a)Verify each of them can run individually and separately
b)Without knowing too much about the way you are triggering your tests,you will still have to wire in the mechanism through you which you run both the test simultaeously.Just to test-Create two separate jobs in Hudson master and trigger them at teh same time and it should allow you to run the tests in different browser at the same time.

seven

July 20, 2011 at 11:09 am

Rutvik,
Thanks very much for your replay.
Today i try to run the two jobs in hudson master.First i directly start the 2 jobs at one time, but job 2 is in pending while job1 is runnig. Then I try this-‘Batch Task Plugin’ for hudson. I set 2 tasks within 1 job, for task 1 i mant to make it run in IE and task 2 in safari. And i make 2 workspaces for the job.But job 2 always can not be called up.Could you give me some suggetions for how to run the 2 jobs on hudson in one time?Thanks!

seven

July 20, 2011 at 11:15 am

Oh,sorry.Pre comment for this sentence ‘But job 2 always can not be called up’ should be ‘but task 2 always can not be called up’

Seven

July 24, 2011 at 10:12 pm

And if I make two jobs to run with one time, maybe can not generate ONE summary report .Thanks.

Erwin

July 26, 2011 at 5:43 am

Does anybody know how to set firefoxProfileTemplate on the slave.
Hudson Selenium Plugin mentiones that it allows specifying additional Remote Control startup options (-browserSideLog, -log, -debug, -firefoxProfileTemplate) but I have not figured out how to do this.
I need to set the Firefox Profile where I installed certificates required for accessing the test site.

rutvik

July 26, 2011 at 5:54 pm

Seven,
You can create one report-there are different ways to do this

a)use your testng configuration and see if you can have call all tests from single configuration-but there is a con to this as your results will be muddled up.in my experience it’s better to keep the reports separated

b)use a single ant wrapper file to call both your scripts and then from Hudson call the ant file

rutvik

July 26, 2011 at 5:57 pm

job 2 is pending because you might have allocated only one thread for your Hudson instance.Check the configuration of Hudson and see if you can allocate 2 threads.this will allow you to run 2 jobs at the same time.

Seven

July 29, 2011 at 5:25 am

rutvik,
Thank you very much!
Now I can made the two jobs run at the same time and can generate 1 summary report.
I have a trouble that the test can not run in Firefox on hudson -selenium environment. But I can run the test when i seperally launch the hub and register a rc.
The error is showed as this:Failed to start new browsr session…..

rutvik

August 2, 2011 at 1:01 am

Good work Seven..you persisted and you had success :).I probably need more information on the error that you are getting.can you please give me more information.

Seven

August 5, 2011 at 2:01 am

Rutvik,
I has resolved the FireFox issue. I just update the selenium-server-1.0.1.jar to 2.0 then i can run the test on firefox. Thank you very much Rutvik!Thanks for your great support

Leo

August 22, 2011 at 1:13 am

Hi,
While i am on step 4.
http://localhost:4444/registration-manager/unregister?host=locahost&port=5556&environment=*iexplore

I use this command. Why i can not unregister the RC.The web page show “OK”。But actually, I do not work. I also see the RC in hub.
Why? Do you have the same problem.

rutvik

August 22, 2011 at 12:58 pm

Leo,
I see a typo in the command (host=locahost should be host=localhost).Also make sure that Selenium RC is on localhost otherwise you need to provide the IP address.

http://localhost:4444/registration-manager/unregister?host=locahost&port=5556&environment=*iexplore

Keith

October 13, 2011 at 6:53 pm

Hi,
I’m having problems stopping the hub-remote-control instances.
I loaded the page:
http://localhost:3333/registration-manager/unregister?host=locahost&port=5556&environment=*firefox
and “OK” was displayed.
I saw the following messages in the launch-hub instance:
[java] Oct 13, 2011 3:42:22 PM com.thoughtworks.selenium.grid.hub.management.UnregistrationServlet process
[java] INFO: Unregistering remote control…
[java] Oct 13, 2011 3:42:22 PM com.thoughtworks.selenium.grid.hub.management.UnregistrationServlet process
[java] INFO: Unregistered [RemoteControlProxy locahost:5556#false]
[java] Oct 13, 2011 3:43:28 PM com.thoughtworks.selenium.grid.hub.remotecontrol.RemoteControlPoller garbageCollectRemoteControls
[java] INFO: Garbage collecting unavailable RCs and stale sessions…

Five minutes later, the console page still shows 5556 as an available remote control and that ant instance is still running.
It wasn’t until I actually terminated that hub-remote-control instance did it’s entry get removed from the console page.
I am running at the Windows command prompt right now but, when I move to Jenkins, how would I get these jobs to terminate?

Dorothy Valiga

November 15, 2011 at 4:08 pm

Can Selenium 2 be substituted?

rutvik

November 16, 2011 at 12:43 pm

Dorothy,
I haven’t tried with Selenium 2.You might want to check
a)Hudson Selenium grid plugin documents and see if it has support for Selenium 2
b)Selenium grid itself supporting Selenium 2

Theoretically things are supposed to be backward compatible,but I haven’t tried myself.

markuseb

December 7, 2011 at 11:04 pm

Thanks for providing a forum for SeleniumGrid Plugin questions. I’m currently experimenting with Jenkins (on WIndows) and after installing the SeleniumGrid plugin on my Jenkins server, I’m curious how to go about configuring the hub and the rc’s in a Jenkins environment.

I’m probably missing something but the SG plugin for Jenkins seems to be a no-config situation. Am I relegated to un-jar’ing the selenium grid .jar and modifying the grid_configuration.yml?

I’m still not sure how the RC (in a Jenkins environment) can be configured for something other than default settings.

Can you assist please?

Thanks.
MB

Fizmatik

December 28, 2011 at 1:15 am

Seven, I’ve got the same problem woth Firefox. How have you fixed it?

Fizmatik

December 28, 2011 at 9:47 am

firefox is opened. ok.

but test doesn’t run. Help please. Where can be the problem?

Edward Gierek

May 8, 2012 at 8:23 am

Hello,
are you able to update whole post with usage of a current version of Selenium (2.0 with webdriver)?

Regards,
Edward

Leave a comment

Your email address will not be published. Required fields are marked *