作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经创建了一个用于参数化的示例脚本,我正在寻找类似我的脚本的东西,它应该从 Excel 工作表中读取数据,然后更新同一 Excel 工作表的下一列中每个测试用例的结果。我已经生成了一个脚本,但不幸的是它不起作用。 Excel 工作表正在上述路径生成,但当尝试打开它时,它显示为锁定状态,如果我们检查此 Excel 工作表的整体属性,则它显示的大小为 0 字节。我是 Selenium 的新手,所以我对我遗漏了什么或做错了什么感到困惑。
这是我附加的一些示例代码:
package Pn1;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import org.apache.poi.hslf.model.Sheet;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class parameterization {
public static void main(String[] args) throws BiffException, IOException, Exception {
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);
//Workbook location
Workbook wBook = Workbook.getWorkbook(new File("C:\\Users\\Documents\\TestData\\SampleData.xls"));
File fExcel = new File ("C:\\Users\\Documents\\TestSmokeTestResult2.xls");
//get sheet
jxl.Sheet Sheet = wBook.getSheet(0);
//loop
for(int i=1; i<Sheet.getRows(); i++)
{
driver.get("Enter Test Env");
driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);
driver.findElement(By.xpath("//input[@id='UserName']")).sendKeys(Sheet.getCell(0, i).getContents());
WritableWorkbook writableBook = Workbook.createWorkbook(fExcel);
writableBook.createSheet("Data", 1);
WritableSheet writableSheet =writableBook.getSheet(0);
Label data1 = new Label(0, 0, "Login as user");
writableSheet.addCell(data1);
Label data2 = new Label(1, 0, "Pass");
writableSheet.addCell(data2);
driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);
driver.findElement(By.xpath("//input[@id='Password']")).sendKeys(Sheet.getCell(1, i).getContents());
driver.findElement(By.xpath("//input[@id='Password']")).sendKeys(Sheet.getCell(1, i).getContents());
//Need to use twice time otherwise it will not take password.
Thread.sleep(40);
driver.findElement(By.xpath("//input[@name='Login']")).click();
new WebDriverWait(driver,30).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@id='topnav']/a/span")));
driver.findElement(By.xpath("//div[@id='topnav']/a/span")).click();
driver.findElement(By.xpath("//a[contains(text(),'Logout')]")).click();
}
driver.close();
// TODO Auto-generated method stub
}
}
最佳答案
在关闭驱动程序之前添加两条语句
writableBook.write();
writableBook.close();
关于java - 如何在同一个 Excel 工作表中读取和写入测试用例的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26335339/
我最近购买了《C 编程语言》并尝试了 Ex 1-8这是代码 #include #include #include /* * */ int main() { int nl,nt,nb;
早上好!我有一个变量“var”,可能为 0。我检查该变量是否为空,如果不是,我将该变量保存在 php session 中,然后调用另一个页面。在这个新页面中,我检查我创建的 session 是否为空,
我正在努力完成 Learn Python the Hard Way ex.25,但我无法理解某些事情。这是脚本: def break_words(stuff): """this functio
我是一名优秀的程序员,十分优秀!