通过Groovy脚本在SoapUI中进行自动数据驱动测试

时间:2019-12-17 09:19:58

标签: groovy soapui

正如在soapUI免费版本中讨论的HERE一样,我试图将此WS称为:

    <soap:Body>
<RequestParameters>
    <Parameter name="key" value="SomeorderId"/>
</RequestParameters>
    </soap:Body>

,我想从桌面上的本地data.txt文件中获取“ key”的值。该文件的内容:

9999999991
9999999992
9999999993

为此,我用以下三个测试步骤创建了一个测试套件:

1。第一步:常规脚本:

def data = new File('C:/Users/Polarick/Desktop/data.txt') 
data.eachLine { orderId ->
   context.orderId = orderId
   //Get the step2, index of the step is 1
   def step = context.testCase.getTestStepAt(1)
   //Run the step2
   step.run(testRunner, context)
}
//all the orders got executed,jump to step2, index is 2
testRunner.gotoStep(2)

2。第二步:修改请求:

<Parameter name="MSISDN" value="${orderId}"/>

并对其声明该脚本:

//Check if there is response
assert context.request, "Request is empty or null"

//Save the contents to a file
def saveToFile(file, content) {
    if (!file.parentFile.exists()) {
         file.parentFile.mkdirs()
         log.info "Directory did not exist, created"
    }
    file.write(content) 
    assert file.exists(), "${file.name} not created"
}

def response = context.expand( '${Step2#Response}' )
def f = new File("C:/Users/Polarick/Desktop/${context.orderId}_Response.xml")
f.write(response, "UTF-8")
saveToFile(f, context.response)

3。第三步:常规脚本:

log.info "Test completed."

一切正常,并依次为data.txt文件中存在的所有行调用WS,但是我希望每次执行都找到一个响应.xml文件,例如:

C:/Users/Polarick/Desktop/9999999991_Response.xml
C:/Users/Polarick/Desktop/9999999992_Response.xml
C:/Users/Polarick/Desktop/9999999993_Response.xml

,但没有生成响应文件, 你能帮忙吗?

0 个答案:

没有答案
相关问题