Thursday, March 11, 2010

Defining your own Environment and Using it in Selenium Grid


If you want to use an environment something like “Firefox on Windows” or “Firefox on Linux”.
You can use that by starting the Remote control with the said environment name. This will register the Remote control to the hub with the said environment name.
For ex. Start the hub normally but while starting the Remote control replace the -Denvironment value with your own particular name.

ant -Dport=5555 -Dhost=192.168.1.0 -DhubURL=http://192.168.1.2:4444 -Denvironment=”Firefox on Linux” launch-remote-control


If you check the Hub console it will look something like


Also if you want to use such an environment for executing your Test you need to pass the environment name to the selenium object in your code.
For Java you need to use the following function while creating the selenium object.


new DefaultSelenium("localhost", 4444, “Firefox on Windows”, 'http://google.com');

Now if you go through the above things you will think about how to use the above function and define the selenium object since it is already been declared and defined when you get it from selenium IDE.
This happens because when you copy the code from the Selenium Ide, the class that is defined in the code extends the “SeleneseTestCase” class where this “selenium ” object has already been defined.


For using the custom Environment with the Selenium Grid do the following thing:

1.Remove the “SeleneseTestCase” class which is extended by the Test class.

2.Define your own Selenese object as shown below

Selenium selenium;
selenium =new DefaultSelenium("localhost", 4444, " ", "http://www.google.com");


3.Start the selenium using the below command.

selenium.start();

This will start your selenium session. Then using this selenium object you run your test cases.

4.After your test is done use the following command to stop the selenium.


selenium.stop();

When you call the selenium grid by giving some particular Environment name. The Selenium Hub will make sure to provide the test with a remote control that registered with this specific Hub environment.

3 comments :

Unknown said...

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

Sivaprasad Kandula said...

I have done work with selenium grid using windows 7 as well as windows XP now i am moving run to scripts in mac OS lion could u help any one ?

Varun Menon said...

What is the issue that your are facing?

Post a Comment