How to run parallel test cases in selenium grid?

7,713 views
Skip to first unread message

Pushpraj Singh

unread,
Jan 18, 2013, 4:45:51 AM1/18/13
to webd...@googlegroups.com
Hi All,

I want to run parallel test cases (more than one firefox windows ) using selenium grid on my MAC 10.6; to achieve this I am referring to the tutorial here (run demo ).
I was able to run the demo in parallel, BUT now I want to run my own test cases in parallel. How can I do that?

Here is, what I have, with which I am trying to achieve parallel execution of test cases with the help of grid.

sample script 1:
package com.example.tests;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;

public class searchdenims {
   
    WebDriver driver;
   
    @Test
    public void test () {
       
        driver = new FirefoxDriver();
        driver.get("http://www.bing.com/");
        driver.findElement(By.xpath("//*[@id='sb_form_q']")).clear();
        driver.findElement(By.xpath("//*[@id='sb_form_q']")).sendKeys("selenium");
        driver.findElement(By.xpath("//*[@id='sb_form_go']")).click();
    }

}

testng.xml :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="classes">
  <test name="Test">
    <classes>
      <class name="Live.searchdenims"/>
      <class name="Live.searchcheese"/>
      <class name="Live.searchsuckerpunch"/>
      <class name="Live.searchCBR250"/>
      <class name="Live.searchraga"/>
      <class name="Live.searchcake"/>
      <class name="Live.searchironfist"/>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->

Don't know how to create a Grid Project if that's required.
Don't know how to configure build.xml inside grid project.

java version "1.6.0_37"
Apache Ant(TM) version 1.8.4
selenium-grid-1.0.8

Krishnan Mahadevan

unread,
Jan 18, 2013, 4:51:12 AM1/18/13
to webd...@googlegroups.com
Grid1 is DEPRECATED.

Please start using Grid2.


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"





--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To view this discussion on the web visit https://groups.google.com/d/msg/webdriver/-/pJXqDVEh458J.
To post to this group, send email to webd...@googlegroups.com.
To unsubscribe from this group, send email to webdriver+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.

Pushpraj Singh

unread,
Jan 18, 2013, 5:49:05 AM1/18/13
to webd...@googlegroups.com
Thanks Krishnan for the information.
I went to the wiki page and tutorial given by you.

But my query is still there, how to run parallel test cases via grid 2.
If I run testng.xml via testng(using eclipse IDE) , it will run 6 classes in parallel  in 6 firefox windows but I want to run these classes with the help of grid.How can I do that?

1. Do I have make some changes in my scripts; need to add desired capablities, ports ?
or
2. I simply make some changes in my suite (testng.xml)
3. Once I achieve any of these steps (don't want to change scripts , would be very hectic), how would I let know the grid2, to fetch and run these classes or testng.xml?

I am on MAC 10.6. Please help.

Krishnan Mahadevan

unread,
Jan 18, 2013, 5:58:06 AM1/18/13
to webd...@googlegroups.com
You DONT need to change anything in your script.

You would basically configure your nodes to support "n" concurrent sessions per node and "n" instances per browser flavor.

Once that is done, you kick off your parallel tests via TestNG and the Grid should take care of ensuring that the parallel runs do happen.

  • n instances per browser flavor is configured via the parameter "maxInstances" in your nodeConfig JSON file [1]
  • n concurrent sessions per node is configured via the parameter "maxSession" [2]



Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To view this discussion on the web visit https://groups.google.com/d/msg/webdriver/-/Xmm9GXHdBroJ.

Richard Lavoie

unread,
Jan 18, 2013, 7:58:57 AM1/18/13
to webd...@googlegroups.com
Well he does have to change the initialization of new FirefoxDriver() to new RemoteWebDriver(url, capabilities) so it launches the test through grid, otherwise it will always run locally (how would it know of the existence of a grid server in the network otherwise ?)

Prithvi Raj

unread,
Jan 18, 2013, 9:05:31 AM1/18/13
to webd...@googlegroups.com
But I have a question here which could be very silly one though.

In my framework I have mentioned the condition saying that if it is firefox execute firefox, if it is IE then invoke IE,.....etc so as Richard mentioned can we just mention RemoteWebDriver(url, capabilties) then will it execute on multiple browsers set in my grid (which has IE, Chrome and Firefox).

What I am trying to achieve is that I want to execute the same script on multiple browser without mentioning the condition (whether its IE or Firefox or Chrome). Can someone please advise me here.

Thanks

Raj

Krishnan Mahadevan

unread,
Jan 18, 2013, 10:59:36 AM1/18/13
to webd...@googlegroups.com
You would still need condition checks in place to determine what sort of a capability you would need to create i.e., invoke one of the static methods within DesiredCapabilities class to create a capability that matches a desired browser.


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/


Prithvi Raj

unread,
Jan 18, 2013, 11:53:27 AM1/18/13
to webd...@googlegroups.com
Thank you Krishnan,

I used the condition and the browsers doesnot get invoked. I have Firefox, chrome and IE to run as parallel in my TestNg.xml.

But for some reason I get this error

org.openqa.selenium.WebDriverException: Error forwarding the new session cannot find: {platform=ANY, browserName=FF, version=}

Caused by: org.openqa.selenium.remote.ErrorHandler$UnknownServerException: Error forwarding the new session cannot find : {platform=WINDOWS, ensureCleanSession=true, browserName=IE, version=}

org.openqa.selenium.WebDriverException: Error forwarding the new session cannot find : {platform=WINDOWS, ensureCleanSession=true, browserName=IE, version=}

Can you please where I am going wrong.

Cheers!!!

Prithvi

Richard Lavoie

unread,
Jan 18, 2013, 12:17:38 PM1/18/13
to webd...@googlegroups.com

On Fri, Jan 18, 2013 at 11:53 AM, Prithvi Raj <mprit...@gmail.com> wrote:
d by: org.openqa.selenium.remote.ErrorHandler$UnknownServerException: Error forwarding the new session cannot find : {platform=WINDOWS, ensureCleanSession=true, br

When you have a grid, you also need to start a slave node to connect to this grid so you have real executors. The grid only acts as a proxy and cannot acts at the same time as a slave executor.

So you have to start a Grid, and a slave node.


--
Richard Lavoie
IT consultant / consultant en informatique

Richard Lavoie

unread,
Jan 18, 2013, 12:18:32 PM1/18/13
to webd...@googlegroups.com
if you wanna know what are the slaves connected to your grid, you can connect to your grid by http on http://grid:4444/ and follow the console link

Prithvi Raj

unread,
Jan 18, 2013, 12:59:30 PM1/18/13
to webd...@googlegroups.com
Hi Richard,

Both of them have been started as I had prepared a bat file which invokes the grid and node together and I can see the console which shows the number of instances of different browsers. Also I had changed the instances in WebConfig.txt file.

So Its up and running but the tests are not getting executed.
What could be the reason?
I have attached the screenshots for your reference.

Cheers!!!

Prithvi

--
Screen Shot 2013-01-18 at 17.57.30.png
Screen Shot 2013-01-18 at 17.58.17.png

Richard Lavoie

unread,
Jan 18, 2013, 1:04:41 PM1/18/13
to webd...@googlegroups.com
What do you see when you connect to the console of the grid ? what are the browsers configured for your slave ?

Mouse over the icons to see the capabilities handled for each browsers.

Also the problem might also be with the Platform capability matching (I've had problems with that in the past in previous versions, dunno if it was fixed), try creating yourself a Capability object without using DesiredCapabilities.firefox() and just specify the browser attribute. See if that helps.

Mike Riley

unread,
Jan 18, 2013, 1:17:02 PM1/18/13
to webd...@googlegroups.com
Have you looked here?
http://rationaleemotions.wordpress.com/2012/01/23/setting-up-grid2-and-working-with-it/

Once you have grid set up you just need to configure TestNG to run the tests in parallel.  If you need help with that you should ask on the TestNG forum:
https://groups.google.com/forum/#!forum/testng-users

Mike

Prithvi Raj

unread,
Jan 18, 2013, 1:50:54 PM1/18/13
to webd...@googlegroups.com
Richard,

Thanks. I have also attached the console when after connecting the hub and node. This are the browsers configured on my slave.

Can you throw some light on the capability object? I see that DesiredCapabilities is derived from Capability Interface.
If you can direct me with a snippet that would be great.

Mike - Thanks I did configured the grid seeing that website and I could successfully configure.

I did configured TestNG with parallel attribute and thread counts. Anyways I will ask in the TestNg forum as well if I am doing something wrong.

Cheers!!!

Prithvi

Richard Lavoie

unread,
Jan 18, 2013, 3:16:11 PM1/18/13
to webd...@googlegroups.com
If you look on the link that Mike sent, there is an example of Capability configuration and it explains the problem that I'm talking about.

R.

Prithvi Raj

unread,
Jan 18, 2013, 3:25:32 PM1/18/13
to webd...@googlegroups.com
Richard,

After few hours of struggle, it seems to work for firefox, but Chrome and IE dont invoke asking to set the property. But  I have already mentioned it like below in the condition:

if(browser.equalsIgnoreCase("FF")){
        System.out.println("Launching Firefox");
        capabilities = DesiredCapabilities.firefox();
        capabilities.setBrowserName(DesiredCapabilities.firefox().getBrowserName());
        capabilities.setPlatform(org.openqa.selenium.Platform.ANY);
        URL url = new URL("http://localhost:4444/wd/hub");
        driver = new RemoteWebDriver(url, capabilities);
        }
        else if(browser.equalsIgnoreCase("chrome")){
            System.out.println("Launching Chrome");
            capabilities = DesiredCapabilities.chrome();
            capabilities.setBrowserName(DesiredCapabilities.chrome().getBrowserName());
            capabilities.setPlatform(org.openqa.selenium.Platform.ANY);
            System.setProperty("webdriver.ie.driver", "C://IEDriverServer.exe");
            URL url = new URL("http://localhost:4444/wd/hub");
            driver = new RemoteWebDriver(url, capabilities);
        }
        else if(browser.equalsIgnoreCase("IE")){
            System.out.println("Launching IE");
            capabilities = DesiredCapabilities.internetExplorer();
            capabilities.setBrowserName(DesiredCapabilities.internetExplorer().getBrowserName());
            capabilities.setPlatform(org.openqa.selenium.Platform.WINDOWS);
            System.setProperty("webdriver.chrome.driver", "C://chromedriver.exe");
            URL url = new URL("http://localhost:4444/wd/hub");
            driver = new RemoteWebDriver(url, capabilities);
}}

Where do you think am I going wrong.

Appreciate your help!!!

Cheers

Richard Lavoie

unread,
Jan 18, 2013, 4:51:39 PM1/18/13
to webd...@googlegroups.com
The property has to be set on the executing slave node with a -D jvm parameter.

It makes no sense in the first place to set the property in local system when hou want the browser to be executed remotely.

R.

Prithvi Raj

unread,
Jan 18, 2013, 6:04:44 PM1/18/13
to webd...@googlegroups.com
Hi Richard,

Thanks for your help. I did try using it in the command prompt on the command prompt while starting the node
-Dwebdriver.chrome.driver= C:\Grid Files\chromedriver_win_23.0.1240.0\chromedriver.exe

But still the same error. Can you please advise how to go about or is there a link where i can look into.

Thanks

Prithvi

Richard Lavoie

unread,
Jan 18, 2013, 6:10:34 PM1/18/13
to webd...@googlegroups.com
I'm on my phone atm, but the -D goes before the -jar param and make sure you double quote the path

Richard Lavoie

unread,
Jan 18, 2013, 6:16:30 PM1/18/13
to webd...@googlegroups.com
Try to look on http://code.google.com/chromedriver for some hint on that system peoperty

Prithvi Raj

unread,
Jan 18, 2013, 7:41:33 PM1/18/13
to webd...@googlegroups.com
Hi Richard,

Thank you very much and you have been of great help. That was my blunder by setting the system propertly locally instead on remote file system.

Thank you again Richard.

It all up and running.

Cheers!!!

Prithvi

Richard Lavoie

unread,
Jan 18, 2013, 8:35:34 PM1/18/13
to webd...@googlegroups.com
You're welcome

R.

Bill Ross

unread,
Jan 19, 2013, 4:14:18 PM1/19/13
to webd...@googlegroups.com
Fwiw if you put chromedriver.exe on the machine's PATH, you don't have to specify the location.

Bill

darrell

unread,
Jan 20, 2013, 10:34:30 AM1/20/13
to webdriver
To add to this, I usually launch my tests from a batch file. If the
chromedriver.exe is located in "C:\selenium" then at the start of the
batch file I put:

set PATH=C:\selenium;%PATH%

This insures I get the chromedriver.exe I want and not something
someone might have installed in C:\Windows or C:\Windows\system32.

On Jan 19, 4:14 pm, Bill Ross <r...@cgl.ucsf.edu> wrote:
> Fwiw if you put chromedriver.exe on the machine's PATH, you don't have
> to specify the location.
>
> Bill
>
> On 1/18/2013 3:04 PM, Prithvi Raj wrote:
>
>
>
>
>
>
>
> > Hi Richard,
>
> > Thanks for your help. I did try using it in the command prompt on the
> > command prompt while starting the node
> > -Dwebdriver.chrome.driver= C:\Grid
> > Files\chromedriver_win_23.0.1240.0\chromedriver.exe
>
> > But still the same error. Can you please advise how to go about or is
> > there a link where i can look into.
>
> > Thanks
>
> > Prithvi
>
> > On Sat, Jan 19, 2013 at 3:21 AM, Richard Lavoie
> > <lavoie.rich...@gmail.com <mailto:lavoie.rich...@gmail.com>> wrote:
>
> >     The property has to be set on the executing slave node with a -D
> >     jvm parameter.
>
> >     It makes no sense in the first place to set the property in local
> >     system when hou want the browser to be executed remotely.
>
> >     R.
>
> >     On 2013-01-18, at 15:25, Prithvi Raj <mprithvi...@gmail.com
> >>     <lavoie.rich...@gmail.com <mailto:lavoie.rich...@gmail.com>> wrote:
>
> >>         If you look on the link that Mike sent, there is an example
> >>         of Capability configuration and it explains the problem that
> >>         I'm talking about.
>
> >>         R.
>
> >>         On 2013-01-18, at 13:50, Prithvi Raj <mprithvi...@gmail.com
> >>         <mailto:mprithvi...@gmail.com>> wrote:
>
> >>>         Richard,
>
> >>>         Thanks. I have also attached the console when after
> >>>         connecting the hub and node. This are the browsers
> >>>         configured on my slave.
>
> >>>         Can you throw some light on the capability object? I see
> >>>         that DesiredCapabilities is derived from Capability Interface.
> >>>         If you can direct me with a snippet that would be great.
>
> >>>         Mike - Thanks I did configured the grid seeing that website
> >>>         and I could successfully configure.
>
> >>>         I did configured TestNG with parallel attribute and thread
> >>>         counts. Anyways I will ask in the TestNg forum as well if I
> >>>         am doing something wrong.
>
> >>>         Cheers!!!
>
> >>>         Prithvi
>
> >>>         On Fri, Jan 18, 2013 at 11:34 PM, Richard Lavoie
> >>>         <lavoie.rich...@gmail.com <mailto:lavoie.rich...@gmail.com>>
> >>>         wrote:
>
> >>>             What do you see when you connect to the console of the
> >>>             grid ? what are the browsers configured for your slave ?
>
> >>>             Mouse over the icons to see the capabilities handled for
> >>>             each browsers.
>
> >>>             Also the problem might also be with the Platform
> >>>             capability matching (I've had problems with that in the
> >>>             past in previous versions, dunno if it was fixed), try
> >>>             creating yourself a Capability object without using
> >>>             DesiredCapabilities.firefox() and just specify the
> >>>             browser attribute. See if that helps.
>
> >>>             On Fri, Jan 18, 2013 at 12:59 PM, Prithvi Raj
> >>>             <mprithvi...@gmail.com <mailto:mprithvi...@gmail.com>>
> >>>             wrote:
>
> >>>                 Hi Richard,
>
> >>>                 Both of them have been started as I had prepared a
> >>>                 bat file which invokes the grid and node together
> >>>                 and I can see the console which shows the number of
> >>>                 instances of different browsers. Also I had changed
> >>>                 the instances in WebConfig.txt file.
>
> >>>                 So Its up and running but the tests are not getting
> >>>                 executed.
> >>>                 What could be the reason?
> >>>                 I have attached the screenshots for your reference.
>
> >>>                 Cheers!!!
>
> >>>                 Prithvi
>
> >>>                 On Fri, Jan 18, 2013 at 10:48 PM, Richard Lavoie
> >>>                 <lavoie.rich...@gmail.com
> >>>                 <mailto:lavoie.rich...@gmail.com>> wrote:
>
> >>>                     if you wanna know what are the slaves connected
> >>>                     to your grid, you can connect to your grid by
> >>>                     http onhttp://grid:4444/and follow the console
> >>>                     link
>
> >>>                     On Fri, Jan 18, 2013 at 12:17 PM, Richard Lavoie
> >>>                     <lavoie.rich...@gmail.com
> >>>                     <mailto:lavoie.rich...@gmail.com>> wrote:
>
> >>>                         On Fri, Jan 18, 2013 at 11:53 AM, Prithvi
> >>>                         Raj <mprithvi...@gmail.com
> >>>                         <mailto:mprithvi...@gmail.com>> wrote:
>
> >>>                             d by:
> >>>                             org.openqa.selenium.remote.ErrorHandler$UnknownServerException:
> >>>                             Error forwarding the new session cannot
> >>>                             find : {platform=WINDOWS,
> >>>                             ensureCleanSession=true, br
>
> >>>                         When you have a grid, you also need to start
> >>>                         a slave node to connect to this grid so you
> >>>                         have real executors. The grid only acts as a
> >>>                         proxy and cannot acts at the same time as a
> >>>                         slave executor.
>
> >>>                         So you have to start a Grid, and a slave node.
>
> >>>                         --
> >>>                         Richard Lavoie
> >>>                         IT consultant / consultant en informatique
>
> >>>                     --
> >>>                     Richard Lavoie
> >>>                     IT consultant / consultant en informatique
> >>>                     --
> >>>                     You received this message because you are
> >>>                     subscribed to the Google Groups "webdriver" group.
> >>>                     To post to this group, send email to
> >>>                     webd...@googlegroups.com
> >>>                     <mailto:webd...@googlegroups.com>.
> >>>                     To unsubscribe from this group, send email to
> >>>                     webdriver+...@googlegroups.com
> >>>                     <mailto:webdriver%2Bunsu...@googlegroups.com>.
> >>>                     For more options, visit this group at
> >>>                    http://groups.google.com/group/webdriver?hl=en.
>
> >>>                 --
> >>>                 You received this message because you are subscribed
> >>>                 to the Google Groups "webdriver" group.
> >>>                 To post to this group, send email to
> >>>                 webd...@googlegroups.com
> >>>                 <mailto:webd...@googlegroups.com>.
> >>>                 To unsubscribe from this group, send email to
> >>>                 webdriver+...@googlegroups.com
> >>>                 <mailto:webdriver%2Bunsu...@googlegroups.com>.
> >>>                 For more options, visit this group at
> >>>                http://groups.google.com/group/webdriver?hl=en.
>
> >>>             --
> >>>             Richard Lavoie
> >>>             IT consultant / consultant en informatique
> >>>             --
> >>>             You received this message because you are subscribed to
> >>>             the Google Groups "webdriver" group.
> >>>             To post to this group, send email to
> >>>             webd...@googlegroups.com
> >>>             <mailto:webd...@googlegroups.com>.
> >>>             To unsubscribe from this group, send email to
> >>>             webdriver+...@googlegroups.com
> >>>             <mailto:webdriver%2Bunsu...@googlegroups.com>.
> >>>             For more options, visit this group at
> >>>            http://groups.google.com/group/webdriver?hl=en.
>
> >>>         --
> >>>         You received
>
> ...
>
> read more »

Prithvi Raj

unread,
Jan 20, 2013, 12:29:39 PM1/20/13
to webd...@googlegroups.com
Dear Darell, Bill, Richard and Krishnan,

Thank you all very much.

Its all up and running now and I can execute it on multiple nodes. But can you just explain how does the mechanism works. Because I have a dual operating system where I had my Hub and a node in Windows OS and a node in Mac 10.7(this node is listening to the Windows hub). And my testSuite will run in 3 different browsers namely Chrome, IE and Firefox. So when I ran the test, Windows OS executed IE & Chrome and Mac executed Firefox only even after passing the ChromeDriver path in shell script while configuring the node in Mac(Mac has Chrome installed as well). Does that picks up the node automatically?

Thanks

Prithvi

To post to this group, send email to webd...@googlegroups.com.
To unsubscribe from this group, send email to webdriver+...@googlegroups.com.

Bill Ross

unread,
Jan 21, 2013, 5:23:31 PM1/21/13
to webd...@googlegroups.com
Prithvi Raj <mprit...@gmail.com> wrote:

> Dear Darell, Bill, Richard and Krishnan,
>
> Thank you all very much.
>
> Its all up and running now and I can execute it on multiple nodes. But can
> you just explain how does the mechanism works. Because I have a dual
> operating system where I had my Hub and a node in Windows OS and a node in
> Mac 10.7(this node is listening to the Windows hub). And my testSuite will
> run in 3 different browsers namely Chrome, IE and Firefox. So when I ran
> the test, Windows OS executed IE & Chrome and Mac executed Firefox only
> even after passing the ChromeDriver path in shell script while configuring
> the node in Mac(Mac has Chrome installed as well). Does that picks up the
> node automatically?

I would try running without chrome support on Windows, to see if you
can get it to run on the Mac node.

Bill

Satyaprakash Vyas

unread,
Apr 21, 2017, 6:25:17 PM4/21/17
to webdriver
Hi,

Can anyone help me out to know, how can we run our tests parallel if I do not use testng.

SP
Reply all
Reply to author
Forward
0 new messages