I'm using Java, Gradle, TestNG, Selenium Hub and Node on Localhost and trying to run 5 tests in parallel, the following is a sample code.
This is Base class:
package tests.temp;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
public class TestBase
{
protected ThreadLocal<RemoteWebDriver> threadDriver = null;
@BeforeMethod
public void setUp() throws MalformedURLException {
threadDriver = new ThreadLocal<RemoteWebDriver>();
DesiredCapabilities dc = new DesiredCapabilities();
FirefoxProfile fp = new FirefoxProfile();
dc.setCapability(FirefoxDriver.PROFILE, fp);
dc.setBrowserName(DesiredCapabilities.firefox().getBrowserName());
threadDriver.set(new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), dc));
}
public WebDriver getDriver() {
return threadDriver.get();
}
@AfterMethod
public void closeBrowser() {
getDriver().quit();
}
}
Here is an example of 1 Test. Other Tests are the same except names and numbers:
package tests.temp;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.testng.annotations.Test;
public class Test01 extends TestBase
{
@Test
public void testLink()throws Exception
{
getDriver().get("http://www.yandex.ru");
WebElement textBox = getDriver().findElement(By.name("text"));
textBox.sendKeys("First test");
System.out.println("First test thread-count=\"1\"");
}
}
An XML-file with Suite, with all this 5 Tests:
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Parallel test runs" parallel="tests" thread-count="1">
<test name="Test_01">
<classes>
<class name="tests.temp.Test01" ></class>
</classes>
</test>
...
<test name="Test_05">
<classes>
<class name="tests.temp.Test05" ></class>
</classes>
</test>
</suite>
And the last - XML-file with Suite runner:
<suite name="Parallel Test Suite">
<suite-files>
<suite-file path="./testRunner.xml" />
</suite-files>
</suite>
The trouble is: in case I use thread-count="1" Build log in TeamCity looks fine, but Tests runs sequentially of course. TeamCity thread = 1
If thread-count="2" or any other value - Build log looks confusing and Tests counter value is not correct. But in IDEA - everything is cool and correct! TeamCity thread = 2
Does anyone know how to solve this trouble??