Jack Jason F
Jack Jason F

Reputation: 143

Passing dataProvider parameter inside testng method

I have two @DataProviders:

@DataProvider(name = "smallNumbers")
@DataProvider(name = "bigNumbers")

Variables in pom.xml

<systemPropertyVariables>
<dataP>${dataProvider}</dataP>
</systemPropertyVariables>

Accesing parameter:

String sizeNumbers = System.getProperty("dataP");

And my test:

@Test(dataProvider=sizeNumbers) 

dataProvider in test method have to be: a constant expression Any idea how to pass variable inside @Test(dataProvider= ?

Upvotes: 0

Views: 753

Answers (1)

You cant do this. It is only possible to pass dataprovider directly to method. Why you choose that way to inject data from dataprovider? Show a bit more about your code architecture cause that's look strange.

EDIT:

You can check this way:

@DataProvider(name = "dp")
public static Object[][] dataInject(){
  return new Object[][]{
            {sizeNumbers}
  };
} 

And inside "dp" you can also make some validation for ex. "isNull" etc.

Then in test

@Test(dataProvider = "dp", dataProviderClass = Xyz.class)
public void testFirst(String input){
//...
}

Upvotes: 1

Related Questions