我一直很难使用testng和cucumber设置在xml文件上传递参数。测试确实并行运行,但未传递参数,返回null。根据smartbear文档, @Parameters
应该行得通,但不行。下面是一段代码。我想知道是否有人遇到过这个问题。
聚甲醛
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<suiteXmlFiles>
<file>src/test/resources/testng.xml</file>
</suiteXmlFiles>
<properties>
<property>
<name>dataproviderthreadcount</name>
<value>2</value>
</property>
</properties>
xml\u文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite thread-count="2" name="Suite" parallel="tests">
<test name="Chrome">
<parameter name="os" value="Mac OSX 10.14"/>
<parameter name="browser" value="chrome"/>
<classes>
<class name="test.java.com.cucumber.TestRunner"/>
</classes>
</test> <!-- Test -->
<test name="Firefox">
<parameter name="os" value="Mac OSX 10.14"/>
<parameter name="browser" value="ff"/>
<classes>
<class name="test.java.com.cucumber.TestRunner"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
测试者
@CucumberOptions(features = "classpath:features", glue = "test.java.com.step_definitions", tags = "@signin")
public class TestRunner extends AbstractTestNGCucumberTests {
@Override
@DataProvider(parallel = true)
public Object[][] scenarios() {
return super.scenarios();
}
}
方法,将在其中传递参数
@BeforeClass
@Parameters(value={"os","browser"})
public DesiredCapabilities CBT_ChromeDesiredCap(String os, String browser){
HashMap<String, String> cbtoptions = new HashMap<String, String>();
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("name", "Demo");
caps.setCapability("os", os);
caps.setCapability("browser", browser);
caps.setCapability("version", "72");
caps.setCapability("screenResolution", "1366x768");
caps.setCapability("record_network", "false");
caps.setCapability("cbt:options", cbtoptions);
return caps;
}
smartbear文档https://support.smartbear.com/crossbrowsertesting/docs/automated-testing/parallel-testing.html
cucumber 文献https://cucumber.io/docs/guides/parallel-execution/
如果您需要更多信息,请留下评论,并感谢您的帮助!
1条答案
按热度按时间pxy2qtax1#
我可以用下面的解决方案来解决它。