Back

Explore Courses Blog Tutorials Interview Questions
+1 vote
1 view
in DevOps and Agile by (19.7k points)

So I'm trying to create a java program that uses Selenium to automate a WebDriver to perform tasks on a website. At the moment, I'm using it for work in order to automate an annoying task where the user has to upload files to our database. I've already successfully made a program which automates this and saved myself hours of manual work.

Now I'm trying to get the program to run multiple browsers in parallel. I want to do this in order to speed up the rate at which I can upload files because most of the time is lost waiting for pages to load.

I've tested this with a much simpler version of my program and have managed to speed up simple tasks by 2-10 times by having tens to hundreds of threads open with their own WebDrivers.

The problem is, whenever I run more than 1 WebDriver the entire thing begins to randomly freak out at times, and at other times not work at all. I tried to use 'PhantomJSDriver' along with the latest 'PhantomJS.exe', however at times it would work, and most of the times it would do nothing. The same program that runs flawlessly with one driver running breaks down when they are run in parallel.

I've been trying to find reasons as to why this happens and ways around it, but I haven't found anything definite that I can use.

How can I go about automating web browsing in parallel with Selenium if possible, and if not, where should I look to in order to do this?

1 Answer

0 votes
by (62.9k points)

Actually using Grid you can automate the tests in parallel using the same machine or by using multiple machines (here machines in the sense of individual computers)

It is suggested to create five different programs to run in parallel. If you want to run a single program in parallel, then just use TestNG or Junit to trigger multiple instances.

This is the sample TestNg config code to run a test in parallel. Here I ran two threads. So it will invoke the TestNg @Test method of a given class file com.test.workflow.device.testcase20 in two threads.

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">

 <suite name="Suite1"  parallel="test" thread-count="2">

   <test name="Testcase20" >

    <classes>

        <class name="com.test.workflow.device.testcase20"/>

    </classes>

  </test>

 </suite>

By using the above XML file you can achieve parallelism in webdriver using grid.

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94k users

Browse Categories

...