可能であれば、エクセルのスプレッドシートの行(n番目)に対応するキュウリのシナリオのアウトラインからnTh番号を呼び出す処理をより洗練された方法で行うことを検討しようとしています。キュウリとスプレッドシートを処理するシナリオの概要
現在、私はデータを引き出すためにExcelのスプレッドシートの行番号を定義するために繰り返し番号を使用しています。私はシナリオのアウトラインで以下の例よりも優雅な方法で優れたキュウリを使用することが可能かどうかを見たいと思っていました。
いくつかの背景:
- 各反復は、独自のシナリオにする必要があります。だからなぜ私は 単純なforループとrow.countを使用していないのですか?
- 私はデータテーブルを作成する方法としてシナリオの概要を完全に認識していますが、大企業のデータセットを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 |
STEPファイル:
//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();
}
これはアンチパターンです。あなたがそれを読むことができないなら、それは役に立たない。 –
私は理解しています、より多くの概念の実証と実際のアプリケーション –