@parameter and dataprovider for same tests in TestNG

Is it possible to use @parameter and dataprovider for same test method in TestNG? I tried the below snippet it is throwing exception

Expecting:
@Parameters(“deviceName”)
@Test(dataProvider = “dataprovidername”)
public void testnam(String deviceName,String dataproviderparam1, String dataproviderparam2)
{
if(deviceName){
//do something)
}
else{
//do something
}
}

You can’t apply like that.

Please change to:

public class YourClassName {
private static String deviceName;

@Test(dataProvider = “dataprovidername”)
public void testnam(String dataproviderparam1, String dataproviderparam2){
if(deviceName){
//do something)
}else{
//do something
}
}

@BeforeClass/Test/Suite
@Parameters("deviceName")
public void beforeSuite( String deviceNameFromTestNG) throws ExecuteException, IOException {
    
 this.deviceName = deviceNameFromTestNG;
    
}

}

1 Like