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

查看:469
本文介绍了如何在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"))

然后,仍然在循环中,调用Web服务:

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天全站免登陆