简体   繁体   English

TestNG @AfterMethod变量范围

[英]TestNG @AfterMethod Variable Scope

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. 我们正在使用TestNG在Java中运行自动化测试,但是与此同时,我们试图跟踪某些测试的运行时间以及结果。 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. 这是因为在某些情况下,TestSuite B决定了TestSuite A的结果。要跟踪其中的某些信息,我想做的是保存URL字符串,响应字符串和整数的值。响应码。 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? 如何获取这些变量以及在@AfterMethod中的测试方法中为套件生成的值?

You can use the xmlTest parameter to pass values from your @test methods to your @afterMethod methods 您可以使用xmlTest参数将值从@test方法传递到@afterMethod方法

A sample: 一个样品:

public class Demo5Test { 公共类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"));

}

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM