TestNG :- 无法获得 context.getCurrentXmlTest()
TestNG :- not able to get context.getCurrentXmlTest()
我有一些其他的测试上下文,其中包含要导入和读取的自定义逻辑
"testConfigFile"
但是<我打算迭代多个测试,因此,尝试将测试数据读取为
@DataProvider(name = "testdata")
public Object[][] testdata(ITestContext context) {
Map<String, String> parameters = context.getCurrentXmlTest()
.getAllParameters();
System.out.println("-------");
Iterator it = parameters.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pairs = (Map.Entry) it.next();
String x = (String) pairs.getValue();
if (x.startsWith("created_")
&& !pairs.getKey().toString().contains("shareData")) {
String y = (String) universalMap.get(x);
parameters.put((String) pairs.getKey(), y);
}
}
return new Object[][] { { parameters } };
}
其中无法检测到 context 有一个 getCurrentXmlTest() 方法,即使在将其类型转换为
Map<String, String> parameters = (((ITestContext)context).getCurrentXmlTest())
.getAllParameters();
它仍然抛出:-
The method getCurrentXmlTest() is undefined for the type ITestContext
哦,我使用的是非常旧的 testng-5.4-jdk15.jar TestNG 库。
现在,我已经升级了它,现在工作正常。
谢谢。
我有一些其他的测试上下文,其中包含要导入和读取的自定义逻辑 "testConfigFile"
但是<我打算迭代多个测试,因此,尝试将测试数据读取为
@DataProvider(name = "testdata")
public Object[][] testdata(ITestContext context) {
Map<String, String> parameters = context.getCurrentXmlTest()
.getAllParameters();
System.out.println("-------");
Iterator it = parameters.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pairs = (Map.Entry) it.next();
String x = (String) pairs.getValue();
if (x.startsWith("created_")
&& !pairs.getKey().toString().contains("shareData")) {
String y = (String) universalMap.get(x);
parameters.put((String) pairs.getKey(), y);
}
}
return new Object[][] { { parameters } };
}
其中无法检测到 context 有一个 getCurrentXmlTest() 方法,即使在将其类型转换为
Map<String, String> parameters = (((ITestContext)context).getCurrentXmlTest())
.getAllParameters();
它仍然抛出:-
The method getCurrentXmlTest() is undefined for the type ITestContext
哦,我使用的是非常旧的 testng-5.4-jdk15.jar TestNG 库。
现在,我已经升级了它,现在工作正常。
谢谢。