我必须将4个值从excel表传递到数据提供者并从那里传递给method.I能够从excel表中获取数据但不能向方法提供数据,
数据: -
Column 1 Column 2 column 3 column 4
1.E-coupons - Loyalty card,ID type,Others,No. of e-coupons issued
2.E-coupons - Loyalty card,Member profile,Registration status,No. of e-coupons redeemed
3.E-coupons - Loyalty card,Member profile,Gender,No. of e-coupons expired
4.E-coupons - Loyalty card,Member profile,Marital status,No. of e-coupons issued
请提前帮助我。提前付款
@Test(dependsOnMethods = {"compa"}, dataProvider = "Testdata")
public void AnalysisEcoupon(String analtype, String dim1, String dim2, String fact) throws Exception {
System.out.println("analysis ");
WebElement moveonmenu = driver.findElement(By.xpath("/html/body/div[5]/div[5]/div[2]/div/div[4]/div/div/select"));
action.moveToElement(moveonmenu);
action.perform();
Select dropdown = new Select(driver.findElement(By.id("cube_id")));//year selection
dropdown.selectByVisibleText(analtype);
Thread.sleep(4000);
driver.findElement(By.id("axis_id")).sendKeys(dim1);
Thread.sleep(4000);
driver.findElement(By.id("dimension_id")).sendKeys(dim2);
// driver.findElement(By.id("fact1_id")).sendKeys("No. of e-coupons issued");
driver.findElement(By.id("fact1_id")).sendKeys(fact);
Thread.sleep(4000);
driver.findElement(By.id("fact2_id")).sendKeys(fact);;
Thread.sleep(4000);
driver.findElement(By.id("one_period_radio")).click();
}
@DataProvider(name = "Testdata")
public Object[][] TestDataFeed() throws Exception {
File src = new File("/home/user/Documents/sheet1.xlsx");
FileInputStream fis = new FileInputStream(src);
wb = new XSSFWorkbook(fis);
// load sheet in my case I am referring to first sheet only
sh1 = wb.getSheetAt(0);
// get number of rows so that we can run loop based on this
numrow = sh1.getLastRowNum();
System.out.println("row count:" + numrow);
// Create 2 D array and pass row and columns
Object[][] analdata = new Object[numrow][4];
// This will run a loop and each iteration it will fetch new row
for (int i = 0; i < numrow; i++) {
analdata[i][0] = sh1.getRow(i).getCell(i).getStringCellValue();
analdata[i][1] = sh1.getRow(i).getCell(i + 1).getStringCellValue();
analdata[i][2] = sh1.getRow(i).getCell(i + 2).getStringCellValue();
analdata[i][3] = sh1.getRow(i).getCell(i + 3).getStringCellValue();
System.out.println("strings are :" + analdata[i][0] + "," + analdata[i][1] + "," + analdata[i][2] + "," + analdata[i][3]);
}
// Return 2d array object so that test script can use the same
System.out.println("return proceed");
return analdata;
}