并行执行不适用于"tests"
中的属性suite.xml
。即使我设置了parallel ="tests"
,它仍然只按顺序执行。
请在下面找到我的suite.xml
和测试脚本
suite.xml:
<suite name="testsuite1" parallel="tests" thread-count="2">
<test name="gmailloginchrome">
<parameter name="platform" value="windows"></parameter>
<parameter name="browser" value="chrome"></parameter>
<classes>
<class name="sample.LoginChrome"></class>
</classes>
</test>
<test name="gmailloginie">
<parameter name="platform" value="windows"></parameter>
<parameter name="browser" value="ie"></parameter>
<classes>
<class name="sample.LoginChrome"></class>
</classes>
</test>
</suite>
我的测试脚本:
package sample;
public class LoginChrome {
WebDriver driver;
Logger log = Logger.getLogger(LoginChrome.class);
/**
* tests the login of Gmail for given credentials in Chrome
* @throws Exception
*/
@Test
public void loginTest() throws Exception {
System.out.println("Inside the test method");
log.info("started the test method");
log.info("entering credentials");
driver.findElement(By.id("identifierId")).clear();
driver.findElement(By.id("identifierId")).sendKeys("xyz@gmail.com");
driver.findElement(By.id("identifierNext")).click();
driver.findElement(By.name("password")).sendKeys("abc@2016");
Thread.sleep(3000);
driver.findElement(By.cssSelector("div#passwordNext")).click();
Thread.sleep(6000);
log.info("checking whether login successful or not");
String title = driver.getTitle();
log.info("Title is " + title);
Thread.sleep(3000);
Assert.assertEquals(title, "Inbox (7,258) - xyz@gmail.com - Gmail");
log.info("completed the test method");
}
/**
* sets the driver executable and opens the browser
* @param platform
* @param browser
* @return nothing
*/
@Parameters({ "platform", "browser" })
@BeforeMethod
public void beforeMethod(String platform, String browser) {
if(browser.contains("chrome")) {
System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") + "/drivers/chromedriver.exe");
driver = new ChromeDriver();
}
else if(browser.contains("ie")) {
System.setProperty("webdriver.ie.driver", System.getProperty("user.dir") + "/drivers/IEDriverServer.exe");
driver = new InternetExplorerDriver();
}
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get("https://www.gmail.com");
}
/**
* quits the driver & closes the browser
* @return nothing
*/
@AfterMethod
public void afterMethod() {
driver.quit();
}
}
答案 0 :(得分:0)
我遇到了这个问题。这是因为TestNG版本。如果我使用TestNG -6.9.10,相同的代码工作正常。代码没有错。