Issues with Selenium and TestNG with DataProvider parallel=true

75 views
Skip to first unread message

Ajit Nair

unread,
Jun 6, 2011, 10:58:54 AM6/6/11
to Selenium Users
Hi,

I am facing issues running WebDriver with TestNG Data Provider and
with setting parallel=true;

I believe this is because of the WebDriver not being multi thread
safe.
I am using the selenium-server-standalone-2.0rc2.jar
Running it as a hub on one Window and as a webdriver on another
Window.

It does launch three parallel Windows for opening the browser, but
throws an exception as below.
I also tried to use the following URL -- http://127.0.0.1:5555/wd/hub
--
instead of driver = new RemoteWebDriver(new URL("http://localhost:
4444/wd/hub"), desiredCapabilities);

I still continue to get the exception

java.lang.IllegalStateException: Invalid use of
SingleClientConnManager: connection still allocated.
Make sure to release the connection before allocating another one.

If there is any mistake I am making in the way I am using the driver,
or if there is a workaround,
If there is any more detail required, please let me know

Thanks
Ajit Nair.

----------------------

The code to reproduce the issue

package com.abc.qa.xfort.auto;

import java.net.URL;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.TimeoutException;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
public class MasterAdminFunctionalTests {


private RemoteWebDriver driver;

@BeforeMethod(alwaysRun = true)
public void startDriver()
{

try
{
Capabilities desiredCapabilities= DesiredCapabilities.firefox();
driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/
hub"), desiredCapabilities);
driver.executeScript("if (window.screen){window.moveTo(0,
0);window.resizeTo(window.screen.availWidth,window.screen.availHeight);};");

}
catch (TimeoutException e) {
System.out.println("Could not reach the url: "+ "\n" +
e.fillInStackTrace());
Assert.fail("Could not reach the url: ");
}
catch (Exception e) {
System.out.println("Some other exception in reaching the url: "+
"\n" + e.fillInStackTrace());
Assert.fail("Could not reach the url: ");
}

}



@AfterMethod(alwaysRun = true)
public void closeBrowser()
{
try
{
driver.close();
}
catch (Exception e) {
System.out.println("Some other exception in closing the browser:
"+ "\n" + e.fillInStackTrace());
Assert.fail("Could not have a clean close ");
}
}

@DataProvider(name = "urlProvider", parallel = true)
public Object[][] urlProvider() {

return new Object[][]{{"http://www.google.com"},{"http://
www.yahoo.com"},{"http://www.microsoft.com"}};

}

@Test(dataProvider = "urlProvider", threadPoolSize=3)
public void openURL(String URL)
{
System.out.println("Inside openURL getting URL: " + URL);
driver.get(URL);
}



}


-----------------------------
The full stack trace is as given below

FAILED CONFIGURATION: @AfterMethod logout
java.lang.AssertionError: Could not have a clean close
at org.testng.Assert.fail(Assert.java:89)
at
com.arcot.qa.xfort.auto.MasterAdminFunctionalTests.logout(MasterAdminFunctionalTests.java:
51)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at
org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:
76)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:
525)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:202)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:757)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:846)
at
org.testng.internal.TestMethodWithDataProviderMethodWorker.call(TestMethodWithDataProviderMethodWorker.java:
73)
at
org.testng.internal.TestMethodWithDataProviderMethodWorker.call(TestMethodWithDataProviderMethodWorker.java:
14)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown
Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

FAILED: openURL("http://www.microsoft.com")
java.lang.IllegalStateException: Invalid use of
SingleClientConnManager: connection still allocated.
Make sure to release the connection before allocating another one.
at
org.apache.http.impl.conn.SingleClientConnManager.getConnection(SingleClientConnManager.java:
199)
at org.apache.http.impl.conn.SingleClientConnManager
$1.getConnection(SingleClientConnManager.java:173)
at
org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:
390)
at
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:
641)
at
org.openqa.selenium.remote.HttpCommandExecutor.fallBackExecute(HttpCommandExecutor.java:
272)
at
org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:
252)
at
org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:
389)
at
org.openqa.selenium.remote.RemoteWebDriver.get(RemoteWebDriver.java:
166)
at
com.arcot.qa.xfort.auto.MasterAdminFunctionalTests.openURL(MasterAdminFunctionalTests.java:
66)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at
org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:
76)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:673)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:846)
at
org.testng.internal.TestMethodWithDataProviderMethodWorker.call(TestMethodWithDataProviderMethodWorker.java:
73)
at
org.testng.internal.TestMethodWithDataProviderMethodWorker.call(TestMethodWithDataProviderMethodWorker.java:
14)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown
Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

----------------------------

Command line HUB

D:\NewDownloads\selenium-2.0rc2>java -jar selenium-server-
standalone-2.0rc2
-role hub
Jun 6, 2011 7:52:11 PM org.openqa.grid.web.Hub loadGrid1Config
INFO: Did not find a Grid 1.0 configuration file. Skipping Grid 1.0
setup.
Jun 6, 2011 7:52:11 PM org.openqa.jetty.http.HttpServer doStart
INFO: Version Jetty/5.1.x
Jun 6, 2011 7:52:11 PM org.openqa.jetty.util.FileResource <clinit>
INFO: Checking Resource aliases
Jun 6, 2011 7:52:11 PM org.openqa.jetty.util.Container start
INFO: Started
org.openqa.jetty.jetty.servlet.WebApplicationHandler@186768e
Jun 6, 2011 7:52:11 PM org.openqa.jetty.util.Container start
INFO: Started WebApplicationContext[/,/]
Jun 6, 2011 7:52:11 PM org.openqa.jetty.http.SocketListener start
INFO: Started SocketListener on 0.0.0.0:4444
Jun 6, 2011 7:52:11 PM org.openqa.jetty.util.Container start
INFO: Started org.openqa.jetty.jetty.Server@54172f
Jun 6, 2011 7:52:20 PM org.openqa.grid.internal.RemoteProxy <init>
WARNING: Max instance not specified. Using default = 1 instance
Jun 6, 2011 7:52:20 PM org.openqa.grid.internal.RemoteProxy <init>
WARNING: Max instance not specified. Using default = 1 instance
Jun 6, 2011 7:52:20 PM org.openqa.grid.internal.RemoteProxy <init>
WARNING: Max instance not specified. Using default = 1 instance
Jun 6, 2011 7:52:20 PM org.openqa.grid.internal.RemoteProxy <init>
WARNING: Max instance not specified. Using default = 1 instance
Jun 6, 2011 7:52:20 PM org.openqa.grid.internal.RemoteProxy <init>
WARNING: Max instance not specified. Using default = 1 instance
Jun 6, 2011 7:52:20 PM org.openqa.grid.internal.RemoteProxy <init>
WARNING: Max instance not specified. Using default = 1 instance
Jun 6, 2011 7:52:20 PM org.openqa.grid.internal.RemoteProxy <init>
WARNING: Max instance not specified. Using default = 1 instance

---------------


The WebDriver command console

D:\NewDownloads\selenium-2.0rc2>java -jar selenium-server-
standalone-2.0rc2.jar
-role webdriver -hub http://localhost:4444/grid/register -port 5555
19:52:19.836 INFO - Java: Sun Microsystems Inc. 17.0-b17
19:52:19.837 INFO - OS: Windows 7 6.1 x86
19:52:19.840 INFO - v2.0 [rc2], with Core v2.0 [rc2]
19:52:19.950 INFO - RemoteWebDriver instances should connect to:
http://127.0.0.
1:5555/wd/hub
19:52:19.951 INFO - Version Jetty/5.1.x
19:52:19.952 INFO - Started HttpContext[/selenium-server/driver,/
selenium-server
/driver]
19:52:19.953 INFO - Started HttpContext[/selenium-server,/selenium-
server]
19:52:19.953 INFO - Started HttpContext[/,/]
19:52:19.972 INFO - Started
org.openqa.jetty.jetty.servlet.ServletHandler@f9f9d8

19:52:19.973 INFO - Started HttpContext[/wd,/wd]
19:52:19.976 INFO - Started SocketListener on 0.0.0.0:5555
19:52:19.976 INFO - Started org.openqa.jetty.jetty.Server@e24e2a

--------------------------------
Reply all
Reply to author
Forward
0 new messages