【问题标题】:DataGen in soapui or soapui pro?在soapui 或soapui pro 中的DataGen?
【发布时间】:2012-09-20 10:11:25
【问题描述】:

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

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

谁能告诉我 DataGen TestStep 在 SoapUI-4.5.1 或 SoapUI Pro 中是否可用。

【问题讨论】:

    标签: rest testing soapui data-generation


    【解决方案1】:

    我 99% 确定数据源等仅在 SoapUI pro 中提供。不过,您可以在 groovy 脚本中完成同样的事情,但您最好从文本文件中读取,而不是从电子表格中读取。

    【讨论】:

    • SOAPUI 不支持数据生成或数据源方法。您可以使用 SOAPUI Pro 版本
    【解决方案2】:

    该步骤仅在 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 UI 免费版 4.5 中实现相同的 DataGen 功能

    【讨论】:

      【解决方案3】:

      所以,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" )
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-25
        • 1970-01-01
        • 1970-01-01
        • 2021-01-05
        • 1970-01-01
        相关资源
        最近更新 更多