I have some init statements that need to be done with the data provider parameter and would want to access the data provider parameter value in the @BeforeMethod
setup method. Is this possible?
Yes, its totally possible. In the @BeforeMethod
annotated method, you can pass an optional built-in argument of Object[] that is basically a copy of the parameters being passed to the @Test
method. In my case, I pass 2 args to my test method:
@Test(dataProvider="provider")
public void doTest( TestHelper testHelper, Map<String,String> paramMap ) {
....
So, something like this (and it doesn't need to be a factory DataProvider) :
@BeforeMethod
public void setUp( Object[] testArgs ) {
Map<String,String> paramMap = (Map<String, String>)testArgs[1];
TestHelper testHelper = testArgs[0];
String testName = paramMap.get( "testCaseName" );
log.logTcStep( "Test case name: " + testName );
log.setLogTcName( testName );
testHelper.setTestName( testName );
testHelper.setTagsByString( paramMap.get( "browser" ) );
testHelper.setBuildNumber( paramMap.get( "environment" ) );
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With