...
/Parameterisation, DataProvider and Factory
Parameterisation, DataProvider and Factory
This lesson explains in detail how to parameterize a test and use @Parameter, @DataProvider and @Factory annotations effectively for testing purposes.
We'll cover the following...
@Parameters
#
Tests can be parameterized using @Parameter
. They can be passed from testng.xml. Parameters can be set at suite
level or test
level.
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Sample Test Suite">
<parameter name="browser" value="chrome" />
<test name="Sample Test">
<parameter name="browser" value="chrome" />
</test>
</suite>
Here in the above testng.xml, we set the parameter browser to chrome at the test suite level. The same parameter can be overridden at the test level as well, as shown.
To use parameter in the test method, follow the following approach.
@Parameters("browser")
@Test
public void testMethod(String browser) {
}
For configuration methods like @BeforeXXX
and @AfterXXX
, follow the following approach.
@Parameters("browser")
@BeforeMethod
public void initMethod(String browser)
...