我想在SoapUI中测试Restful web服务。为此,我需要从Excel中读取值并将其传递给request。
我在网上搜索,我发现通过DataGen TestStep是可能的。我有SoapUI,但我找不到那个选项。
谁能告诉我DataGen TestStep在SoapUI-4.5.1或SoapUI专业版中是否可用?
发布于 2012-09-20 22:24:15
我有99%的把握,数据源和类似的只有SoapUI pro。不过,在groovy脚本中也可以完成相同的任务,但是从文本文件中读取可能比从电子表格中读取更好。
发布于 2017-10-02 20:52:33
该步骤仅在Soap UI Pro (Ready API)中可用
在免费版本中,即Soap UI中,您可以使用POI方式通过groovy脚本读取excel文件,并在输入请求中传递这些值。
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中读取的代码。读取这些值后,可以//将这些值存储在属性中
testRunner.testCase.setPropertyValue(tcprop,"cellValue")然后在你的请求中,你可以像下面这样展开它
${#TestCase#tcprop}这样,您就可以在Soap free version4.5中实现相同的DataGen功能
发布于 2014-12-18 04:30:20
因此,在SoapUI安装脚本中有一个选项可以提前运行,您可以将您的Excel转换为csv或文本文件,并从那里处理日期。
我用REST服务做了一些测试,仅用于读取文本文件特性。代码如下:
//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" )
}https://stackoverflow.com/questions/12510426
复制相似问题