NOTE:
In the testng xml, if i change the parallel= to classes or methods then it runs the tests fine but it does it one by one not in parallel.
If I keep parallel="tests" then it runs in parallel but it opens the same browser three times in the same VM, which is not correct.
My setup:
I have 11 virtual machines setup and Selenium Grid nodes have been initialised for each browser on each box. I have created my testng xml to run tests on each box. The tests are written in Java using Webdriver.
My problem:
When I execute the test, 3 instances of IE are opened and the tests are run in parallel in the same VM. I have different VMs setup with the correct nodes so from my testng xml below, I expected the tests to run correctly in IE, FF and IE9 in a different VM.
TESTNG XML
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Parallel Tests" verbose="1" thread-count="3" parallel="tests" >
<tests>
<test name="IE11">
<parameter name="GridBrowser" value="iexplore11windows7"/>
<classes>
<class name="test.tes_connect.homepage.VerifyCarouselIsWorkingCorrectly" />
</classes>
</test>
<test name="FF25">
<parameter name="GridBrowser" value="firefox25win7"/>
<classes>
<class name="test.tes_connect.homepage.VerifyCarouselIsWorkingCorrectly" />
</classes>
</test>
<test name="IE9">
<parameter name="GridBrowser" value="iexplore9windows7"/>
<classes>
<class name="test.tes_connect.homepage.VerifyCarouselIsWorkingCorrectly" />
</classes>
</test>
</tests>
</suite>
CONFIGURATION.JAVA
package com.environments;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.openqa.selenium.remote.DesiredCapabilities;
public class Configuration {
public static DesiredCapabilities setCap;
public static String SeleniumGridSetup(String gridBrowser) {
String newGridBrowser = gridBrowser;
switch (newGridBrowser) {
// QA CLIENT 11
case "iexplore8windowsXP":
System.out.println("Internet Explorer 8 on Windows XP");
setCap= DesiredCapabilities.internetExplorer();
setCap.setBrowserName("internet explorer");
setCap.setPlatform(org.openqa.selenium.Platform.XP);
setCap.setVersion("8.0");
break;
case "firefox23":
System.out.println("Firefox 23 on Windows XP");
setCap= DesiredCapabilities.firefox();
setCap.setBrowserName("firefox");
setCap.setPlatform(org.openqa.selenium.Platform.XP);
setCap.setVersion("23.0");
break;
case "chromeLatestwinXP":
System.out.println("Chrome Latest Version on Windows XP");
setCap= DesiredCapabilities.chrome();
setCap.setBrowserName("chrome");
setCap.setPlatform(org.openqa.selenium.Platform.XP);
setCap.setVersion("L1");
break;
// QA CLIENT 10
case "iexplore7winXP":
System.out.println("Internet Explorer 7 on Windows XP");
setCap= DesiredCapabilities.internetExplorer();
setCap.setBrowserName("internet explorer");
setCap.setPlatform(org.openqa.selenium.Platform.XP);
setCap.setVersion("7.0");
break;
...... ETC ETC
}
return newGridBrowser;
}
TEST CLASS
package test.authentication;
import java.net.URL;
import static org.testng.Assert.fail;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
import ui.common.masthead;
import ui.authentication.logInPage;
import com.environments.Configuration;
import com.thoughtworks.twist.core.execution.TwistScenarioDataStore;
import com.data.Users;
public class LoginWithCorrectUsernameToTESConnect {
public WebDriver browser;
public static String url;
private StringBuffer verificationErrors = new StringBuffer();
@Autowired
private TwistScenarioDataStore scenarioStore;
// Selenium grid constructor for running tests in the Grid
@Parameters({"GridBrowser"})
public LoginWithCorrectUsernameToTESConnect(String GridBrowser) throws Exception {
Configuration.SeleniumGridSetup(GridBrowser);
browser = new RemoteWebDriver(new URL(Configuration.getHubUrl()), Configuration.setCap);
url = Configuration.getUrl();
browser.manage().window().maximize();
browser.navigate().to(url);
}
// Webdriver constructor for running tests using the Twist IDE
public LoginWithCorrectUsernameToTESConnect(WebDriver browser) throws Exception {
this.browser = browser;
browser.manage().window().maximize();
url = Configuration.getUrl();
browser.navigate().to(url);
}
// Test method for login to TES Connect start from here
@Test
public void loginWithDifferentUsersAndVerifyUsernameDisplayed() throws Exception {
for (int i = 0; i < Users.getUsernameFromList().size(); i++) {
try {
browser.findElement(masthead.UCP.loginLink).click();
browser.findElement(logInPage.usernameInput).sendKeys(Users.getUsernameFromList().get(i));
browser.findElement(logInPage.passwordInput).sendKeys(Configuration.getGenericUserPassword());
browser.findElement(logInPage.logInButton).click();
Assert.assertEquals(browser.findElement(masthead.UCP.userName).getText(), Users.getUsernameFromList().get(i), "Username did not match");
browser.findElement(masthead.UCP.logoutLink).click();
}
catch (Error e) {
verificationErrors.append(e.toString());
}
}
}
@AfterTest
public void tearDown() {
browser.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
}