I've been trying to retrieve some parameters from TestNG XML suite. A parameter with a testrail reference is attached to xml suites that are supposed to fail with a known bug. I want to include this parameter in a generated report (we use Extent Reporting for that). I've tried numerous ways of retrieving parameters from xml suites but the number of returned parameters is always zero.
I've tried to retrieve data from xml file by using ITestContext.
flush() method is called in one of the listeners upon completion of a test and accepts ITestContext parameter. I'm trying to retrieve parameters from provided ITestContext argument.
public void flush( ITestContext testContext ) {
Map<String, String> parameters = ( ( (ITestContext) testContext ).getCurrentXmlTest() )
.getAllParameters();
for ( Map.Entry<String, String> entry : parameters.entrySet() ) {
warn( "testrail_case_id: " + entry.getKey() + " (id): " + entry.getValue() );
}
extent.flush();
}
This is example of xml suite where we specify a parameter (sometimes a few) with a reference to a bug ticket. To be more specific - I'm trying to retrieve a variable with a parameter name testrail_case_id
<suite name="MySuite" parallel="false" thread-count="1"
junit="false" verbose="1">
<listeners>
<listener class-name="MyListener"/>
</listeners>
<test name="MyTest">
<parameter name="testrail_case_id" value="684342"/>
<classes>
<class name="MyTestClass"/>
</classes>
</test>
</suite>
The problem is that Map<String, String> parameters = ( ( testContext ).getCurrentXmlTest() ).getAllParameters();
always returns zero parameters (not null).
How can I retrieve a parameter with testrail_case_id
from xml suite?