excel文件的groovy脚本在SoapUI中进行数据驱动测试
SoapUI Pro具有从外部文件读取数据的功能,例如:excel,csv等。但SoapUI不提供从excel文件读取数据的功能。因此,为了从SoapUI中的excel文件中读取数据,我们需要在groovy脚本中编写一些代码。
我这篇文章我将告诉你,如何从excel文件中读取数据。我正在使用poi jar文件从groovy中的excel文件中读取数据,下载以下jar文件并放入SoapUI lib文件夹。
- POI-3.8-beta5-20111217.jar
- POI-例子-3.8-beta5-20111217.jar
- POI-excelant-3.8-beta5-20111217.jar
- POI-OOXML-3.8-beta5-20111217.jar
- POI-OOXML-架构 - 3.8 beta5-20111217.jar
- POI暂存器-3.8-beta5-20111217.jar
- dom4j的-1.6.1.jar
在这篇文章中,我为“ConversionRate”API创建了一个SoapUI项目,并创建了一个名为“ConversionRate”的测试用例和测试步骤。所以这里我需要为数据集运行此测试,其中数据在外部excel文件中。

我创建了一个“ReadXLSFile”groovy步骤,并在下面编写代码,从“Book1.xlsx”文件中读取“ConversionRate”API方法的数据。以下是excel文件数据:
I have created a “ReadXLSFile” groovy step and write below code to read data from “Book1.xlsx” file for the “ConversionRate” API method. Below is excel file data:
|
To
|
From
|
|
USD
|
ALL
|
|
AFA
|
DZD
|
|
AWG
|
BSD
|
|
BSD
|
BDT
|
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.xssf.usermodel.*;
import org.apache.poi.ss.util.*;
import org.apache.poi.ss.usermodel.*;
import java.io.*; class ExcelReader { def readData() {
def path = "E:\\Automation-WorkArea\\APITest\\Book1.xlsx";
InputStream inputStream = new FileInputStream(path);
Workbook workbook = WorkbookFactory.create(inputStream);
Sheet sheet = workbook.getSheetAt(0); Iterator rowIterator = sheet.rowIterator();
rowIterator.next()
Row row;
def rowsData = []
while(rowIterator.hasNext()) {
row = rowIterator.next()
def rowIndex = row.getRowNum()
def colIndex;
def rowData = []
for (Cell cell : row) {
colIndex = cell.getColumnIndex()
rowData[colIndex] = cell.getRichStringCellValue().getString();
}
rowsData << rowData
}
rowsData
}
} def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def myTestCase = context.testCase ExcelReader excelReader = new ExcelReader();
List rows = excelReader.readData();
def d = []
Iterator i = rows.iterator();
while( i.hasNext()){
d = i.next();
myTestCase.setPropertyValue("From", d[0])
myTestCase.setPropertyValue("To", d[1])
testRunner.runTestStepByName( "ConversionRate")
}
描述:
- 包含函数“readData”的ExcelReader类,用于从“Book1.xlsx”文件中读取数据。
- myTestCase.setPropertyValue(“From”,d [0])和myTestCase.setPropertyValue(“To”,d [1])用于设置测试用例“from”和“To”属性值。
- testRunner.runTestStepByName(“ConversionRate”)此步骤用于运行测试步骤“ConversionRate”
excel文件的groovy脚本在SoapUI中进行数据驱动测试的更多相关文章
- Coded UI Test中的数据驱动测试
有关什么是Coded UI Test以及如何使用Coded UI Test可以查看我的另一篇文章:http://www.cnblogs.com/jaxu/p/3706652.html 本文主要介绍如何 ...
- C#中实现excel文件批量导入access数据表中
一 .界面简单设计如下: 二 .代码如下: using System; using System.Collections.Generic; using System.ComponentModel; u ...
- pandas 将多个dataframe保存为一个excel文件的多个sheet表中
# 创建文件 def create(): df1 = pd.DataFrame({"a1": [1, 2, 3], "b1": [4, 5, 6]}) df2 ...
- 前端必读:如何在 JavaScript 中使用SpreadJS导入和导出 Excel 文件
JavaScript在前端领域占据着绝对的统治地位,目前更是从浏览器到服务端,移动端,嵌入式,几乎所有的所有的应用领域都可以使用它.技术圈有一句很经典的话"凡是能用JavaScript实现的 ...
- 读取Excel文件中的单元格的内容和颜色
怎样读取Excel文件中的单元格的内容和颜色 先创建一个Excel文件,在A1和A2中随意输入内容,设置A1的字体颜色为红色,A2的背景为黄色.需要 using Excel = Microsoft.O ...
- C#项目中操作Excel文件——使用NPOI库
转载自:http://blog.csdn.net/dcrmg/article/details/52356236# 感谢-牧野- 实际C#项目中经常会涉及到需要对本地Excel文件进行操作,特别是一些包 ...
- 如何在C#中打开和读取EXCEL文件
这篇文章向您展示如何在C#Windows Forms Application中使用ExcelDataReader,ExcelDataReader.DataSet打开和读取Excel文件.创建一个新的W ...
- 如何使用JavaScript导入和导出Excel文件
本文由葡萄城技术团队于原创并首发 转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具.解决方案和服务,赋能开发者. JavaScript是一个涵盖多种框架.直译式.可以轻松自定义客户端的脚本 ...
- python 模块openpyxl读excel文件
使用openpyxl模块来读取excel.要注意openpyxl读不再支持旧的xls格式. 先看一下操作前的excel是什么样子吧.对了,现在只支持xlsx格式的excel读取 我现在想在第三行插入3 ...
随机推荐
- 使用RandomAccessFile读写数据
------------siwuxie095 工程名:TestRandomAccessFile 包名:com.siwuxie095.file 类名:MultiWriteFile.java(主类).Wr ...
- 【摘自大型网站技术架构书】负载均衡时session如何共享
由于负载均衡服务器可能会将请求分发到集群任何一台服务器上,所以保证每次请求能够获得正确的session比单机时复杂. 集群环境下,session管理的主要几种手段 1.session复制 sessio ...
- MAC通过SSH使用PEM文件登录
1.命令如下 ssh -i key.pem ssh -i key.pem root@IP 如果出现报错说明这个问题是文件的权限太大了,需要给小点 sudo chmod 600 key.pem 然后再执 ...
- 数字图像处理实验(12):PROJECT 05-03,Periodic Noise Reduction Using a Notch Filter 标签: 图像处理MATLAB 2017-0
实验要求: Objective: To understand the principle of the notch filter and its periodic noise reducing abi ...
- hdu 4681 String(转载)
#include <stdio.h> #include <string.h> #include <algorithm> #include <iostream& ...
- 4.python 系统批量运维管理器之paramiko模块
paramiko paramiko是ssh服务最经常使用的模块,遵循SSH2协议,支持以加密和认证的方式,进行远程服务器的连接. paramiko实现ssh2不外乎两个角度:SSH客户端与服务端 SS ...
- servlet模板
package ${enclosing_package};import java.io.IOException;import javax.servlet.ServletException;import ...
- 人脸识别 人工智能(AI)
.. 如何通过AI实现 用我自己的数据集:能识别几张人脸.能否判断相似度.能否认出.
- 关于IIS配置SimpleHandlerFactory-Integrated在其模块列表中有一个错误模块ManagedPipelineHandler的错误处理
解决方法: 使用管理员运行aspnet_regiis.exe 命令:%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -i v ...
- c# 实现点击下载功能
转自百度知道 private void DownLoad(string strName, string strPath) { string fileName = strName;//客户端保存的文件名 ...