我使用testNG
和Selenium webdriver2.0
。如何在@BeforeSuite中使用testNG @Parameters读取资源文件
在我testNG.xml
我有
<suite data-provider-thread-count="2" name="selenium FrontEnd Test" parallel="false" skipfailedinvocationCounts="false" thread-count="2">
<parameter name="config_file" value="src/test/resources/config.properties/"/>
<test annotations="JDK" junit="false" name="CarInsurance Sanity Test" skipfailedinvocationCounts="false" verbose="2">
<parameter name="config-file" value="src/test/resources/config.properties/"/>
<groups>
<run>
<include name="abstract"/>
<include name="Sanity"/>
</run>
</groups>
<classes>
</classes>
</test>
</suite>
在Java文件
@BeforeSuite(groups = { "abstract" })
@Parameters(value = { "config-file" })
public void initFramework(String configfile) throws Exception
{
Reporter.log("Invoked init Method \n",true);
Properties p = new Properties();
FileInputStream conf = new FileInputStream(configfile);
p.load(conf);
siteurl = p.getProperty("BASEURL");
browser = p.getProperty("BROWSER");
browserloc = p.getProperty("BROWSERLOC");
}
获取误差
AILED配置:@BeforeSuite initFramework org.testng.TestNGException: 参数“配置文件”是由@Configuration在met上需要的HOD initFramework 但仍未标记@optional或
定义如何使用@Parameters
的资源文件?
你的testng.xml数据缺少您的帖子.. –
请发布您的testng.xml文件的内容 - 它需要看到'config-file'参数的上下文。 – artdanil