使用黄瓜场景大纲处理excel电子表格

我试图看到,如果可能的话,有一个更优雅的方式来处理从一个黄金场景大纲,与Excel电子表格行(第n)有关的呼叫nTh号码。

目前,我正在使用迭代数字来定义Excel电子表格的行号以从中提取数据。 我想看看是否有可能使用excel中的黄瓜更优雅的方式比下面的场景大纲的例子。

一些背景:

  • 每个迭代都需要是自己的场景。 因此,为什么我不使用row.count的简单for循环。
  • 我完全意识到脚本大纲是做数据表的一种方式,但是我的公司希望看到一个可以通过excel集成大数据集的POF。
  • 目前的设置适用于小数据集,但是当我们进入大型Excel电子表格时,我不想在大纲中input第n个数字

黄瓜代码:

Feature: User is using an excel spreadsheet with cucumber driving it Scenario Outline: Data Driven with excel and data sets When I am on the amps mainscreen Then I input username and passwords with excel row"<row_index>" dataset Examples: | row_index | | 1 | | 2 | | 3 | | 4 | 

步骤文件:

 //Excel Steps @When("^I am on the amps mainscreen$") public void i_am_on_the_amps_mainscreen() { System.out.println("Im loading"); } //Excel Steps @Then("^I input username and passwords with excel row\"([^\"]*)\" dataset$") public void i_input_username_and_passwords_with_excel_row_dataset(int rownum) throws IOException { login.readExcel(rownum); } 

实际代码:

  public void readExcel (int row) throws IOException{ File src=new File("src/test/resources/username.xlsx"); FileInputStream fis=new FileInputStream(src); XSSFWorkbook srcBook= new XSSFWorkbook(fis); XSSFSheet sourceSheet = srcBook.getSheetAt(0); XSSFRow sourceRow = sourceSheet.getRow(row); XSSFCell username=sourceRow.getCell(0); XSSFCell password=sourceRow.getCell(1); String userExcel = username.getStringCellValue(); String pwExcel = password.getStringCellValue(); System.out.println("The username is" +userExcel); System.out.println("The password is" +pwExcel); log.info("The username on " +row + " is: "+userExcel); log.info("The password on "+row+ " is: "+pwExcel); driver.findElement(txtbox_username).sendKeys(userExcel); driver.findElement(txtbox_password).sendKeys(pwExcel); driver.findElement(btn_logon).click(); } 

您可以使用QMetry Automation Framework和黄瓜工厂 。 它支持在function文件之外提供的testing数据,例如excel,xml,json,csv或数据库。 你可以提供如下的例子的数据文件:

实施例:{ '数据文件': '资源/ testdata.xls'}

这里是你可以检查的例子 。