2017-09-25 79 views
0

我已经编写了一个groovy脚本来读取excel工作表中的数据,工作正常。 现在我在Excel中有两行。我想row1去request1和row2去request2。如何从excel中获取数据到soapui请求

下面是我的Groovy脚本

import org.apache.poi.xssf.usermodel.* 
import org.apache.poi.xssf.usermodel.XSSFWorkbook 
def fs = new FileInputStream(“C:\\Users\\singh532\\Desktop\\try1.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) 
     def d = cell.getStringCellValue() 
     log.info d 
    } 
} 
+0

我使用的soapUI 5.3 – nilay

+0

请出示你的测试用例的结构?如多少个步骤(按照它们的类型排序)?你在尝试数据驱动的测试吗? – Rao

+0

我有一个三个测试步骤的测试用例...第1步。上面提到的groovy脚本.... step2和step3是两个肥皂请求.....是的我正在尝试数据驱动的测试。 – nilay

回答

1

这只是提供一些想法如何能我使用的负载测试运行测试来完成

步骤多次(多行数据)

下面

是测试套件的结构

测试步骤

  • 属性(COL1,COL2,COL3,COL ...)对应于我的CSV列数文件
  • 与从CSV行的值加载从CSV文件和替代COL*属性值数据的Groovy脚本对应于当前运行迭代。

public static class Const{ 
    public static ArrayList data=new ArrayList(); 
    static{ 
     //load data file statically 
     new File('./my-data.csv').splitEachLine(","){ 
      data.add(it); 
     } 
    } 
} 

//get current run number and calculate row of data from it 
int row=context.getProperty('TotalRunCount'); 
if(row==null)row=0; 
row=row%Const.data.size(); 
//substitute properties with ones from file 
for(int i=0; i<Const.data[row].size(); i++){ 
    context.setProperty('COL'+(i+1), Const.data[row][i]); 
} 

  • 使用表达与属性服务调用步骤:

<a> 
    <b>${=context.getProperty('COL1')}</b> 
    <c>${=context.getProperty('COL2')}</c> 
    ... 
</a> 

注意:数据文件中的行数应该对应于负载测试中总运行的限制。如果total runs将大于文件中的行数,则会重复测试。

enter image description here

+0

这很整齐。我也想知道如何使用SoapUI将数据喷入负载。谢谢,我现在有一些东西可以玩。 –