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) {
原文地址:https://www.cnblogs.com/amy2012/p/11623922.html