【发布时间】:2020-11-26 06:28:55
【问题描述】:
我想从 TestNG 中的 @Test 获取参数名称及其值。这些参数由@DataProvider 提供。通常,当我想并行运行测试时,我可以将它存储在类的变量中,这不是一个好主意。这是我的代码:
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
public class TestHomePage{
@BeforeMethod(alwaysRun = true)
public void setup(Method method) throws Exception {
System.out.println("INFO ====setup===:" + method.getName());
// how can I get parameters and value from @Test?
//ex: sLogin="notLogin";sLike=""
}
@AfterMethod()
public void tearnDown(Method method) {
System.out.println("INFO ====tearnDown===:" + method.getName());
// how can I get parameters and value from @Test?
}
@DataProvider(name = "likedata", parallel = true)
public Object[][] likeDataprovider() throws Exception {
return new Object[][] { { "notLogin", "" }, { "loggedIn", "notLike" }, { "loggedIn", "liked" } };
}
@Test(dataProvider = "likedata")
public void verifyLikeFunction(String sLogin, String sLike, Method method) throws Exception {
// Test
}
}
谁能帮帮我?
谢谢。
【问题讨论】:
标签: automated-tests testng dataprovider testng-dataprovider