1. New ParameterDemo04 class
< /p>
2. Path to copy class
3. Testng.xml configuration class address and parameters
xml version="1.0" encoding="UTF-8"?>
<suite name="Suite" parallel="false">
<test name="Test">
<classes >
<class name="cn.xiaobing.testng.ParameterDemo04"/>
classes>
<parameter name="browserType" value="chrome">parameter>
test>
suite>
[email protected](value= {“browserType”})//The variable name is consistent with the xml configuration name
package cn.xiaobing.testng;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
public class ParameterDemo04 {
@Test
@Parameters(value= {"browserType"})//variable The name is consistent with the xml configuration name
public void test(String bt) {
System.out.println("The browser currently used for testing is:"+bt);
}
}
5. Run (step on the pit)
The reason for the error: Because of the configuration parameters in testng.xml, to get the browserType parameter, you must run testng.xml
6. Run testng.xml and right click
7. Summary of learning, follow-up supplement of deficiencies!
xml version="1.0" encoding="UTF-8"?>
<suite name="Suite" parallel="false">
<test name="Test">
<classes >
<class name="cn.xiaobing.testng.ParameterDemo04"/>
classes>
<parameter name="browserType" value="chrome">parameter>
test>
suite>
package cn.xiaobing.testng;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
public class ParameterDemo04 {
@Test
@Parameters(value= {"browserType"})//variable The name is consistent with the xml configuration name
public void test(String bt) {
System.out.println("The browser currently used for testing is:"+bt);
}
}