如何在具有不同内容的soapUI中循环发出请求? [英] how can i make requests in a loop in soapUI with different content?

查看:17
本文介绍了如何在具有不同内容的soapUI中循环发出请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个方法作为soapUI中的请求.它将数据传输到在线平台.我有不同的变量,每次都有不同的内容.有没有办法让我每次都用不同的内容循环请求?

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?

我试图以某种方式将请求连接到一个 groovy 脚本,以便在那里编程循环,但无法弄清楚如何去做

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

目标是拥有一个 cvs 文件,例如保存 100 个地址.然后传输所有数据.但是所有与同一地址相关的数据都在同一个请求中传输.并且必须对每个数据组"(例如地址、姓名、电话号码、ID、性别)重复请求

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)

推荐答案

如果您没有使用 Pro,那么您可以使用开源版本做很多事情,但它需要一些 Groovy 脚本.不过也不算太难.基本前提是:从 CSV 读取一些数据 -> 为每条记录替换变量值 -> 使用这些变量调用服务.全部在一个脚本中.

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.

我们先获取CSV数据:

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]

测试以确保:

        log.info(name)

SoapUI 使用一个称为属性的概念,链接到不同级别的范围:测试用例、测试套件、项目等.您可以使用 CSV 值填充类似的道具,并在 SOAP 调用中使用它们.你可以把它和上面的结合起来,但为了清楚起见,我把它分开了:

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)

如果您希望将结果 XML 保存到文件,请按如下方式获取:

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)

结束循环:

    }

最后一部分是动态获取属性值到soap调用中.您可以在请求 XML 中这样做:

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>
                 ...

一旦您意识到您可以使用完整的 Groovy 语言,很多事情都是可能的.

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

这篇关于如何在具有不同内容的soapUI中循环发出请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆