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?
You can start each upload in parallel threads instead of using selenium grid to achieve this. You need to learn how multithreading works though. It's not right to use grid for executing in multiple browsers parallelly. You can invoke multiple browser sessions by just creating multiple driver objects, and managing them.
Run Tests in Parallel. On BrowserStack, you can run multiple Selenium Webdriver tests at the same time across various browser, device and OS combinations. This is called Parallel Testing. Parallel Testing gives you the same benefits as running a multi-threaded application.
With its support for parallel testing, TestNG makes it easy to perform parallel test execution. Using the auto-defined XML file, you can specify parallel attributes to classes, tests, and methods.
This is what you need, it is called "Selenium Grid"
http://selenium-grid.seleniumhq.org/
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With