one class having multiple tests how to run parallel in multiple instances of same browser

1,778 views
Skip to first unread message

Ramesh

unread,
Oct 3, 2012, 2:46:56 PM10/3/12
to testng...@googlegroups.com
Hello Everybody,
I am new for Testng, One class having the multiple tests(methods). While running these tests it should run all the tests as parallel in multiple instances of same browser (Ex: Firefox) at a same time. So for every test it should open a new instance of a browser.

for example :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" verbose="1" parallel="methods" thread-count="3">
    <parameter name="selenium.browser" value ="firefox"/>
    <parameter name="selenium.url" value ="https://my.oxseed.net"/>
    <parameter name="startpage.workbasket" value ="Inbox"/>
  <test name="Run on firefox " > 
    <classes>
      <class name="com.oxseed.gui.TestNGTesting"/>
    </classes>   
  </test>
 </suite>

please guide me how to run parallel test

thanks
ramesh






edwolb

unread,
Nov 22, 2012, 12:51:03 PM11/22/12
to testng...@googlegroups.com
I'm not sure if your question was about the XML or the code.  If the XML, then it looks correct, in that your methods will run in parallel, up to 3 at at time.

Now you just need to make sure your driver is instantiated as part of a @BeforeMethod.  Because you're parallelizing on methods, each method will need its own driver.  Of course you'll also want to close it in an @AfterMethod.

--
chris

Mike

unread,
Nov 29, 2012, 12:42:36 PM11/29/12
to testng...@googlegroups.com
I never used the parallel threads, because I never figured out how I could pass the Selenium (WebDriver) instance to the various tests.  So I had my tests run externally and kept the Selenium instance as a static.

How do you pass that instance when using parallel threads like this?

Mike

Krishnan Mahadevan

unread,
Nov 29, 2012, 1:12:31 PM11/29/12
to testng...@googlegroups.com
Mike
If the webdriver instance is static then it is not going to work in parallel runs. You could instead use a ThreadLocal variable. 
--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/testng-users/-/Us3uL5yW85YJ.
To post to this group, send email to testng...@googlegroups.com.
To unsubscribe from this group, send email to testng-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.


--
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/

Mike

unread,
Nov 30, 2012, 1:57:15 PM11/30/12
to testng...@googlegroups.com
Yes, I knew static wouldn't work, since it would be common to all threads.  I was not aware of using ThreadLocal, so I'll research that.  I knew there had to be a way to do it.

Thanks.

Mike
Mike
To unsubscribe from this group, send email to testng-users+unsubscribe@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.

Nipun @ http://seleniumtesting-nx.blogspot.in/

unread,
Dec 12, 2013, 8:06:26 AM12/12/13
to testng...@googlegroups.com
Hi Krish,

Can you please provide us an example on using ThreadLocal variable to achieve the functionality of executing multiple tests parallel on multiple firefox windows using webdriver? 
Mike
To unsubscribe from this group, send email to testng-users+unsubscribe@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.

Krishnan Mahadevan

unread,
Dec 12, 2013, 8:12:29 AM12/12/13
to testng...@googlegroups.com

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/


To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.

To post to this group, send email to testng...@googlegroups.com.

Nipun @ http://seleniumtesting-nx.blogspot.in/

unread,
Dec 12, 2013, 8:54:10 AM12/12/13
to testng...@googlegroups.com

Hi Krish,

Thanks for giving insight on this. Your blog was really helpful.
Just tried the steps mentioned in your blog, I could successfully execute the tests from suite level using the testng.xml.
However, when i try to execute the tests from java class as individual tests(through eclipse), they fail throuwing the following error log:
==================================================================
java.lang.NullPointerException
    at project.ThreadLocalDemo.invokeBrowser(ThreadLocalDemo.java:28)
    at project.ThreadLocalDemo.testMethod1(ThreadLocalDemo.java:9)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
================================================================================

Can you please provide a solution to over come this and have the capability to run individual tests as well?

Krishnan Mahadevan

unread,
Dec 12, 2013, 8:56:53 AM12/12/13
to testng...@googlegroups.com
That is because the Listener that is responsible for providing WebDriver instances on a per thread level is perhaps not even being invoked

<listener class-name="organized.chaos.WebDriverListener"></listener>

You should try one of the following as detailed in this blog post of mine : http://rationaleemotions.wordpress.com/2012/01/27/listen-to-what-i-have-to-say-about-testng-listeners/


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/


Nipun @ http://seleniumtesting-nx.blogspot.in/

unread,
Dec 12, 2013, 9:19:27 AM12/12/13
to testng...@googlegroups.com
Sorry Krish, I could not find a direct solution to over come this.

I tried to give
"@Listeners(WebDriverListener.class)"
at the beginning of my class file, However it did not solve the issue. It would be really helpful if you can provide an insight on what i should be trying to get my tests run individually as well through eclipse.

Krishnan Mahadevan

unread,
Dec 12, 2013, 9:26:49 AM12/12/13
to testng...@googlegroups.com
Ok. Do the following

Step 1
Create a TestNG template xml as below [ call it myConfig.xml]:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="methods">
<listeners>
<listener class-name="organized.chaos.WebDriverListener"></listener>
</listeners>
</suite> <!-- Suite -->

Now from within eclipse go to project > Properties > TestNG

and in there give the complete path to where myConfig.xml resides on your desktop in the text box that says Template XML File.

After that you should be fine.





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/


Nipun @ http://seleniumtesting-nx.blogspot.in/

unread,
Dec 12, 2013, 9:56:49 AM12/12/13
to testng...@googlegroups.com

It did not work, Cant we have some more realistic means to obtain this?

Krishnan Mahadevan

unread,
Dec 12, 2013, 10:03:05 AM12/12/13
to testng...@googlegroups.com
I gave it my best shot ! Lets hope someone else can help you out in a better way...

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/


On Thu, Dec 12, 2013 at 8:26 PM, Nipun @ http://seleniumtesting-nx.blogspot.in/ <nip...@gmail.com> wrote:

It did not work, Cant we have some more realistic means to obtain this?

Reply all
Reply to author
Forward
0 new messages