我有一个public Dictionary<string,string> ListOfSections()
{
Dictionary<string,string> newDictionary = new Dictionary<string,string>();
IList<IWebElement> tdSectionName = sectionTable.FindElements(By.CssSelector("td.name"));
foreach (IWebElement element in tdName)
{
IWebElement hierarchy = element.FindElement(By.CssSelector("span[data-bind='text: hierarchyId']"));
IWebElement name = element.FindElement(By.CssSelector("span[data-bind='text: Name']"));
newDictionary.Add(hierarchy.Text, name.Text);
}
return newDictionary;
}
方法,并且我从@Test
获取测试用例名称。我需要并行运行测试用例:
@Dataprovider
如果我想并行运行测试用例 即如果我要并行执行“开发人员团队负责人”,“质量检查”,“业务分析师”,“ DevOps Eng”,“ PMO”,我该怎么办?
5个浏览器-每个浏览器运行不同的测试用例。
TestNG XML:
@Test(dataprovider="testdataprodivder")
public void TestExecution(String arg 1)
{
/* Read the testcases from dataprovider and execute it*/
}
@Dataprovider(name="testdataprodivder")
public Object [][]Execution() throws IOException
{
return new Object[][] {{"Developer"},{"Team Lead"},{"QA"},{"Business Analyst"},{"DevOps Eng"},{"PMO"} };
}
答案 0 :(得分:0)
一件事pubic
并不是作用域:) -您那里还有更多不正确的语法。数据提供程序中Object
后的空格不应存在,函数签名应为
public Object[][] Execution() throws IOException {
return new Object[][] {{"Developer"},{"Team Lead"},{"QA"},{"Business Analyst"},{"DevOps Eng"},{"PMO"} };
}
接下来,您的TestExecution
方法中的参数定义不正确。
public void TestExecution(String arg) {
// Execute your tests
}
最后,只要使用DataProvider
中的'p',就必须大写。这样就给我们留下了
@Test(dataProvider="testdataprovider")
public void TestExecution(String arg)
{
/* Read the testcases from dataprovider and execute it*/
}
@DataProvider(name="testdataprovider")
public Object[][] Execution() throws IOException
{
return new Object[][] {{"Developer"},{"Team Lead"},{"QA"},{"Business Analyst"},{"DevOps Eng"},{"PMO"} };
}
在这一点上,我不确定仍然存在哪些问题。这是您想要的东西吗?让我知道这是否有帮助。
答案 1 :(得分:0)
为了并行运行数据驱动的测试,您需要在parallel=true
中指定@DataProvider
。例如:
@Dataprovider(name="testdataprodivder", parallel=true)
public Object [][]Execution() throws IOException
{
return new Object[][] {{"Developer"},{"Team Lead"},{"QA"},{"Business Analyst"},{"DevOps Eng"},{"PMO"} };
}
要指定数据驱动测试使用的线程数,可以指定data-provider-thread-count
(默认为10)。例如:
<suite name="Smoke_Test" parallel="methods" thread-count="5" data-provider-thread-count="5">
注意:要为数据驱动的测试外部代码动态设置并行行为,可以使用QAF-TestNG extension,在其中可以使用global.datadriven.parallel
和<test-case>.parallel
{ {3}}。