Reputation: 13
I am a newbie on automated testing(TestNG) and I have the following dilemma. I want to run some tests on multiple data inputs. My structure is like this:
TestHotelSearchResults
class that extends another class - InitialSetup
where I keep my @BeforeClass
method @BeforeClass
method I instantiate the driver, go to the URL and perform the initial search that I want to perform on different destinations. (now it is made just on New York)From what I know I cannot use DataProvider for a @BeforeClass
, then what is my alternative.
class TestHotelSearchResults extends InitialSetup {
@Test
...
}
class InitialSetup extends Base {
@BeforeClass
public void Init() {
super.setUp();
HomePage hp = PageFactory.initElements(getDriver(), HomePage.class);
hp.goTo();
hp.searchHotelAfterDestination("New York", CriteriaSearchEnum.DESTINATION);
}
}
Upvotes: 1
Views: 1066
Reputation: 8531
You need to only separate the data in the dataprovider. Keep the setup in the beforeclass and the flow in the test.
for eg.
@BeforeClass
public void setup(){
System.out.println("Init driver here");
}
@DataProvider
public Object[][] sendData(){
return new Object[][]{
{"NewYork"},{"Boston"},{"Chicago"}
};
}
@Test(dataProvider="sendData")
public void test1(String city){
System.out.println("Going to "+city);
}
Upvotes: 2