Running DataProvider in parallel with TestNG

103 views
Skip to first unread message

Eric Liu

unread,
Nov 4, 2019, 1:12:27 PM11/4/19
to Selenium Users

I set up my tests where each row in the dataProvider creates a new instance of the test class with its own web driver and runs some tests with the data passed in. I want to have all the tests execute simultaneously, however when I run the tests with the current setup, test "a" is instantiated and the first method is run, then test "b" is instantiated and the first method is run, etc. I want to be able to have tests a,b,c all execute at once side by side without waiting for each other to finish the previous step.

I've achieved this parallel behavior by creating 3 separate class files with individual dataproviders with one row of unique data and then calling parallel="classes", but how would I do it all in one class?


https://pastebin.com/kfHFxQHw


Oleksiy Kyrylenko

unread,
Nov 4, 2019, 2:02:27 PM11/4/19
to Selenium Users
there could be multiple factors that are not allowing you to run in parallel as of now. What bindings do you use?

Eric Liu

unread,
Nov 4, 2019, 2:07:17 PM11/4/19
to seleniu...@googlegroups.com
What do you mean by bindings? I have a class with dataProvider and Factory. Every time a row from DP is called it creates a new class with its own unique webdriver, opens a web page, and executes some tests on the page.

--
You received this message because you are subscribed to a topic in the Google Groups "Selenium Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/selenium-users/eMNhVrBgwdw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/3d8f26b3-df82-40d4-9230-85c530794504%40googlegroups.com.

⇜Krishnan Mahadevan⇝

unread,
Nov 4, 2019, 9:47:59 PM11/4/19
to Selenium Users
Eric,

If you use parallel=instances in your suite file, then the tests in all your test class instances will run at the same time.

parallel=classes makes sense only when you have 2 or more classes involved.

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/
My Technical Scribblings @ https://rationaleemotions.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 view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/CAK%3DR5kZz7-JkggZJEyFbjXUqn2hOhYkX%3Drgnypj9jAZObquosQ%40mail.gmail.com.

Alex K

unread,
Nov 5, 2019, 11:42:19 AM11/5/19
to Selenium Users
Selenium support multiple bindings such as Java, DotNet, Python, JS, etc. Enabling parallel execution works differently in different bindings, more specific - dependence on a test framework - testng, nunit, mstest, tc. In testng you need to set this in the xml file you use to execute your script, in nunit you need to provide parallelization attribute.
To unsubscribe from this group and all its topics, send an email to seleniu...@googlegroups.com.

Eric Liu

unread,
Nov 5, 2019, 11:44:52 AM11/5/19
to seleniu...@googlegroups.com
Ah, I'm running Windows 10, java, and testng

To unsubscribe from this group and all its topics, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/312cc5b3-f488-4b3b-b821-4452af95a4b0%40googlegroups.com.

Eric Liu

unread,
Nov 5, 2019, 3:50:56 PM11/5/19
to seleniu...@googlegroups.com
I am trying to run all x entries in the dataprovider at once by creating x instances of the dataprovider parent class. So I'd like there to be x windows that pop up and they all simultaneously go through the test steps.

⇜Krishnan Mahadevan⇝

unread,
Nov 5, 2019, 9:55:54 PM11/5/19
to Selenium Users
parallel=instances is designed to exactly do that.

The suite file that you shared doesnt have any parallel attribute defined. Please add it and try.

If its still not working then I would suggest that you do the following:

1. Make use of latest version of TestNG and try.
2. Create a simple standalone project that can be used to reproduce your issue. Ideally speaking you should try and remove selenium dependency also and just log the thread Ids [ Thread.currentThread().getId() ] and see if they are all the same or different. If they are different then it means that TestNG is indeed spinning off those tests in parallel. Then you can take a closer look at your browser instantiation logic to see if it has any bottlenecks around it. The reason why I say this is because this is a very basic usecase for TestNG and the codebase has a lot of tests around it to ensure that this functionality works and is not broken.
3. Share the project on the testng-users google forum [ Your question doesn't have anything to do with Selenium and am trying to ensure that we keep the forums relevant ]

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/
My Technical Scribblings @ https://rationaleemotions.com/

Eric Liu

unread,
Nov 6, 2019, 5:38:16 PM11/6/19
to seleniu...@googlegroups.com
Figured it out. It was because group-by-instances was set to true which I thought was for running all instances of a class together, but it really waits for each instance to complete step 1 before all moving forward to step 2, etc.
Sorry for the post here, thought I posted in the test-ng group.

Once again thanks for your helpful response!

Reply all
Reply to author
Forward
0 new messages