Selenium脚本执行非常慢,以防Excel(XLSX)表中没有行增加



我已经为我的项目编写了Selenium脚本,当我开始运行大约80个测试用例并且每个测试用例有100个步骤时,它非常慢,但是如果我运行10个测试用例,每个测试用例具有相同的100个步骤,执行速度非常快,任何人都可以帮助我如何解决此类问题,下面是 Excel 阅读类,在驱动程序类中,我们获取字符串值中的值并传递到应用程序中。

我所有的测试用例步骤都在 excel 文件中提到,如下所示

1.Open Browser for this Browser keyword
2.Open URl for this openApp keyword
3.Wait for Username for this waitElement keyword
4.Enter Username for this typeText keyword. etc 

同样遵循测试用例流程的完成,100 个测试用例的 100 张。

package Utilities;
import java.io.File;
import java.io.FileOutputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class ExcelFileUtil {
XSSFWorkbook wb;
// It will load all the excel sheet & it will instantiate that particular
// workbook
public ExcelFileUtil(String file) throws Exception {
FileInputStream fis = new FileInputStream("InputSheet.xlsx");
File files = new File(file);
OPCPackage pkg =OPCPackage.open(files.getAbsolutePath());
wb = new XSSFWorkbook(pkg);
}
public int rowCount(String sheetname) {
return wb.getSheet(sheetname).getLastRowNum();
}
public int colCount(String sheetname, int rowNo) {
return wb.getSheet(sheetname).getRow(rowNo).getLastCellNum();
}
public String getData(String sheetname, int row, int column) {
String data = null;
if (wb.getSheet(sheetname).getRow(row).getCell(column).getCellType() == Cell.CELL_TYPE_STRING) {
data = wb.getSheet(sheetname).getRow(row).getCell(column).getStringCellValue();
}
else {
int celldata = (int) wb.getSheet(sheetname).getRow(row).getCell(column).getNumericCellValue();
data = String.valueOf(celldata);
}
return data;
}
public void setData(String sheetname, int row, int column, String str,String file) throws Exception {
XSSFSheet sh = wb.getSheet(sheetname);
Row rownum = sh.getRow(row);
Cell cell = rownum.createCell(column);
cell.setCellValue(str);
FileOutputStream fos = new FileOutputStream(file);
wb.write(fos);
fos.close();
}
}

您是否正在使用 Testng 数据提供程序?如果不尝试这样做,那么您将不会看到任何问题。 还有一件事,如果你不想使用testng,那么你必须使用集合概念或将所有excel数据存储在一个二维数组中,并逐个访问值。

下面的链接有在哈希图收集框架中存储数据的非常最好的示例。 http://www.inviul.com/store-data-excel-sheet-hashmap/

希望这有帮助。

最新更新