Jlearner
Jlearner

Reputation: 45

Trouble reading parameter values from testng.xml

I am having trouble reading parameter values from testng.xml inside a testng testcase in Eclipse IDE. I have browser initiated from BeforeClass and at @TEST method ,parameter values are coming as "NULL"...and it asks me to define my @Test parameters as 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 file

<?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="[email protected]"></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 -->

Am i missing something here?

Upvotes: 1

Views: 3613

Answers (1)

niharika_neo
niharika_neo

Reputation: 8531

If you right click on the file and run as testng test, the testng xml is not picked up by default, which explains why the parameters are not being picked up.
Two solutions :

Right click on the suite xml and trigger with Run as ->testng suite

OR

Go to Project->Properties->Testng-> Set this xml as your template xml and then you can run as testng test

Upvotes: 2

Related Questions