how can i make requests in a loop in soapUI with different content?

守給你的承諾、 提交于 2020-02-07 05:24:29

问题


I have a method as a request in soapUI. it transfers data to an online platform. i have different variables which are with different contet each time. is there a way how i can loop the request with different contet each time?

i tried to somehow connect the request to a groovy script in order to programm the loopthere but couldent figure out how to do it

the goal is to have for example a cvs file where for example 100 addresses are saved. then have all the data tranfered. but all the data which is related to the same address is transferred in the same request. and the request has to be repeated with every "group of data" (e.g. address, name, telefone number, id, gender)


回答1:


If you are not using Pro, there is a lot you can do with the open source version, but it requires some Groovy scripting. It is not too hard though. The basic premise is: read some data from a CSV -> for each record replace variable values -> call the service with those variables. All in one script.

Let's get the CSV data first:

    new File("/path/to/data.csv").splitEachLine(",") { line ->
        def address = line[0]
        def name = line[1]
        def telephoneNumber = line[2]
        def id = line[3]
        def gender = line[4]

Test to make sure:

        log.info(name)

SoapUI uses a concept called properties linked to various levels of scope: a test case, test suite, project and so on. You can populate props like that with the CSV values, and use them in SOAP calls. You can combine this with the above, but I split it for clarity:

        testRunner.testCase.setPropertyValue( "address", address )
        testRunner.testCase.setPropertyValue( "name", name )
        testRunner.testCase.setPropertyValue( "telephoneNumber", telephoneNumber )
        testRunner.testCase.setPropertyValue( "id", id )
        testRunner.testCase.setPropertyValue( "gender", gender )

You'll see them on the Custom Properties tab if the test case is selected. You can also retreive the values programmatically like this:

        log.info(testRunner.testCase.getPropertyValue("name"))

Then, still in the loop, call the web service:

        def soapTestStep = testRunner.testCase.getTestStepByName("My SOAP Request").name
        testRunner.runTestStepByName(soapTestStep)

If you want the result XML, to save to a file, get it like this:

        import com.eviware.soapui.support.XmlHolder
        def xml = new XmlHolder(context.response)

End loop:

    }

The last part is to get the property values dynamically into the soap call. You do that like this in the request XML:

    <soap:Header/>
        <soap:Body>
            <ns:SomeRequest>
                 <ns:address>${#TestCase#address}</ns:address>
                 <ns:name>${#TestCase#name}</ns:name>
                 ...

Once you realise that you have access to the full Groovy language, a lot of things are possible.



来源:https://stackoverflow.com/questions/58525954/how-can-i-make-requests-in-a-loop-in-soapui-with-different-content

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!