0

I am performing unit testing using TestNG where I am testing my code using test cases defined in xml file.

I am performing login operation using the test case defined in xml file. But the catch is I want to send parameter as usersname and password in method login.

Is it possible to pass value(username and password) to login method in xml file where testcases are executed?

Following is my XML file

<suite name="Suite" parallel="none">
  <test name="Test">
    <classes>
      <class name="com.common.Login">
        <methods>
          <include name="login"/>
        </methods>
      </class>
      <class name="com.tmp.Documentrepository"/>
    </classes>
  </test>
</suite>

Thanks

f1sh
  • 11,489
  • 3
  • 25
  • 51
Isha Pinjarkar
  • 83
  • 1
  • 2
  • 8

1 Answers1

1

yes , you can send.

testNg file:

<suite name="API TEST CASES">


 <parameter name="userNmae" value="Raghav"/> 
  <parameter name="password" value="password"/> 

<test name="api test" parallel="methods">

    <groups>

        <run>
            <include name="test_proxy" />
        </run>

    </groups>

    <classes>
        <class name="com.spire.test.test" />
    </classes>

</test>


</suite>

Java class:

import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class test {
@Parameters({ "userNmae" ,"password"})
@Test(groups = { "test_proxy" })
public void test_proxy(String userNmae,String password) throws Exception {

    System.out.println(userNmae);
    System.out.println(password);

}

}

Raghav N
  • 201
  • 1
  • 6