注意:
在testng xml中,如果我将parallel =更改为类或方法,那么它可以很好地运行测试但是它不是并行地逐个执行。
如果我保持parallel =“tests”,那么它会并行运行,但它会在同一个VM中打开相同的浏览器三次,这是不正确的。
我的设置:
我有11个虚拟机设置,并且每个盒子上的每个浏览器都初始化了Selenium Grid节点。我已经创建了我的testng xml来在每个盒子上运行测试。测试是使用Webdriver用Java编写的。
我的问题:
当我执行测试时,将打开3个IE实例,并在同一个VM中并行运行测试。我有不同的VM设置与正确的节点,所以从我下面的testng xml,我期望测试在IE,FF和IE9中在不同的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);
}
}
}
答案 0 :(得分:1)
我在将以下内容添加到我的selenium节点后设法让它正常工作:
MAXINSTANCES = 5 maxSession = 5