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
GroovyScript Code:


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”
所以这样当我运行测试“ReadXLSFile”从xls文件中读取数据时,将为每个输出数据执行测试“ConversionRate”

excel文件的groovy脚本在SoapUI中进行数据驱动测试的更多相关文章

  1. Coded UI Test中的数据驱动测试

    有关什么是Coded UI Test以及如何使用Coded UI Test可以查看我的另一篇文章:http://www.cnblogs.com/jaxu/p/3706652.html 本文主要介绍如何 ...

  2. C#中实现excel文件批量导入access数据表中

    一 .界面简单设计如下: 二 .代码如下: using System; using System.Collections.Generic; using System.ComponentModel; u ...

  3. pandas 将多个dataframe保存为一个excel文件的多个sheet表中

    # 创建文件 def create(): df1 = pd.DataFrame({"a1": [1, 2, 3], "b1": [4, 5, 6]}) df2 ...

  4. 前端必读:如何在 JavaScript 中使用SpreadJS导入和导出 Excel 文件

    JavaScript在前端领域占据着绝对的统治地位,目前更是从浏览器到服务端,移动端,嵌入式,几乎所有的所有的应用领域都可以使用它.技术圈有一句很经典的话"凡是能用JavaScript实现的 ...

  5. 读取Excel文件中的单元格的内容和颜色

    怎样读取Excel文件中的单元格的内容和颜色 先创建一个Excel文件,在A1和A2中随意输入内容,设置A1的字体颜色为红色,A2的背景为黄色.需要 using Excel = Microsoft.O ...

  6. C#项目中操作Excel文件——使用NPOI库

    转载自:http://blog.csdn.net/dcrmg/article/details/52356236# 感谢-牧野- 实际C#项目中经常会涉及到需要对本地Excel文件进行操作,特别是一些包 ...

  7. 如何在C#中打开和读取EXCEL文件

    这篇文章向您展示如何在C#Windows Forms Application中使用ExcelDataReader,ExcelDataReader.DataSet打开和读取Excel文件.创建一个新的W ...

  8. 如何使用JavaScript导入和导出Excel文件

    本文由葡萄城技术团队于原创并首发 转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具.解决方案和服务,赋能开发者. JavaScript是一个涵盖多种框架.直译式.可以轻松自定义客户端的脚本 ...

  9. python 模块openpyxl读excel文件

    使用openpyxl模块来读取excel.要注意openpyxl读不再支持旧的xls格式. 先看一下操作前的excel是什么样子吧.对了,现在只支持xlsx格式的excel读取 我现在想在第三行插入3 ...

随机推荐

  1. Bypassing iPhone Code Signatures

    [Bypassing iPhone Code Signatures] Starting with the recent beta releases of the iPhoneOS, Apple has ...

  2. Reporting Service中配置oracle 数据连接

    一.安装配置报表服务器 数据源 1.安装oracle客户端32位“Oracle - OraClient11g_home1_32bit” 2.配置监听及tnsnames.ora 3.配置ODBC 添加一 ...

  3. 【总结整理】Edraw Max亿图图示软件快捷键(转)

    Edraw Max亿图图示软件快捷键大全,你想要的都在这了!   用过Edraw Max亿图图示软件的一定知道,亿图是一款功能十分强大的图形图表设计软件.无论是流程图.思维导图.组织结构图.甘特图.网 ...

  4. Angular24 树形菜单 ???

    待更新... 2018年5月21日15:17:47 参考博文01 参考博文02

  5. SpringBoot16 MockMvc的使用、JsonPath的使用、请求参数问题、JsonView、分页查询参数、JsonProperty

    1 MockMvc的使用 利用MockMvc可以快速实现MVC测试 坑01:利用MockMvc进行测试时应用上下文路径是不包含在请求路径中的 1.1 创建一个SpringBoot项目 项目脚手架 1. ...

  6. opennebula image单个实例响应数据格式

    { ", ", ", "TEMPLATE": { "DEV_PREFIX": "hd", " }, ...

  7. Solidity payable 方法表现

    pragma solidity ^; contract Person { string public name; uint age; uint private weight; string inter ...

  8. fiddler抓包时显示Tunnel to......443

    打开手机浏览器,输入http://192.168.0.65:8888/FiddlerRoot.cer

  9. Mr_matcher的细节3

    主要是订阅了playbag发布的scan话题和odom话题 其类型分别为 //cache the static tf from base to laser getBaseToLaserTf(scan_ ...

  10. 十四课 slam&gmapping

    gmapping 根据激光数据(或者深度数据模拟的激光数据)建立地图,在turtlebot里面应用的就是深度数据模拟的激光数据.如果没有激光雷达的话可以使用Kinect. SLAM 机器人在未知环境中 ...