Running tests in parallel is leaving browsers open

333 views
Skip to first unread message

Rick Simpson

unread,
Jul 29, 2014, 9:53:09 PM7/29/14
to seleniu...@googlegroups.com
Hi,

I'm trying to run my Selenium tests in parallel and I'm finding that when I run more than 3 tests in a pass, browsers are left open after the run.  The more tests I run the more left over browsers I end up with.  If I run 10 test I might get 3 browsers still open.  If I run 80 tests I might get 20 browsers.  

I run my Selenium tests via Maven and use TestNg for the testing framework.  My POM looks like this:

...

<groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-surefire-plugin</artifactId>
         <version>2.16</version>
                <configuration>
                       <forkCount>2C</forkCount>
                       <reuseForks>true</reuseForks>
                       <parallel>methods</parallel>
                       <threadCount>10</threadCount
>
...


The parallelism is work, but I can't figure out why the browsers are being quit.  I've tried different forkCounts, reuseForks and parallel settings  but the basic result is always the same, the Webdriver doesn't doesn't quit at the end of some tests.  My tests all follow the same pattern.  I use an @BeforeMethod to instantiate the Webdriver, and and @AfterMethod to quit the Webdriver. 

Any help, tips or suggestions welcome.  Right now I'm doing this locally but ultimately want to merge this in to my main branch and run this on our grid.

Thanks

Mark Collin

unread,
Jul 30, 2014, 3:31:44 AM7/30/14
to seleniu...@googlegroups.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 post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/aade1e8d-2b53-4aa9-9171-cbebc461c6bd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Rick Simpson

unread,
Jul 30, 2014, 7:46:32 PM7/30/14
to seleniu...@googlegroups.com
Thanks for the pointers Mark,

I've looked at that project and mine is pretty much in line with it.  Tracking all the drivers created and quitting them in an @AfterSuite method cleans up the mess but doesn't really get the problem.  

I spent some more time today and discovered the problem isn't that the driver isn't failing try a quit, the driver is throwing an UnreachableBrowserException beforehand. So as many browsers are opened, more browser become unreachable and that is what is causing the orphaned browsers. 

I spent some time researching the cause of UnreachableBrowserExceptions and there doesn't seem to single cause.   Still stumped on the magic combination to get this working.

Krishnan Mahadevan

unread,
Jul 30, 2014, 10:28:23 PM7/30/14
to Selenium Users
Rick,

A few questions :

1. What browser are you running on ? I have seen Firefox start having problems after I have spun off 15 concurrent instances of it via Selenium. So in my grid environment I restrict the number of concurrent firefox sessions to 15.
2. Are you facing this problem when you run in a local mode (WebDriver driver = new FirefoxDriver() ) (or) are you facing this problem when you are running against a grid. If its the grid, please try to set the concurrent session value to 15 (or) below and see if that helps.




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 Scribbings @ http://rationaleemotions.wordpress.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 post to this group, send email to seleniu...@googlegroups.com.

Rick Simpson

unread,
Jul 31, 2014, 2:44:58 PM7/31/14
to seleniu...@googlegroups.com
Hi Krishnan,

Right now I'm just using Firefox on Mac locally.  Ultimately, I'll want run this on our grid, but for now I'm just trying to get it work.  I'm seeing this problem when I'm only spinning 5-10 instances.

Any suggestions welcome at this point.

Thanks
Rick

Krishnan Mahadevan

unread,
Aug 1, 2014, 10:45:28 AM8/1/14
to Selenium Users
Rick,

Nothing stands out immediately as possible reasons [ apart from the fact that there could be a mismatch between the selenium library and the firefox version being used ]. Just to rule this out, do you see the same behavior when you switch to Chrome browser ?

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 Scribbings @ http://rationaleemotions.wordpress.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 post to this group, send email to seleniu...@googlegroups.com.

Rick Simpson

unread,
Aug 1, 2014, 6:20:34 PM8/1/14
to seleniu...@googlegroups.com
Hi Krishnan,

I see the basic problem with Chrome. Chrome is launching a browser for each threadCount, looses contact with all but the last of that number.  I've made sure everything is the latest and greatest.  I've even striped down the the tests to just a single driver.get and a sleep.

I'm completely stumped at this point.

Rick

Krishnan Mahadevan

unread,
Aug 1, 2014, 11:10:34 PM8/1/14
to seleniu...@googlegroups.com
Rick
Can you please share a trimmed version of your code that can be used to recreate the problem ? Let me see what I can figure out. 

Please also include the following :
Selenium version being used. 
Chrome version. 
Chromdriver version

~ Krishnan

iSent. iPhone. iReget.iTypos!
--
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 post to this group, send email to seleniu...@googlegroups.com.

Amit Nigam

unread,
Aug 2, 2014, 2:43:05 AM8/2/14
to seleniu...@googlegroups.com
I am using it with Junit with parallel suites and parallel categories.it woks fine for me. You need to create watchman which close using browser and driver at end of test case even If it fails
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/90769CDF-6BC4-4C7A-A684-C648204BB136%40gmail.com.

For more options, visit https://groups.google.com/d/optout.


--
Thanks & Regards,

Amit K Nigam

Rick Simpson

unread,
Aug 4, 2014, 5:59:15 PM8/4/14
to seleniu...@googlegroups.com
Krishnan,

Attached is a zip of a stripped down version of a project.  There's only one test class with ten test cases that all do the same thing (visit google.com, wait 2 seconds, assertTrue).

Thanks for taking a look.

Rick
para.zip

Rahul

unread,
Aug 5, 2014, 4:10:21 AM8/5/14
to seleniu...@googlegroups.com
Hi Rick ,

I was able to reproduce the problem in your project para.zip.
Made some changes to your code and POM.xml. Now browser(driver) is quiting properly for each independent test thread.


<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<forkCount>1</forkCount>
<reuseForks>true</reuseForks>
<parallel>methods</parallel>
<threadCount>5</threadCount>

Below is nre 
package a_suite;

import static org.testng.Assert.assertEquals;

import java.lang.reflect.Method;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.browserlaunchers.Sleeper;
import org.openqa.selenium.firefox.*;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

public class Set_01_Test {

long delay = 2;
String address = "http://google.com";
//public RemoteWebDriver driver;
private static InheritableThreadLocal<WebDriver> driver = new InheritableThreadLocal<WebDriver>();
protected static void setDriverValue() {
driver.set(new FirefoxDriver());
}
public static WebDriver getDriver() {
try {
return driver.get();
} catch (Exception e) {
return null;
}
}
@BeforeMethod(alwaysRun = true)
public void setUp() {
setDriverValue();
}
@AfterMethod(alwaysRun = true)
public void tearDown() {
if (getDriver() != null) {
getDriver().quit();
driver.remove();
}
}

@Test
public void set_01_test01(Method method) {
System.out.println(method.getName());
getDriver().get(address);
Sleeper.sleepTightInSeconds(delay);
assertEquals(4, 4);
}

@Test
public void set_01_test02(Method method) {
System.out.println(method.getName());
getDriver().get(address);
Sleeper.sleepTightInSeconds(delay);
assertEquals(4, 4);
}

@Test
public void set_01_test03(Method method) {
System.out.println(method.getName());
getDriver().get(address);
Sleeper.sleepTightInSeconds(delay);
assertEquals(4, 4);
}

@Test
public void set_01_test04(Method method) {
System.out.println(method.getName());
getDriver().get(address);
Sleeper.sleepTightInSeconds(delay);
assertEquals(4, 4);
}

@Test
public void set_01_test05(Method method) {
System.out.println(method.getName());
getDriver().get(address);
Sleeper.sleepTightInSeconds(delay);
assertEquals(4, 4);
}

@Test
public void set_01_test06(Method method) {
System.out.println(method.getName());
getDriver().get(address);
Sleeper.sleepTightInSeconds(delay);
assertEquals(4, 4);
}

@Test
public void set_01_test07(Method method) {
System.out.println(method.getName());
getDriver().get(address);
Sleeper.sleepTightInSeconds(delay);
assertEquals(4, 4);
}

@Test
public void set_01_test08(Method method) {
System.out.println(method.getName());
getDriver().get(address);
Sleeper.sleepTightInSeconds(delay);
assertEquals(4, 4);
}

@Test
public void set_01_test09(Method method) {
System.out.println(method.getName());
Sleeper.sleepTightInSeconds(delay);
assertEquals(4, 4);
}

@Test
public void set_01_test10(Method method) {
System.out.println(method.getName());
getDriver().get(address);
Sleeper.sleepTightInSeconds(delay);
assertEquals(4, 4);
}
}


Running a_suite.Set_01_Test
Configuring TestNG with: TestNG652Configurator
set_01_test05
set_01_test04
set_01_test02
set_01_test01
set_01_test03
set_01_test07
set_01_test06
set_01_test09
set_01_test08
set_01_test10
Tests run: 10, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 77.334 sec - in a_suite.Set_01_Test

Results :

Tests run: 10, Failures: 0, Errors: 0, Skipped: 0
Reply all
Reply to author
Forward
0 new messages