【发布时间】:2018-06-06 06:34:26
【问题描述】:
我正在使用 Rest Assured 进行 REST API 测试,我正在使用 @BeforeTest 注释调用 jxl 数据并在 @Dataprovider 注释的帮助下将结果写入其中以传递测试数据。
但是在这里我总共有 4 个 api,我想根据来自不同类的 @Test 注释中的方法名称来阅读特定的其余 API 的特定工作表。
示例:
1.cardvalidation - 验证表 2.Purchase - 采购单 3.Cancel - 取消采购表
例如,如果方法名称是 cardvalidation,那么我将只为所有 4 个 API 获取验证表等,并且我正在使用 Before Method 注释,但它只为一行而不是所有测试数据行写入结果。
示例代码:
@BeforeMethod
public void excelWriter(Method method) throws BiffException, IOException, RowsExceededException, WriteException {
File file = new File(inputFile);
FileInputStream testFile = new FileInputStream(file);
Workbook workBook = Workbook.getWorkbook(testFile);
String methodName = method.getName();
if(methodName.equals("validateTesting")) {
sheet = workBook.getSheet("Validate_TestData");
}else if(methodName.equals("purchaseTesting")) {
sheet = workBook.getSheet("Purchase_TestData");
}
int rows = sheet.getRows();
int columns = sheet.getColumns();
String dataFile[][] = new String[rows][columns];
File outputResults = new File(outputFile);
// Write data into file
FileOutputStream fileOutputStream = new FileOutputStream(outputResults);
// Create the workbook
workbookCopy = Workbook.createWorkbook(fileOutputStream);
if(methodName.equals("validateTesting")) {
writablesh = workbookCopy.createSheet("Validate_Results", 0);
}else if(methodName.equals("purchaseTesting")) {
writablesh = workbookCopy.createSheet("Purchase_Results", 1);
}
// Copy all data from source file to Destination File
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
dataFile[i][j] = sheet.getCell(j, i).getContents();
Label l = new Label(j, i, dataFile[i][j]);
Label L2 = new Label(13, 0, "Results");
writablesh.addCell(l);
writablesh.addCell(L2);
}
}
}
【问题讨论】: