TestNG TestListener - 如何在 TestListener beforeInvocation 方法中到达 testmethod 参数 [英] TestNG TestListener - How to reach testmethod parameter in TestListener beforeInvocation method

查看:31
本文介绍了TestNG TestListener - 如何在 TestListener beforeInvocation 方法中到达 testmethod 参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

xml文件中的参数设置在<include>标签内,如下所示:

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>
..

如果参数标签在include标签之外,当然我可以在beforeInvocation方法中到达测试参数,例如:method.getTestMethod().getXmlTest().getParameter("parameter1").但在这种情况下,需要将参数绑定到测试方法,而我得到 null 作为 getParameter 方法的返回值.

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.

谢谢,斯特里斯蒂

推荐答案

我找到了问题的答案.IInvokedMethodListener beforeInvocation 方法有 ITestResult 参数,它有 getParameters 和 setParameters 方法.或者IHookable接口让你处理testMethod的输入参数,并回调testMethod.

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, 斯特里斯蒂

这篇关于TestNG TestListener - 如何在 TestListener beforeInvocation 方法中到达 testmethod 参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆