[英]When using TestNG DataProvider is there a way to read and write parameters from the SAME Excel sheet?
I'm still relatively new to both Java and TestNG, so forgive me if I use incorrect technical terms. 我对Java和TestNG还是比较陌生,所以如果我使用了错误的技术术语,请原谅我。 I'll keep an eye out for responses throughout the day in case I need to correct myself or clarify.
如果我需要纠正自己或澄清自己的话,我会全天关注答复。
In the automated test that I am writing, I am passing my parameters through an Excel sheet via Data Provider. 在我正在编写的自动化测试中,我正在通过数据提供程序通过Excel工作表传递参数。 That whole part is fine.
整个部分都很好。 However, I would now like to perform a getText() on an element and copy that String BACK to the excel sheet that Data Provider was reading from.
但是,我现在想对元素执行getText()并将该String Back复制到Data Provider正在读取的excel工作表中。
Here is an example of my intentions: 这是我意图的一个例子:
//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();
An Issue that I potentially see is that the cell that the value would be saved in would be dynamic. 我可能看到的一个问题是,将值保存在其中的单元格是动态的。
Here is what the excel sheet would look like before the test is run 这是运行测试之前excel工作表的外观
Here is what the same sheet would like AFTER the test is run. 这是运行测试后同一张纸想要的。 Any help or insight would be greatly appreciated!
任何帮助或见识将不胜感激! Thanks
谢谢
getData
method but I suspect that you are using Apache POI (either directly or indirectly) to read data from the Excel Worksheet. getData
方法尚不清楚,但我怀疑您正在使用Apache POI(直接或间接)从Excel工作表中读取数据。 There are plenty of examples on StackOverflow and elsewhere for reading and writing rows of data using Apache POI. Row
object and then know which column (cellnum) to write your output to. Row
对象的引用,然后知道将输出写入哪一列(单元格)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.