Valentina
Valentina

Reputation: 13

Run tests (TestNG) on multiple data inputs

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:

  1. My tests are on TestHotelSearchResults class that extends another class - InitialSetup where I keep my @BeforeClass method
  2. In @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

Answers (1)

niharika_neo
niharika_neo

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

Related Questions