如何使用 TestNG 侦听器从测试方法中获取变量值
How to get a variable value from a test method with TestNG Listeners
我正在使用 TestNG 运行 自动化测试。我还实现了 TestNG Listener 以某种格式保存测试结果。
对于某些特定场景,我需要执行以下操作:
当测试运行s时,一个值被赋值给一个变量(局部方法变量)。
我需要将变量的值传递给我实现的 TestNG Listener class。有多种方法(ontestStart、onTestFinish、onTestSuccess/Failure/Skipped),但我不知道如何在 运行 时间获取变量。
而且我没有在 TestNG 文档中找到它。
有人可以帮忙吗?或分享 his/her 类似问题的经验。
谢谢!
您可以通过 listening to the method invocations and set values into the [ITestResult
](http://testng.org/javadocs/org/testng/IAttributes.html#setAttribute(java.lang.String, java.lang.Object)) 尝试。
然后你会发现从 ITestResult
到 your custom reporter.
的值
我正在使用 TestNG 运行 自动化测试。我还实现了 TestNG Listener 以某种格式保存测试结果。
对于某些特定场景,我需要执行以下操作: 当测试运行s时,一个值被赋值给一个变量(局部方法变量)。 我需要将变量的值传递给我实现的 TestNG Listener class。有多种方法(ontestStart、onTestFinish、onTestSuccess/Failure/Skipped),但我不知道如何在 运行 时间获取变量。 而且我没有在 TestNG 文档中找到它。
有人可以帮忙吗?或分享 his/her 类似问题的经验。
谢谢!
您可以通过 listening to the method invocations and set values into the [ITestResult
](http://testng.org/javadocs/org/testng/IAttributes.html#setAttribute(java.lang.String, java.lang.Object)) 尝试。
然后你会发现从 ITestResult
到 your custom reporter.