Reading parameter values from Testng.xml file in cucumber stepdefs

后端 未结 1 1426
遥遥无期
遥遥无期 2021-01-20 10:55

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-

相关标签:
1条回答
  • 2021-01-20 11:45

    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.

    0 讨论(0)
提交回复
热议问题