user2473153
user2473153

Reputation: 181

Trying to automate with Selenium in parallel, but multiple webdriver instances freak out

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 ran 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?

Upvotes: 16

Views: 21416

Answers (6)

gest
gest

Reputation: 1

if you use webdriver , try maven-surefire-plugin :

<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.19</version>
        <configuration>
            <forkCount>4</forkCount>
        </configuration>
    </plugin>
</plugins>

in code use option 'forkCount' value 4 - number of processors. 4 processors = 4 JVM. U can start webdriver for each JVM ! link info http://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html

Upvotes: 0

Eyal Sooliman
Eyal Sooliman

Reputation: 2248

I would suggest that you build a driver for each browser and let your code know that you use more than multiple drivers. Other suggestion as already described above, using Selenium Grid is the best solution available: https://sqa.stackexchange.com/questions/5431/how-to-open-multiple-browsers-using-webdriver https://github.com/SeleniumHQ/selenium/wiki/Grid2

Upvotes: 0

ajahongir
ajahongir

Reputation: 479

It's possible to run selenium instances concurrently. When selenium runs browser instances, it opens the connection on port 7055 by default.

So, if you want to run multiple instances, you have to run them on different ports.

Upvotes: 0

Narayan Raman
Narayan Raman

Reputation: 891

You could try with Sahi http://sahi.co.in/. It can run multiple instances of browsers in parallel.

Do look at how Sahi does file uploads though. http://sahi.co.in/w/_setFile

Upvotes: 0

Manigandan
Manigandan

Reputation: 5080

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

I hope this link will show you how to run a tests in parallel in same machine.

In the above given link the user said to create a five different programs to run in parallel. If you want to run single program in parallel, then just use TestNg or Junit to trigger multiple instance.

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 above xml file you can acheive parallelism in webdriver using grid.

Upvotes: 2

LINGS
LINGS

Reputation: 3630

This is what you need, it is called "Selenium Grid"

http://selenium-grid.seleniumhq.org/

Upvotes: 4

Related Questions