java当使用TestNG DataProvider时,有没有办法从同一个Excel工作表中读取和写入参数?
我对Java和TestNG还比较陌生,所以请原谅我使用了不正确的技术术语。我会全天留意回应,以防我需要纠正自己或澄清
在我正在编写的自动测试中,我通过数据提供程序通过Excel表传递参数。那部分很好。但是,我现在希望对元素执行getText(),并将该字符串复制回数据提供程序读取的excel工作表
以下是我的意图的一个例子:
//Grabs Parameters to be used from Excel Sheet
@DataProvider
public Object[][] getData(){
suiteXls = new Xls_Reader(System.getProperty("user.dir")+"//src//testData.xlsx")
List<String> sheetNames = new ArrayList<String>();
sheetNames.add("TestStrings");
return TestUtilFinal.getData(suiteXls,sheetNames);
}
//Test Begins
@Test(dataProvider="getData")
public void Test1(String Value_1, String Operator, String Value_2, String Output){
// do some work here
Output.saveToCell();
我可能看到的一个问题是,保存值的单元格是动态的
Here is what the excel sheet would look like before the test is run
Here is what the same sheet would like AFTER the test is run. 任何帮助或见解都将不胜感激!谢谢
# 1 楼答案
getData
方法不清楚,但我怀疑您正在使用ApachePOI(直接或间接)从Excel工作表读取数据。在StackOverflow和其他地方有很多使用ApachePOI读写数据行的例子。您只需要维护对测试用例的Row
对象的引用,然后知道将输出写入哪个列(cellnum)李>