Data Driven testing - Using parameters in TestNG

e.g. for the login case,  originally it's hard coded in the script. now using parameters in TestNG.xml

//private static String username = "user01;
//private static String password = "password";

This is a test level parameter:

step 1: add parameter in testng.xml

<suite name="Suite">
<test name="firstTest">
<parameter name="username" value="user01" />
<parameter name="password" value="password" />

step2:  add @Parameter annotation in the caes and pass paremeter to the method

@Parameters({ "username", "password" })
public void firstTest(String username, String password) {

SecurePage securepage = LoginPage.logIn(username, password);

step3: change the method invoked from other class, uncomment the hard coded lines, e.g code in LoginPage.java

public static SecurePage logIn(String username, String password) {

 

posted on 2019-10-05 08:46  子子清清  阅读(102)  评论(0)    收藏  举报

导航