TestNG TestListener - How to reach testmethod para

2019-09-12 20:55发布

The parameters in xml file are set inside the <include> tag, something like this:

<suite name="Suite">
  <listeners>
    <listener class-name="..MyTestListener"/>
  </listeners>
  <classes>
    <class name="Foo">
      <methods>
        <include name="myTest">
          <parameter name="parameter1"  value="parameterValue"/>
        </include>
..

Of course I can reach the test parameter in beforeInvocation method if the parameter tag is outside of the include tag, example: method.getTestMethod().getXmlTest().getParameter("parameter1"). But in this case parameter is necessary to be bound to the test method, and I get null as getParameter method return value.

Thanks, Stristi

标签: testng
2条回答
祖国的老花朵
2楼-- · 2019-09-12 21:43

I found the answer for my question. IInvokedMethodListener beforeInvocation method has ITestResult parameter, which has getParameters and setParameters methods. Or IHookable interface allows you to handle the input parameters of the testMethod, and call back the testMethod.

Br, Stristi

查看更多
beautiful°
3楼-- · 2019-09-12 21:48

As per the dtd here, parameters can be defined at the <suite> or at the <test> level. Parameters defined at the level override parameters of the same name in <suite>. So, one cannot associate a parameter at class level.

Also, a <test> in testng means a set of classes eg here. You can probably refer to the part of testng documentation, where testng xml nomenclature is explained, if it helps. The parameters in the <test> tag, can be referred by all the classes that fall under it.

查看更多
登录 后发表回答