我需要使用Jxl参数化参数化5个文本字段和一个按钮。我只做了两个文本框,我无法同时参与这5个文本框的参数化。
public class test {
public static void main(String[] args) throws InterruptedException, BiffException, IOException {
// TODO Auto-generated method stub
String FilePath = "F:/ISTP Testing/Module 2/Seleniume/project/Spaco_DataEntryTest_ContactPage.xls";
FileInputStream fs = new FileInputStream(FilePath);
Workbook wb = Workbook.getWorkbook(fs);
// TO get the access to the sheet
Sheet sh = wb.getSheet("Sheet1");
String BaseURL="http://istp.in/changathionlinebeta/contact_us.php";
WebDriver wd=new FirefoxDriver();
wd.get(BaseURL);
// To get the number of rows present in sheet
int totalNoOfRows = sh.getRows();
// To get the number of columns present in sheet
int totalNoOfCols = sh.getColumns();
for (int row = 1; row < totalNoOfRows; row++) {
for (int col = 0; col < totalNoOfCols; col++) {
System.out.print(sh.getCell(col, row).getContents() + "\t");
Thread.sleep(3000);
if(col%2==0)
{
wd.findElement(By.id("name")).sendKeys(sh.getCell(col, row).getContents());
}else{
wd.findElement(By.id("email")).sendKeys(sh.getCell(col, row).getContents());
}
}
System.out.println();
}
wd.close();
System.exit(0);
}
}
答案 0 :(得分:3)
Rudziankoŭ但是。
1&gt;使用所有属性(姓名,电子邮件,地址...)
创建class SubmitPageObject
2&gt;在您的程序中创建方法,从工作簿中获取信息并将其分配给List<SubmitPageObject> spo = new List<SubmitPageObject>();
..
spo.Add(new SubmitPageObject(name,email,...))
3&gt;最后一步是遍历列表并:
wd.findElement(By.id("name")).sendKeys(spo[i].name);
wd.findElement(By.id("email")).sendKeys(spo[i].email);
wd.findElement(By.id("phone")).sendKeys(spo[i].phone);
...
答案 1 :(得分:2)
你听说过single responsibility principle吗?如果将职责划分为不同的方法,您的代码将更易于维护,可读,可扩展。
@model Fileuploaddemo.Models.Student
@{ var grid = new WebGrid(Model.StudentList);}
@Html.LabelFor(model => model.Name)
@Html.EditorFor(model => model.Name)
@Html.LabelFor(model => model.Address)
@Html.EditorFor(model => model.Address)
@grid.GetHtml(
htmlAttributes: new
{
id = "gridT1",
@calss = ""
},
tableStyle: "webgrid-table",
headerStyle: "webgrid-header",
columns: grid.Columns(
grid.Column(columnName: "Name", header: "Name"),
grid.Column(columnName: "Address", header: "Address") ))
答案 2 :(得分:1)
你可以尝试一下 -
for (int row = 0; row < totalNoOfRows; row++) {
for (int col = 0; col < totalNoOfCols; col++) {
System.out.print(sh.getCell(col, row).getContents() + "\t"); //don't understand what you want to achieve using this
Thread.sleep(3000);
switch(col){
Case 0: wd.findElement(By.id("name")).sendKeys(sh.getCell(col, row).getContents());
break;
Case 1: wd.findElement(By.id("email")).sendKeys(sh.getCell(col, row).getContents());
break;
Case 2: wd.findElement(By.id("phone")).sendKeys(sh.getCell(col, row).getContents());
break;
Case 3: wd.findElement(By.id("mob")).sendKeys(sh.getCell(col, row).getContents());
break;
Case 4: wd.findElement(By.id("address")).sendKeys(sh.getCell(col, row).getContents());
break;
}
}
}