How to get a variable value from a test method with TestNG Listeners

只谈情不闲聊 提交于 2019-12-22 11:33:57

问题


I'm using TestNG to run automation tests. I also implemented TestNG Listener to save the test results in a certain format.

For some specific scenario I need to do the following: When a test runs, a value is assigned to a variable (local method variable). I need to pass the value of the variable to the TestNG Listener class I implemented. There are various methods (ontestStart, onTestFinish, onTestSuccess/Failure/Skipped), but I cannot figure out how to get the variable at run time. And I didn't find it in TestNG documentation.

Can anyone please help? Or share his/her experience with a similar issue.

Thanks!


回答1:


You can try by 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)). Then you'll find the values from ITestResult into your custom reporter.



来源:https://stackoverflow.com/questions/32339875/how-to-get-a-variable-value-from-a-test-method-with-testng-listeners

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!