TestNG parameterization application

1. New ParameterDemo04 class

Share pictures< /p>

2. Path to copy class

Share picture

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)

share picture

share picture

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

Share a picture

Share a picture

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);
}
}

Leave a Comment

Your email address will not be published.