I've got two nodes with same configurations(Win7, ie9). I set testNG to execute two tests one each node at the same time. Selenium Grid does open two browsers(one each node) at the same time, but the tests seem to be executed in just one browser -- the username is typed in in the same browser twice. And if I set thread-count=1
, both tests succeed.
The testNG test suite xml file:
<suite name="ExampleTest" parallel="tests" thread-count="2">
<test name="ExampleTest1">
<classes>
<class name="com.mycompany.testsuites.GridTest">
<methods>
<include name="test1"></include>
</methods>
</class>
</classes>
</test>
<test name="ExampleTest2">
<classes>
<class name="com.mycompany.testsuites.GridTest">
<methods>
<include name="test2"></include>
</methods>
</class>
</classes>
</test>
The test class GridTest :
public class GridTest {
private WebDriver driver;
String hubUrl = "http://12.11.14.15:4444/wd/hub";
@BeforeClass
public void beforeClass() throws MalformedURLException {
DesiredCapabilities capability = DesiredCapabilities.internetExplorer();
driver = new RemoteWebDriver(new URL(hubUrl), capability);
Page.setUp(driver); //Page is the base class of all page objects.
//The static setUp method assign a WebDriver object
//to static Page.driver, which shared by all pages.
}
@AfterClass
public void afterClass() {
driver.quit();
}
@Test
public void test1() {
driver.get("http://12.11.15.16");
LoginPage login = new LoginPage();
login.setUp(); // set up the Login Page
login.txtUsername().clear(); //clear the username input box
login.txtUsername().sendKeys("username"); // input user name
// ...
}
@Test
public void test2() {
driver.get("http://12.11.15.16");
LoginPage login = new LoginPage();
login.setUp();
login.txtUsername().clear();
login.txtUsername().sendKeys("username");
// ...
}
}
I use selenium-server-standalone-2.41.0.jar for the hub and nodes.