3

与黄瓜集成后,我可以运行 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 用于黄瓜的@Before 方法,但没有成功,并给出了@Before 钩子只接受一个也属于场景类型的参数的异常。你能解释一下如何从参数标签中读取值以在黄瓜的 stepDefinations 中访问。

4

1 回答 1

6

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 extend CustomRunner instead of AbstractTestNGCucumberTests
  • 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.

于 2015-08-11T19:29:15.540 回答