我在从 Eclipse IDE 中的 testng 测试用例内的 testng.xml 读取参数值时遇到问题。我有从 BeforeClass 启动的浏览器,在 @TEST 方法中,参数值为“NULL”...并且它要求我将 @Test 参数定义为可选...
我的Java代码
public class headerValidation extends init {
WebDriver driver;
@BeforeClass
public void beforeClass() {
driver = initBrowser(BrowserType.FIREFOX, "http://www.abc123.com/");
}
@Test
@Parameters(value = { "loginID", "PasswordKey", "testURL" } )
public void testLogin(String loginID, String PasswordKey, String testURL) throws Exception {
try {
driver.get(testURL);
driver.findElement(By.id("login-b")).click();
driver.findElement(By.id("login_e")).sendKeys(loginID);
driver.findElement(By.id("login_p")).sendKeys(PasswordKey);
driver.findElement(By.name("submit")).click();
}//try
catch (Exception e) {
e.printStackTrace();
}//catch
我的 Testng XML 文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="none">
<test name="Test">
<parameter name="loginID" value="emailadd@add2.com"></parameter>
<parameter name="PasswordKey" value="21232131"></parameter>
<parameter name="testURL" value="www.abctest.com"></parameter>
<classes>
<class name="org.pa.qa.headerValidation"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
我在这里遗漏了什么吗?
最佳答案
如果右键单击该文件并作为 testng test 运行,则默认情况下不会选取 testng xml,这解释了为什么未选取参数。
两种解决方案:
右键单击套件 xml 并使用 Run as ->testng suite 触发
或者
转到“项目”->“属性”->“Testng”-> 将此 xml 设置为模板 xml,然后就可以作为 testng test 运行
关于java - 从 testng.xml 读取参数值时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24499847/