我在用testNG
with Selenium webdriver2.0
.
In my testNG.xml
I have
<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:
initFramework 方法上的 @Configuration 需要参数“config-file”
但尚未标记为 @Optional 或定义于
如何使用@Parameters
对于资源文件?
看起来像你的config-file
参数未定义在<suite>
等级。有几种方法可以解决这个问题:
1. 确保<parameter>
元素定义在<suite>
标签但在任何之外<test>
:
<suite name="Suite1" >
<parameter name="config-file" value="src/test/resources/config.properties/" />
<test name="Test1" >
<!-- not here -->
</test>
</suite>
2. 如果您希望 Java 代码中的参数具有默认值,尽管事实上它是在testng.xml
或者没有,你可以添加@Optional
方法参数的注释:
@BeforeSuite
@Parameters( {"config-file"} )
public void initFramework(@Optional("src/test/resources/config.properties/") String configfile) {
//method implementation here
}
EDIT(基于发布的 testng.xml):
选项1:
<suite>
<parameter name="config-file" value="src/test/resources/config.properties/"/>
<test >
<groups>
<run>
<include name="abstract"/>
<include name="Sanity"/>
</run>
</groups>
<classes>
<!--put classes here -->
</classes>
</test>
</suite>
选项2:
@BeforeTest
@Parameters( {"config-file"} )
public void initFramework(@Optional("src/test/resources/config.properties/") String configfile) {
//method implementation here
}
无论如何,我建议不要使用两个具有几乎相同名称、相同值和不同范围的参数。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)