无法使用Selenium在具有不同@Dataproviders的单个类中执行2个@Test注释方法

时间:2016-09-07 07:15:04

标签: java selenium selenium-webdriver selenium-ide selenium-chromedriver

我尝试在单个java类中执行两个@Test注释方法,每个@Dataproviders使用不同的@Test。但是只有一个@Test被执行,而不是两个。你能告诉我哪里出错了吗? 编写的代码如下所示。

@DataProvider 

<\!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-html -->

public class QaToolsECommerceDataProvider {

  @DataProvider(name="ProductInfo")
  public static Object[][] productInfoDataprovider() throws Throwable {

      File file = new File("C:/Users/chetan.k.thimmanna/Documents/Selenium/Resources/QAToolsECommerce/ECommerce_Data.xlsx");
      FileInputStream fis = new FileInputStream(file);
      XSSFWorkbook wb = new XSSFWorkbook(fis);

      XSSFSheet sheet = wb.getSheet("Sheet1");
      int lastRowNum = sheet.getLastRowNum();
      System.out.println(lastRowNum);

      Object[][] obj = new Object[lastRowNum][5];
      for(int i=0; i<lastRowNum; i++){

          XSSFRow row = sheet.getRow(i+1);
          obj[i][0]= (int)row.getCell(0).getNumericCellValue();
          obj[i][1]= row.getCell(1).getStringCellValue();
          obj[i][2]= (int)row.getCell(2).getNumericCellValue();
          obj[i][3]= row.getCell(3).getStringCellValue();
          obj[i][4]= row.getCell(4).getStringCellValue();
      }
        fis.close();
        return obj;  
  }      

  @DataProvider(name="shippingDetails")
  public static Object[][] shipmentInfoDataprovider() throws Throwable{

      File file = new File("C:/Users/chetan.k.thimmanna/Documents/Selenium/Resources/QAToolsECommerce/ECommerce_Data.xlsx");
      FileInputStream fis = new FileInputStream(file);  
      XSSFWorkbook wb = new XSSFWorkbook(fis);
      XSSFSheet sheet = wb.getSheet("Sheet2");
      int lastRowNum = sheet.getLastRowNum();
      System.out.println(lastRowNum);

      Object[][] obj = new Object[lastRowNum][8];
      for(int i=0; i<lastRowNum; i++){

          XSSFRow row = sheet.getRow(i+1);
          obj[i][0]= row.getCell(0).getStringCellValue();
          obj[i][1]= row.getCell(1).getStringCellValue();
          obj[i][2]= row.getCell(2).getStringCellValue();
          obj[i][3]= row.getCell(3).getStringCellValue();
          obj[i][4]= row.getCell(4).getStringCellValue();
          obj[i][5]= row.getCell(5).getStringCellValue();
          obj[i][6]= row.getCell(6).getStringCellValue();
          obj[i][7]= row.getCell(7).getStringCellValue();         
      }
      fis.close();
      return obj;
  }      

<\!-- end snippet -->

@Test

<\!-- begin snippet: js hide: false console: true babel: false -->  

  <!-- language: lang-html -->

public class QaToolsECommerceTest {

    @Test(dataProvider = "ProductInfo", dataProviderClass = QaToolsECommerceDataProvider.class)
    public void eCommerceProduct1(int browser, String product, int quantity, String prices, String totalPrices) {
      QaToolsECommercePageObjects qaEpo = new QaToolsECommercePageObjects();

      qaEpo.setBrowser(browser);
      qaEpo.searchProduct(product);
      qaEpo.productVerify(product);
      qaEpo.checkoutCartVerify(product, quantity, prices, totalPrices);
  }     

    @Test(dataProvider = "shippingDetails", dataProviderClass = QaToolsECommerceDataProvider.class)
    public void eCommerceProduct2(String email, String firstname, String lastname, String address, String city, String state, String postalcode, String mobno) {
      QaToolsECommercePageObjects qaEpo = new QaToolsECommercePageObjects();

      qaEpo.clickContinueButton();
      qaEpo.billingDetails(email, firstname, lastname, address, city, state, postalcode, mobno);
      qaEpo.transactionResults();
      qaEpo.takeScreenshot();
  }     
}

0 个答案:

没有答案