首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >DataGen in soapui还是soapui pro?

DataGen in soapui还是soapui pro?
EN

Stack Overflow用户
提问于 2012-09-20 18:11:26
回答 3查看 2.2K关注 0票数 1

我想在SoapUI中测试Restful web服务。为此,我需要从Excel中读取值并将其传递给request。

我在网上搜索,我发现通过DataGen TestStep是可能的。我有SoapUI,但我找不到那个选项。

谁能告诉我DataGen TestStep在SoapUI-4.5.1或SoapUI专业版中是否可用?

EN

回答 3

Stack Overflow用户

发布于 2012-09-20 22:24:15

我有99%的把握,数据源和类似的只有SoapUI pro。不过,在groovy脚本中也可以完成相同的任务,但是从文本文件中读取可能比从电子表格中读取更好。

票数 1
EN

Stack Overflow用户

发布于 2017-10-02 20:52:33

该步骤仅在Soap UI Pro (Ready API)中可用

在免费版本中,即Soap UI中,您可以使用POI方式通过groovy脚本读取excel文件,并在输入请求中传递这些值。

代码语言:javascript
复制
import org.apache.poi.xssf.usermodel.*
import org.apache.poi.ss.usermodel.DataFormatter;

def fs = new FileInputStream("F:\\Gaurav\\soapui\\readFile.xlsx")
def wb = new XSSFWorkbook(fs)
def ws = wb.getSheet("Sheet1")
def r = ws.getPhysicalNumberOfRows()

for(def i =0 ; i < r ; i++)
{
def row = ws.getRow(i);
def c=row.getPhysicalNumberOfCells()

for(def j=0; j <c ; j++)
{
def cell= row.getCell(j)

// to convert everything to a String format
DataFormatter formatter = new DataFormatter()
def cellValue=formatter.formatCellValue(cell)

log.info cellValue

}
}

//上面是要从excel中读取的代码。读取这些值后,可以//将这些值存储在属性中

代码语言:javascript
复制
testRunner.testCase.setPropertyValue(tcprop,"cellValue")

然后在你的请求中,你可以像下面这样展开它

代码语言:javascript
复制
${#TestCase#tcprop}

这样,您就可以在Soap free version4.5中实现相同的DataGen功能

票数 1
EN

Stack Overflow用户

发布于 2014-12-18 04:30:20

因此,在SoapUI安装脚本中有一个选项可以提前运行,您可以将您的Excel转换为csv或文本文件,并从那里处理日期。

我用REST服务做了一些测试,仅用于读取文本文件特性。代码如下:

代码语言:javascript
复制
//Load the text file
 def inputFile = new File("C://Temp//whatever");

//Create an empty list...
 def mega_List = [];

//...and then populate it with the contents
 // of the text file.
 addSomeThingToList = {mega_List.add(it)};
 inputFile.eachLine(addSomeThingToList);

//...and assign its value to the Test Case Property
 def tc = testRunner.testCase;


//Randomly pick an item from the list...
def index = context.expand( '${#TestCase#index}' ).toInteger()


 if ( index <  mega_List.size() ) { 
def id = mega_List.get(index);
 index++
tc.setPropertyValue("id", id);
tc.setPropertyValue("index", index.toString());

 }
else {
tc.setPropertyValue("index", "0");
tc.setPropertyValue("id", "0");
testrunner.cancel( "time to go home" )
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12510426

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档