使用黄瓜方案大纲处理Excel电子表格 [英] Handling excel spreadsheets with Cucumber Scenario Outline

查看:116
本文介绍了使用黄瓜方案大纲处理Excel电子表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果可能的话,我试图找到一种更优雅的方法来处理与excel电子表格行(nth)相关的黄瓜方案大纲中的调用nTh数字。

I am trying to see, if possible, to have a more elegant way to handle calling nTh numbers from a Cucumber Scenario Outline that correlates to an excel spreadsheet row(nth).

当前,我正在使用迭代编号来定义要从中提取数据的excel电子表格的行号。我想看看是否有可能以比下面的示例更简洁的方式将黄瓜与excel结合使用。

Currently I am using iteration numbers to define the row # of the excel spread sheet to pull the data from. I wanted to see if it was possible to use cucumber with excel in a more elegant way than the below example with the scenario outline.

某些背景:


  • 每次迭代都必须是自己的场景。因此,为什么我不对row.count使用简单的
    for循环。

  • 我完全意识到方案大纲是做数据表的一种方式,但我的公司希望看到我们可以通过excel集成大型数据集的POF。

  • 当前设置适用于小型数据集,但是当我们进入大型excel电子表格时,我不想在上面键入第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自动化框架小黄瓜工厂。它支持功能文件外部提供的测试数据,例如excel,xml,json,csv或数据库。您可以为以下示例提供数据文件:

You can use QMetry Automation Framework with gherkin factory. It supports test data provided outside feature file for example excel, xml, json, csv, or database. you can provide datafile for examples like:


示例:{'datafile':'resources / testdata.xls'}

Examples:{'datafile':'resources/testdata.xls'}

这是示例即可查看。

这篇关于使用黄瓜方案大纲处理Excel电子表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆