我能够在与 Cucumber 集成后运行 testng 脚本。我已按照 http://automatictester.co.uk/2015/06/11/basic-cucumberjvm-selenium-webdriver-test-automation-framework/ 中定义的确切步骤进行操作链接。
现在我还有一个要求。你能解释一下如何从 testng.xml 的参数标签中读取值吗?请参见以下示例:
<test name="ascentis.LoginDemo.Firefox">
<parameter name="BrowserName" value="Firefox" />
<parameter name="Environment" value="local" />
<packages>
<package name="runnerFiles.*"/>
</packages>
</test>
我必须从参数标签中读取 BrowserName 和 Environment 值。我已经尝试将 @parameters 用于 cucumber 的 @Before 方法,但它没有成功,并且给出了一个异常(exception),即 @Before Hook 只接受一个类型场景的参数。你能解释一下如何从参数标签中读取值以在 cucumber 的 stepDefinations 中访问吗?
最佳答案
好吧,我不确定 CucumberJVM 的参数化是否在 testng.xml
上测试过水平是你真正要找的。但是,如果你真的需要从testng.xml
中读取参数文件在你的 CucumberJVM 框架中,这里有一个(肮脏的)解决方案给你:
- 制作
DownloadFeatureRunner
扩展 CustomRunner 而不是AbstractTestNGCucumberTests
- 在你的文件中包含参数
testng.xml
文件:<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); } }
如您所见,您可以访问参数的值。现在由您决定要用它做什么。
关于selenium-webdriver - 从 Cucumber stepdefs 中的 Testng.xml 文件中读取参数值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31924000/