求知 文章 文库 Lib 视频 iPerson 课程 认证 咨询 工具 讲座 Model Center   模型库  
会员   
 


MBSE从理论方法到工作实践
8月26-27日 北京+线上



大模型核心技术RAG、MCP与智能体实践
8月14-15日 厦门



图数据库与知识图谱
8月28-29日 北京+线上
 
 
  Selenium鏁欑▼
Selenium姒傝堪
Selenium IDE
Selenium IDE涓嬭浇
Selenium IDE 宸ュ叿鐗圭偣
Selenium IDE娴嬭瘯鍒涘缓
Selenium IDE娴嬭瘯
Selenium IDE楠岃瘉鐐
Selenium - IDE妯″紡鍖归厤
Selenium鐢ㄦ埛鎵╁睍
Selenium IDE- 涓嶅悓鐨勬祻瑙堝櫒
Selenium 鐜瀹夎璁剧疆
Selenium RC
Selenium - Selenese鍛戒护
Selenium Webdriver
Selenium瀹氫綅鍣
鏂囨湰妗嗙殑鐩镐簰浣滅敤
鍗曢夋寜閽簰鍔
澶嶉夋浜や簰
涓嬫媺妗嗕氦浜
Synchronization 鍚屾
鎷栨斁
閿洏鎿嶄綔
榧犳爣鎿嶄綔
澶氶夋嫨鎿嶄綔
鏌ユ壘鎵鏈夐摼鎺
Selenium娴嬭瘯璁捐鎶鏈
Selenium椤甸潰瀵硅薄妯″瀷
浣跨敤Excel鏁版嵁椹卞姩
log4j鏃ュ織
寮傚父澶勭悊
澶氭祻瑙堝櫒娴嬭瘯
鎹曟崏灞忓箷鎴浘
鎹曟崏瑙嗛
Selenium TestNG
Selenium缃戞牸
 
 

使用Excel数据驱动
1372 次浏览
4次  

使用Excel数据驱动

在设计测试,参数化测试是不可避免的。我们会利用Apache的POI- Excel JAR实现是一样的。它可以帮助我们来读取和写入到Excel中。

下载JAR

第1步:导航到URL- http://poi.apache.org/download.htmll并下载ZIP格式。

第2步:点击镜像链接下载JAR。

第3步:解压缩到一个文件夹。

第4步:如下所示的解压缩后的内容将被显示。

第5步:现在创建一个新的项目,并在“External JARs”添加“POI-3.10.FINAL”文件夹中所有的jar包。

第6步:现在,添加所有的“External JARs”在“OOXML-LIB”文件夹中。

第7步:现在,添加所有的“External JARs”在“lib”文件夹中。

第8步:如下图所示,显示已添加的JAR文件。

第9步:如下图所示的Package Explorer显示。此外附加“webdriver”相关的JAR

参数

为了演示目的,我们将参数的百分比计算器测试。

第1步:我们将所有的参数需要使用Excel的%计算器的输入。所设计的excel如下所示。

第2步:现在,我们将执行所有百分比计算器,所有指定的参数。

第3步:让我们创建通用的方法来访问使用导入JARS Excel文件。这些方法可以帮助我们获得一个特定的单元格数据或设置一个特定的单元格的数据等。

import java.io.*;
import org.apache.poi.xssf.usermodel.*;

public class excelutils
{
private XSSFSheet ExcelWSheet;
private XSSFWorkbook ExcelWBook;

//Constructor to connect to the Excel with sheetname and Path
public excelutils(String Path, String SheetName) throws Exception
{
try
{
// Open the Excel file
FileInputStream ExcelFile = new FileInputStream(Path);
// Access the required test data sheet
ExcelWBook = new XSSFWorkbook(ExcelFile);
ExcelWSheet = ExcelWBook.getSheet(SheetName);
}
catch (Exception e)
{
throw (e);
}
}

//This method is to set the rowcount of the excel.
public int excel_get_rows() throws Exception
{
try
{
return ExcelWSheet.getPhysicalNumberOfRows();
}
catch (Exception e)
{
throw (e);
}
}

//This method to get the data and get the value as strings.
public String getCellDataasstring
(int RowNum, int ColNum) throws Exception
{
try
{
String CellData = ExcelWSheet.getRow(RowNum).getCell(ColNum)
.getStringCellValue();
System.out.println("The value of CellData " + CellData);
return CellData;
}
catch (Exception e)
{
return "Errors in Getting Cell Data";
}
}


//This method to get the data and get the value as number.
public double getCellDataasnumber
(int RowNum, int ColNum) throws Exception
{
try
{
double CellData = ExcelWSheet.getRow(RowNum).getCell(ColNum)
.getNumericCellValue();
System.out.println("The value of CellData " + CellData);
return CellData;
}
catch (Exception e)
{
return 000.00;
}
}
}

第4步:现在,添加它将访问,我们已经开发了Excel的方法,主要的方法。

import java.io.*;
import org.apache.poi.xssf.usermodel.*;

public class excelutils
{
private XSSFSheet ExcelWSheet;
private XSSFWorkbook ExcelWBook;

//Constructor to connect to the Excel with sheetname and Path
public excelutils(String Path, String SheetName) throws Exception
{
try
{
// Open the Excel file
FileInputStream ExcelFile = new FileInputStream(Path);
// Access the required test data sheet
ExcelWBook = new XSSFWorkbook(ExcelFile);
ExcelWSheet = ExcelWBook.getSheet(SheetName);

}
catch (Exception e)
{
throw (e);
}
}

//This method is to set the rowcount of the excel.
public int excel_get_rows() throws Exception
{
try
{
return ExcelWSheet.getPhysicalNumberOfRows();
}
catch (Exception e)
{
throw (e);

}
}

//This method to get the data and get the value as strings.
public String getCellDataasstring
(int RowNum, int ColNum) throws Exception
{
try
{
String CellData = ExcelWSheet.getRow(RowNum).getCell(ColNum).
getStringCellValue();
//Cell = ExcelWSheet.getRow(RowNum).getCell(ColNum);
//String CellData = Cell.getStringCellValue();
System.out.println("The value of CellData " + CellData);
return CellData;
}
catch (Exception e)
{
return "Errors in Getting Cell Data";
}
}

//This method to get the data and get the value as number.
public double getCellDataasnumber
(int RowNum, int ColNum) throws Exception
{
try
{
double CellData = ExcelWSheet.getRow(RowNum).getCell(ColNum)
.getNumericCellValue();
//Cell = ExcelWSheet.getRow(RowNum).getCell(ColNum);
//String CellData = Cell.getStringCellValue();
System.out.println("The value of CellData " + CellData);
return CellData;
}
catch (Exception e)
{
return 000.00;
}
}
}

输出

在执行脚本,输出显示在控制台中,如下图所示。


您可以捐助,支持我们的公益事业。

1元 10元 50元





认证码: 验证码,看不清楚?请点击刷新验证码 必填



1372 次浏览
4次
 捐助