无法在并行模式下执行套件
Unable to execute Suite in Parallel Mode
XML代码:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="tests">
<test thread-count="5" name="Test">
<parameter name="browser" value="firefox">
<classes>
<class name="Crossbrowser.Test1"/>
</classes>
</parameter>
<test thread-count="5" name="chromeTest">
<parameter name="browser" value="chrome">
<classes>
<class name="Crossbrowser.Test1"/>
</classes>
</parameter>
</test> <!-- Test -->
</test> <!-- Test -->
</suite> <!-- Suite -->
Java代码:
package Crossbrowser;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
public class Test1 {
WebDriver driver;
@BeforeTest
@Parameters("browser")
public void setup(String browser) throws Exception{
//Check if parameter passed from TestNG is 'firefox'
if(browser.equalsIgnoreCase("firefox")){
//create firefox instance
driver = new FirefoxDriver();
}
//Check if parameter passed as 'chrome'
else if(browser.equalsIgnoreCase("chrome")){
//set path to chromedriver.exe
System.setProperty("webdriver.chrome.driver", "F:\New folder\chromedriver.exe");
//create chrome instance
driver = new ChromeDriver();
}
//Check if parameter passed as 'Edge'
else if(browser.equalsIgnoreCase("Edge")){
//set path to Edge.exe
System.setProperty("webdriver.edge.driver","F:\New folder (2)\MicrosoftWebDriver.exe");
//create Edge instance
driver = new EdgeDriver();
}
else{
//If no browser passed throw exception
throw new Exception("Browser is not correct");
}
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
@Test
public void testParameterWithXML() throws InterruptedException{
driver.get("xxxxxxxxxxxxx");
driver.manage().window().maximize();
driver.findElement(By.xpath("/html[1]/body[1]/div[2]/header[1]/ss-header[1]/div[1]/div[1]/div[1]/span[1]/a[1]")).click();
Thread.sleep(2000);
//Find user name
WebElement userName = driver.findElement(By.xpath("/html[1]/body[1]/div[2]/div[1]/div[1]/ss-auth-form[1]/md-card[1]/ss-login-form[1]/div[1]/form[1]/input[1]"));
//Fill user name
userName.sendKeys("xxxxxxxxxxxxx");
//Find password
WebElement password = driver.findElement(By.xpath("/html[1]/body[1]/div[2]/div[1]/div[1]/ss-auth-form[1]/md-card[1]/ss-login-form[1]/div[1]/form[1]/input[2]"));
//Fill password
password.sendKeys("1234567890");
Thread.sleep(2000);
driver.findElement(By.xpath("//form[@name='myForm']//ss-submit-button[@label='Log In']//input[@class='submit']")).click();
}
}
作为单一套件执行时,下面的代码工作正常,但在并行模式下执行相同操作时,出现错误:
The content of element type "test" must match
"(method-selectors?,parameter*,groups?,packages?,classes?)".
为什么会出现此错误?
PS: 在单独的网络浏览器中执行时,我没有收到此错误。我只有在并行模式下启动 运行 时才得到它。
在套件级别指定线程数并更改您的 testng xml 如下
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="tests" thread-count="5">
<test name="chromeTest">
<parameter name="browser" value="chrome">
<classes>
<class name="Crossbrowser.Test1"/>
</classes>
</parameter>
</test> <!-- Test -->
</suite>
请尝试关注XML。这对我有用。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="tests" thread-count="5" >
<test name="FirefoxTest">
<parameter name="browser" value="firefox" />
<classes>
<class name="Crossbrowser.Test1" />
</classes>
</test>
<test name="chromeTest">
<parameter name="browser" value="chrome" />
<classes>
<class name="Crossbrowser.Test1" />
</classes>
</test>
</suite>
XML代码:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="tests">
<test thread-count="5" name="Test">
<parameter name="browser" value="firefox">
<classes>
<class name="Crossbrowser.Test1"/>
</classes>
</parameter>
<test thread-count="5" name="chromeTest">
<parameter name="browser" value="chrome">
<classes>
<class name="Crossbrowser.Test1"/>
</classes>
</parameter>
</test> <!-- Test -->
</test> <!-- Test -->
</suite> <!-- Suite -->
Java代码:
package Crossbrowser;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
public class Test1 {
WebDriver driver;
@BeforeTest
@Parameters("browser")
public void setup(String browser) throws Exception{
//Check if parameter passed from TestNG is 'firefox'
if(browser.equalsIgnoreCase("firefox")){
//create firefox instance
driver = new FirefoxDriver();
}
//Check if parameter passed as 'chrome'
else if(browser.equalsIgnoreCase("chrome")){
//set path to chromedriver.exe
System.setProperty("webdriver.chrome.driver", "F:\New folder\chromedriver.exe");
//create chrome instance
driver = new ChromeDriver();
}
//Check if parameter passed as 'Edge'
else if(browser.equalsIgnoreCase("Edge")){
//set path to Edge.exe
System.setProperty("webdriver.edge.driver","F:\New folder (2)\MicrosoftWebDriver.exe");
//create Edge instance
driver = new EdgeDriver();
}
else{
//If no browser passed throw exception
throw new Exception("Browser is not correct");
}
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
@Test
public void testParameterWithXML() throws InterruptedException{
driver.get("xxxxxxxxxxxxx");
driver.manage().window().maximize();
driver.findElement(By.xpath("/html[1]/body[1]/div[2]/header[1]/ss-header[1]/div[1]/div[1]/div[1]/span[1]/a[1]")).click();
Thread.sleep(2000);
//Find user name
WebElement userName = driver.findElement(By.xpath("/html[1]/body[1]/div[2]/div[1]/div[1]/ss-auth-form[1]/md-card[1]/ss-login-form[1]/div[1]/form[1]/input[1]"));
//Fill user name
userName.sendKeys("xxxxxxxxxxxxx");
//Find password
WebElement password = driver.findElement(By.xpath("/html[1]/body[1]/div[2]/div[1]/div[1]/ss-auth-form[1]/md-card[1]/ss-login-form[1]/div[1]/form[1]/input[2]"));
//Fill password
password.sendKeys("1234567890");
Thread.sleep(2000);
driver.findElement(By.xpath("//form[@name='myForm']//ss-submit-button[@label='Log In']//input[@class='submit']")).click();
}
}
作为单一套件执行时,下面的代码工作正常,但在并行模式下执行相同操作时,出现错误:
The content of element type "test" must match "(method-selectors?,parameter*,groups?,packages?,classes?)".
为什么会出现此错误?
PS: 在单独的网络浏览器中执行时,我没有收到此错误。我只有在并行模式下启动 运行 时才得到它。
在套件级别指定线程数并更改您的 testng xml 如下
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="tests" thread-count="5">
<test name="chromeTest">
<parameter name="browser" value="chrome">
<classes>
<class name="Crossbrowser.Test1"/>
</classes>
</parameter>
</test> <!-- Test -->
</suite>
请尝试关注XML。这对我有用。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="tests" thread-count="5" >
<test name="FirefoxTest">
<parameter name="browser" value="firefox" />
<classes>
<class name="Crossbrowser.Test1" />
</classes>
</test>
<test name="chromeTest">
<parameter name="browser" value="chrome" />
<classes>
<class name="Crossbrowser.Test1" />
</classes>
</test>
</suite>