无法从testng.xml读取参数值

时间:2014-06-30 22:24:07

标签: java webdriver testng

我在Eclipse IDE的testng测试用例中从testng.xml读取参数值时遇到问题。我有从BeforeClass启动的浏览器和@TEST方法,参数值来自" NULL" ...并且它要求我将@Test参数定义为Optional ..

MyJavacode

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

My 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 -->

我在这里错过了什么吗?

1 个答案:

答案 0 :(得分:1)

如果右键单击该文件并作为testng测试运行,默认情况下不会选择testng xml,这解释了为什么没有拾取参数。
两种解决方案:

右键单击套件xml并使用Run as - &gt; testng suite

触发

OR

转到Project-&gt; Properties-&gt; Testng-&gt;将此xml设置为模板xml,然后您可以作为testng test

运行
相关问题