【问题标题】:Trouble reading parameter values from testng.xml从 testng.xml 读取参数值时遇到问题
【发布时间】:2014-07-02 13:33:10
【问题描述】:

我在 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 -->

我错过了什么吗?

【问题讨论】:

  • 你的测试怎么样?
  • 我在 Eclipse 中将其作为 TESTng 测试运行

标签: java webdriver testng


【解决方案1】:

如果右键文件并作为testng test运行,默认不会拾取testng xml,这就解释了为什么没有拾取参数。
两种解决方案:

右键单击套件 xml 并使用 Run as ->testng 套件触发

转到Project->Properties->Testng->将此xml设置为您的模板xml,然后您可以作为testng测试运行

【讨论】:

  • 感谢以上信息,我可以在显式运行 testng.xml 文件时看到参数
猜你喜欢
  • 1970-01-01
  • 2022-11-10
  • 1970-01-01
  • 1970-01-01
  • 2016-06-03
  • 2021-12-16
  • 2018-02-27
  • 2018-06-06
  • 2019-01-28
相关资源
最近更新 更多