[英]Handling excel spreadsheets with Cucumber Scenario Outline
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). 我试图看,如果可能的话,有一种更优雅的方式来处理从与黄金表格大纲行(第n个)相关的黄瓜场景大纲中调用nTh数字。
Currently I am using iteration numbers to define the row # of the excel spread sheet to pull the data from. 目前我正在使用迭代数来定义excel电子表格的行#以从中提取数据。 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.
我想看看是否可以以比下面的示例更优雅的方式使用带有excel的黄瓜和场景轮廓。
Some background: 一些背景:
Cucumber code: 黄瓜代码:
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 |
Step File: 步骤文件:
//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);
}
Actual Code: 实际代码:
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();
}
You can use QMetry Automation Framework with gherkin factory . 您可以将QMetry Automation Framework与小黄瓜工厂一起使用 。 It supports test data provided outside feature file for example excel, xml, json, csv, or database.
它支持在特征文件外部提供的测试数据,例如excel,xml,json,csv或数据库。 you can provide datafile for examples like:
您可以提供数据文件,例如:
Examples:{'datafile':'resources/testdata.xls'}
实施例:{ '数据文件': '资源/ testdata.xls'}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.