【问题标题】:Use excel file variables in SOAP request in SoapUI在 SoapUI 的 SOAP 请求中使用 excel 文件变量
【发布时间】:2020-02-25 17:27:17
【问题描述】:

我遇到了一个问题。我是 SoapUI 的新手。 我必须阅读excel文件,然后在soap请求中放入一些变量。这就是我所做的: 我添加了一个 groovy 脚本来获取 excel 文件数据: 导入 jxl.*

Workbook workbook = Workbook.getWorkbook(new File("C:\\PATH\\TestData.xls"))
Sheet sheet1 = workbook.getSheet("Sheet1")
def rows = sheet1.getRows()
def cols = sheet1.getColumns()
log.info "Row Count =" + rows 
log.info "Column Count =" + cols 
def array = []
for(i=1;i<rows;i++) { 
    for(j=0;j<cols;j++) { 
       Cell cell = sheet1.getCell(j,i)
       def variable = cell.getContents()
       log.info cell.getContents() 
       array << variable
    } 
}
return array

数组返回:10 和 20。 这是一个肥皂请求:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
   <soapenv:Header/>
   <soapenv:Body>
      <tem:Add>
         <tem:intA>10</tem:intA>
         <tem:intB>10</tem:intB>
      </tem:Add>
   </soapenv:Body>
</soapenv:Envelope>

我可以以某种方式调用一个 groovy 脚本并将变量放入

             <tem:intA>10</tem:intA>
             <tem:intB>20</tem:intB>

我应该调用一个 groovy 脚本方法来代替 10 和 20,并放入我从 excel 文件中获取的数据。

【问题讨论】:

  • 是否总是有两个变量:intA 和 intB?还是需要更加动态?
  • 是的,在这种情况下它总是 intA 和 intB。

标签: soap groovy automated-tests soapui


【解决方案1】:

由于您的用例很简单:只需替换两个变量,您可以只使用两个属性。

将脚本中的return array 更改为:

testCase.setPropertyValue("intA", array[0].toString())
testCase.setPropertyValue("intB", array[1].toString())

然后您的请求:

     <tem:intA>${#TestCase#intA}</tem:intA>
     <tem:intB>${#TestCase#intB}</tem:intB>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-20
    • 1970-01-01
    • 1970-01-01
    • 2023-04-05
    • 2021-05-28
    相关资源
    最近更新 更多