We are using TestNG to run automated tests in java, but at the same time, we are trying to keep track of when certain tests were run, and what the outcome was. This is because we have situations where TestSuite B is determinant on the results of TestSuite A. To keep track of some of this information, what I want to do is to save the values of the URL string, response string, and an integer for the response code. These variables exist within the test method. How do I get those variables and the values generated within the test method in the @AfterMethod for the suite?
Asked
Active
Viewed 3,523 times
1
-
See post here: https://stackoverflow.com/questions/18597976/detect-test-failure-in-testng-aftermethod. It has a good explanation and examples. – G M Jan 11 '23 at 22:34
1 Answers
2
You can use the xmlTest parameter to pass values from your @test methods to your @afterMethod methods
A sample:
public class Demo5Test {
@Test(groups={"webtest"})
public void snapshotTest(ITestContext ctx){
ctx.getCurrentXmlTest().addParameter("param1","param2");
}
@AfterMethod
public void afterMethod(ITestContext ctx){
System.out.println(ctx.getCurrentXmlTest().getParameter("param1"));
}
}

Gosaka
- 181
- 7