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