我能够在与 Cucumber 集成时运行 testng 脚本。我已按照中定义的确切步骤进行操作http://automatictester.co.uk/2015/06/11/basic-cucumberjvm-selenium-webdriver-test-automation-framework/ link.
现在我还有一个要求。你能解释一下如何从 testng.xml 的参数标签中读取值吗?请参阅下面的示例:
<test name="ascentis.LoginDemo.Firefox">
<parameter name="BrowserName" value="Firefox" />
<parameter name="Environment" value="local" />
<packages>
<package name="runnerFiles.*"/>
</packages>
</test>
我必须从参数标签中读取 BrowserName 和环境值。我尝试对黄瓜的@Before方法使用@parameters,但它没有成功,并给出了异常,@Before钩子只接受一个参数,该参数也属于场景类型。你能解释一下如何从参数标签中读取值以在黄瓜的步骤定义中进行访问吗?
好吧,我不确定 CucumberJVM 的参数化是否测试testng.xml
级别才是您真正想要的。但是,如果您确实需要从中读取参数testng.xml
在你的 CucumberJVM 框架中创建一个文件,这里有一个(肮脏的)解决方案:
- make
DownloadFeatureRunner
扩展 CustomRunner 而不是AbstractTestNGCucumberTests
- 在 yout 中包含参数
testng.xml
file: <parameter name="someParam" value="someValue"/>
-
并实现新的父类:
public class CustomRunner implements IHookable {
public CustomRunner() {
}
@Parameters("someParam")
@Test(
groups = {"cucumber"},
description = "Runs Cucumber Features"
)
public void run_cukes(String someParam) throws IOException {
System.out.println(someParam);
(new TestNGCucumberRunner(this.getClass())).runCukes();
}
public void run(IHookCallBack iHookCallBack, ITestResult iTestResult) {
iHookCallBack.runTestMethod(iTestResult);
}
}
如您所见,您可以访问参数的值。现在取决于你想用它做什么。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)