not running parallel using Testng

1,468 views
Skip to first unread message

Rajiv Nanduani

unread,
Feb 19, 2013, 3:50:41 AM2/19/13
to seleniu...@googlegroups.com
Hi all,

I have to run my test parallel in different browsers at same time. I have used testng but still it is not running in parallel. It is running sequentially one by one.first it opens Firefox, after completion it open IE.

like my test() need to be run in fireox and test2() in IE parallel at same time


Please have a look & correct me if any thing wrong.


----------------------------------------------------------------------------------------------------
package remotRuneWebdriver;

import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class ParallelRun {
   
   
    @BeforeTest

    public void setUp() throws Exception {
    System.out.println("firefox Started");
    }

    @Test

    public void test() {
    DesiredCapabilities capability = DesiredCapabilities.firefox();
    RemoteWebDriver driver = null;
    try {
        driver = new RemoteWebDriver(new URL(String.format("http://127.0.0.1:4444/wd/hub")), capability);
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    driver.get("http://www.google.co.in/");

    driver.findElement(By.name("q"));
    driver.findElement(By.name("q"));
    driver.findElement(By.name("q"));
    driver.findElement(By.name("q"));
    try {
        driver.wait(10000);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    driver.quit();

    }
   
    @Test
    public void test2() {
        DesiredCapabilities capability = DesiredCapabilities.internetExplorer();
        capability.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
    RemoteWebDriver driver = null;
    try {
        driver = new RemoteWebDriver(new URL(String.format("http://127.0.0.1:4444/wd/hub")), capability);
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    driver.get("http://www.google.co.in/");

    driver.findElement(By.name("q"));
    try {
        driver.wait(50000);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    driver.quit();

    }
   


}

----------------------------------------------------------------------------------------------------------------------------


testng xml file:
____________________________________________________________________________

<?xml version="1.0" encoding="UTF-8"?>
<suite name="Selenium TestNG Suite" parallel="tests"
    thread-count="2">

    <test name="Selenium TestNG - 1">
        <classes>
            <class name="remotRuneWebdriver.ParallelRun" />
        </classes>
        </test>
</suite>

_-------------------------------------------------------------------------------------------------------------------------------
______________________________________________________________________________

--

Regards

RAJIV KUMAR NANDVANI

http://rajivkumarnandvani.wordpress.com
http://testeverythingqtp.blogspot.com/



Krishnan Mahadevan

unread,
Feb 19, 2013, 5:59:44 AM2/19/13
to seleniu...@googlegroups.com
The issue lies in your suite xml file.

You asked TestNG to run "tests" in parallel but your suite xml has ONLY one test. Please donot confuse this test with the @Test annotated method.
Here a test means <test> tag.

Change your parallel="methods" and you should see parallelism kick in.

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/


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Rajiv Nanduani

unread,
Feb 19, 2013, 7:09:50 AM2/19/13
to seleniu...@googlegroups.com
Hi Krishnan,

Thanks a lot for guiding me  I was confused with test. Now i have updated the xml file the but still it is not showing in parallel means two browsers are not opening at same time. it is opening one after one(after completion of one).

xml file
----------------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<suite name="Selenium TestNG Suite" parallel="methods"
    thread-count="3">


    <test name="Selenium TestNG - 1">
        <classes>
            <class name="remotRuneWebdriver.ParallelRun" />
        </classes>
        </test>
       
         <test name="Selenium TestNG - 2">

        <classes>
            <class name="remotRuneWebdriver.ParallelRun" />
        </classes>
        </test>
</suite>
----------------------------------------------------------------------------------------------------

please guide me..

Krishnan Mahadevan

unread,
Feb 19, 2013, 7:52:28 AM2/19/13
to seleniu...@googlegroups.com
Rajiv,
You changed your suite to now include two tests :)
You should first ascertain if TestNG is indeed spawning your tests [@Test annotated methods] in parallel.

I normally use a 

System.out.println("Thread id = " + Thread.currentThread().getId());

to print the thread ids.

If I see the same value then it means there is no parallelism being involved. If I see unique values then it means TestNG is indeed spawning the tests in parallel.

On a side note, I think you need to spend some time trying to understand TestNG a bit more before you start using it in your Selenium Tests.

There are a lot of things that you haven't told us yet. You seem to be using the Grid. So you need to tell us how exactly you spawned the grid and the node etc.,

To summarise, your question doesnt have anything to do with Selenium/WebDriver for that matter, but seems to be a question related to TestNG. I would encourage you to post it on testng-users forum.

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/


Rajiv Nanduani

unread,
Feb 19, 2013, 8:15:27 AM2/19/13
to seleniu...@googlegroups.com
Thanks Krishnan for replying..

I have checked thread id it is showing different for each test
Thread id = 11
internetExplorer Started
Thread id = 10
firefox Started
Thread id = 13
firefox Started
Thread id = 14
internetExplorer Started


There are a lot of things that you haven't told us yet. You seem to be using the Grid. So you need to tell us how exactly you spawned the grid and the node etc.,

I have started the seleium grid server

java -jar selenium-server-standalone-2.25.0.jar -role hub

and also started the node/webdriver

java -jar selenium-server-standalone-2.25.0.jar -role webdriver -hub http://localhost:4444/grid/register

Krishnan Mahadevan

unread,
Feb 19, 2013, 8:16:22 AM2/19/13
to seleniu...@googlegroups.com
So that answers your question. TestNG is indeed spawning your threads in parallel !

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/


Rajiv Nanduani

unread,
Feb 19, 2013, 8:20:35 AM2/19/13
to seleniu...@googlegroups.com
ya but browsers are opening in sequentially... :(

Isaac Howard

unread,
Feb 19, 2013, 11:22:57 AM2/19/13
to seleniu...@googlegroups.com
Another thing to look at is how many instances of FF and IE are on the node? The default should be 5 FF and 5 IE, but if it's only running one instance of each.

2nd. you can also add this
<?xml version="1.0" encoding="UTF-8"?>
<suite name="Selenium TestNG Suite" parallel="methods" thread-count="3">

    <test name="Selenium TestNG - 1" parallel="tests" thread-count="2">
        <classes>
            <class name="remotRuneWebdriver.ParallelRun" />
        </classes>
        </test>
        
         <test name="Selenium TestNG - 2" parallel="tests" thread-count="2">
        <classes>
            <class name="remotRuneWebdriver.ParallelRun" />
        </classes>
        </test>
</suite>

To make your threaded 'methods' run in multiple threads.

Last but not least, what is the power behind your nodes? I've noticed that when running on 'not so awesome' VMs that the node can't handle lots of simultaneous connections, and it looks like it's executing in series.

Isaac

ALISTER ERNEST

unread,
Feb 19, 2013, 1:43:07 PM2/19/13
to seleniu...@googlegroups.com
To add to Issac's point, if you have a default value of just 1 instance of firefox running on your system, then the tests will be sequential though your testng.xml wants them to run in parallel. You might want to provide more than 1 instance of firefox for the tests to start in parallel.

I usually start my firefox node like this. Try it and see if this helps.

java -jar selenium-server-standalone-2.25.0.jar -role node -hub http://localhost:4444/grid/register -maxSession 10 -browser browserName=firefox,platform=WINDOWS,maxInstances=10 -port 5555


Thanks,
Alister Ernest

Rajiv Nanduani

unread,
Feb 20, 2013, 6:55:34 AM2/20/13
to seleniu...@googlegroups.com
Thanks all now its working fine using methods :)

To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/6LCGegZCRyoJ.

For more options, visit https://groups.google.com/groups/opt_out.
 
 

Rajiv Nanduani

unread,
Feb 21, 2013, 5:47:25 AM2/21/13
to seleniu...@googlegroups.com
Finally i am able to run in parallel mode. Thanks all for guiding me
Special thanks to krishnan & Issac

hers is the XML 

i have 4 @tests/methods in parallel.ParallelRUN java file

in Firefox max instance 5 so i used 4 threads for this <test name="Selenium TestNG - 1" parallel="methods" thread-count="4">

In IE only one max instance is supported so i did not used  parallel  for this  <test name="Selenium TestNG - 2" >

I need to run in two browsers (Firefox and IE) simultaneously   I used two tests in XML using parallel="tests" thread-count="2"
now its open 4 firefox browsers at one go
and one IE instance, run 4 times for IE



-----------------------------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>

<suite name="Same TestCases on Different Browser" verbose="3"  parallel="tests" thread-count="2"> 
  
<test name="Selenium TestNG - 1" parallel="methods" thread-count="4">

<parameter name="browser"  value="firefox"/>
    <classes>
      <class name="parallel.ParallelRUN"/>
    </classes>
 </test>  
 <test name="Selenium TestNG - 2" >

<parameter name="browser"  value="iexplore"/>
    <classes>
      <class name="parallel.ParallelRUN"/>
    </classes>
 </test>  
</suite>
----------------------------------------------------------------------------------
Reply all
Reply to author
Forward
0 new messages