我如何从第二类的@before方法在第一类中调用@Test(数据驱动方法)

时间:2019-05-05 05:39:29

标签: java selenium selenium-webdriver testng testng-dataprovider

我试图从第二类的@beforemethod调用第一类的数据驱动方法。我正在将Excel工作表用于数据驱动方法。

我尝试在方法似乎无效之前使用@dataprovider注释

  //This is the first class
    @DataProvider
 public Object[][] getTestData() {
    Object [][] data=TestUtil.getTestData(sheetname);//since this 
    is stored in a 2d object array
    return data;
}



@Test(dataProvider="getTestData")
public void validateEnterUserDetails(String name,String address,String 
    city,String state,String zipCode,String cardType,
        String creditCardNumber,String creditCardMonth,String 
    creditCardYear,String nameOnCard) {

    reservationpage.enterUserDetails(name, address, city, state, 
    zipCode, cardType,
            creditCardNumber, creditCardMonth, 
    creditCardYear, nameOnCard);

  //This is the second class

    @BeforeMethod
public void setup(String name,String address,String city,String 
   state,String zipCode,String cardType,
        String creditCardNumber,String creditCardMonth,String 
    creditCardYear,String nameOnCard) {

    initialization();
    homepage=new HomePage();
    homepage.selectDepartureCity();
    homepage.selectDestinationCity();
    flightspage=new FlightsPage();
    flightspage=homepage.findflights();
    reservationpage=flightspage.clickCheapFlight();

    confirmationpage=reservationpage.enterUserDetails(name, 
   address, city, state, zipCode, cardType, creditCardNumber, 
   creditCardMonth, creditCardYear, nameOnCard);

只能将其中之一注入@BeforeMethod注释的设置中。 我如何在第二个类中调用enteruserdetails数据驱动方法,请帮忙

0 个答案:

没有答案