Passing Parameters through testng.xml

Test Case:

package testng;

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

public class PassingParameters 
{
	@Parameters({"username", "password"})
	
	@Test
	public void login (String username, String password)
	{
		System.out.println("User name :- " + username +"\n");
		
		System.out.println("Password :- " + password +"\n");
	}	

}

testng.xml

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Passing parameters Test Suite" >
  <test name="Parameterization Execution"  >
  <parameter name="username" value="selenium"/>
  <parameter name="password" value="testng123"/>
    <classes>
      <class name="testng.PassingParameters"/>      
    </classes>
  </test>
</suite>

Output:

[TestNG] Running:
  E:\Selenium\Myscripts\testng.xml

User name :- selenium

Password :- testng123


===============================================
Passing parameters Test Suite
Total tests run: 1, Failures: 0, Skips: 0
===============================================

 

Leave a Reply

Your email address will not be published. Required fields are marked *