[英]Handling excel spreadsheets with Cucumber Scenario Outline
我試圖看,如果可能的話,有一種更優雅的方式來處理從與黃金表格大綱行(第n個)相關的黃瓜場景大綱中調用nTh數字。
目前我正在使用迭代數來定義excel電子表格的行#以從中提取數據。 我想看看是否可以以比下面的示例更優雅的方式使用帶有excel的黃瓜和場景輪廓。
一些背景:
黃瓜代碼:
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與小黃瓜工廠一起使用 。 它支持在特征文件外部提供的測試數據,例如excel,xml,json,csv或數據庫。 您可以提供數據文件,例如:
實施例:{ '數據文件': '資源/ testdata.xls'}
這是您可以檢查的示例 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.