I've searched and read almost every article about Selenium Grid and running tests in parallel with testNG. However, I still can't figure about what I'm doing wrong.
Using Page Object Pattern I'm testing http://www.gmail.com. I'm using Google Guice dependency injection in order to provide every page with WebDriver, for that I used @Provides annotation in AbstractModule class:
public class GmailModule extends AbstractModule {
@Override
protected void configure() { ... }
String NODE_URL = "http://localhost:5555/wd/hub";
@Provides
WebDriver getRemoteDriver() throws MalformedURLException {
ThreadLocal<RemoteWebDriver> threadDriver = new ThreadLocal<RemoteWebDriver>();
DesiredCapabilities capability = new DesiredCapabilities();
capability.setBrowserName(DesiredCapabilities.firefox().getBrowserName());
capability.setCapability(FirefoxDriver.PROFILE, new File(ResourceExaminer.getValueFromExpDataMap("firefoxprofile")));
capability.setPlatform(Platform.XP);
RemoteWebDriver webDriver = new RemoteWebDriver(new URL(NODE_URL), capability);
threadDriver.set(webDriver);
return threadDriver.get();
}
}
All pages extends Abstract page, where I'm passing the driver and then just use it.
public abstract class AbstractPage extends HTMLElements{
public WebDriver webDriver;
@Inject
public AbstractPage(WebDriver driver){
this.webDriver = driver;
PageFactory.initElements(new HtmlElementDecorator(webDriver), this);
}
}
Then all tests extends AbstractTestingClass, which is provided with Google @Guice annotation in order to inject the first page. I use the following cmd lines to run the hub and node with Selenium Grid:
java -jar selenium-server-standalone-2.39.0.jar -role hub -hubConfig DefaultHub.json java -jar selenium-server-standalone-2.39.0.jar -role node -nodeConfig DefaultNode.json
In DefaultNode.json I cut down the number of maxSessions=2 and browserName=firefox
My test suite contains the following
<suite name="PositiveTestSuite" parallel="classes" thread-count="2" verbose="2">
<test name="Attaching file">
<classes>
<class name="com.epam.seleniumtask.gmail.test.AttachingFilesTest"/>
</classes>
</test>
<test name="2nd">
<classes>
<class name="com.epam.seleniumtask.gmail.test.ChangeSignatureTest"/>
</classes>
</test>
<test name="3rd">
<classes>
<class name="com.epam.seleniumtask.gmail.test.CreateNewLabelTest"/>
</classes>
</test>
<test name="4th">
<classes>
<class name="com.epam.seleniumtask.gmail.test.DeletingMessagesTest"/>
</classes>
</test>
However, tests are running very strange -->
- 4 browsers are opened, not 2.
- 2 tests ARE running in parallel, but the other two are waiting in the other browsers.
My questions are - 1) Why I still have 3 browsers even if I restrict the number of them in Selenium Grid? 2) How can I force my tests to run in only 2 browsers? 2 tests in one, 2 in another?
Please, help me. I will appreciate any answer.