TestNG | User-specified TestNG XML parameters
You can add any number of custom parameters to a TestNG.xml file. Following is a code sample you can use to access and store custom parameters for use anywhere else in your test framework.
To store these parameters, you use parameter tags. These tags can substitute or be in addition to properties file values. They can be specified at the suite or test level. Test level parameters take precedence.
<suite name="TestSuite">
<parameter name="perfectoURL" value="https://yourcloud.perfectomobile.com"/>
<parameter name="perfectoUserName" value="username"/>
<parameter name="perfectoPassword" value="password"/>
<parameter name="inputWorkbook" value="test.xlsx"/>
<test name="iPhone Tests">
<parameter name="deviceSheet" value="iPhone"/>
<parameter name="devicesPerTest" value="3"/>
<parameter name="testFailureRetries" value="1"/>
<classes>
<class name="testing.Phone2TestNG" >
<methods>
...
To access all these parameters from within a test or test framework, you can use the following line of code. (ITestContexttestContext can be added as a parameter to any @Before, @Test, or @DataProvider annotated method.)
HashMap<String,String> parameters = new HashMap<String, String>(testContext.getCurrentXmlTest().getAllParameters());
For more information, read the TestNG documentation on parameters: http://testng.org/doc/documentation-main.html#parameters