从黄瓜stepdefs中的Testng.xml文件读取参数值 [英] Reading parameter values from Testng.xml file in cucumber stepdefs
问题描述
我可以在与黄瓜整合后运行testng脚本。我遵循了 http://automatictester.co.uk/2015/06/06/basic-cucumberjvm-selenium-webdriver-test-automation-framework/ 链接。
I'm able to run testng scripts upon integrating with cucumber. I've followed the exact steps defined in http://automatictester.co.uk/2015/06/11/basic-cucumberjvm-selenium-webdriver-test-automation-framework/ link.
现在我还有一个要求。你能解释一下如何从testng.xml的参数标签中读取值。请参阅以下示例:
Now I’ve one more requirement. can you explain me how to read values from parameters tag of testng.xml. See below example:
<test name="ascentis.LoginDemo.Firefox">
<parameter name="BrowserName" value="Firefox" />
<parameter name="Environment" value="local" />
<packages>
<package name="runnerFiles.*"/>
</packages>
</test>
我必须从参数标签读取BrowserName和Environment值。我尝试使用@parameters的黄瓜的@Before方法,但它没有工作,并提供异常@Before钩只接受一个参数太类型情况。你可以解释一下如何从参数标签中读取值,以便在黄瓜的stepDefinations中访问。
I’ve to read BrowserName and Environment values from parameters tag. I’ve tried to use @parameters for @Before method of cucumber but it didn’t work out and gave exception that @Before hook only accepts one parameter that too of type scenario. can you explain me how to read values from parameters tag to access in stepDefinations of cucumber.
推荐答案
如果对 testng.xml
级别的CucumberJVM测试的参数化是你真正想要的。但是,如果你真的需要从你的CucumberJVM框架中的 testng.xml
文件读取参数,这里是一个(脏)解决方案:
Well, I'm not sure if parametrisation of CucumberJVM tests on testng.xml
level is what you are really looking for. However, if you really need to read parameters from testng.xml
file in your CucumberJVM framework, here is a (dirty) solution for you:
- make
DownloadFeatureRunner
扩展CustomRunner而不是AbstractTestNGCucumberTests
- 包含参数yout
testng.xml
file:< parameter name =someParamvalue =someValue/ < / p>
- make
DownloadFeatureRunner
extend CustomRunner instead ofAbstractTestNGCucumberTests
- include parameter in yout
testng.xml
file:<parameter name="someParam" value="someValue"/>
and also implement you new parent class:
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);
}
}
如您所见,您可以访问参数的值。这取决于你现在想做什么。
As you can see, you can access value of the parameter. It's up to you what you want to do with it now.
这篇关于从黄瓜stepdefs中的Testng.xml文件读取参数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!