如何访问单个groovy脚本中的所有soap请求 [英] How to access all soap request in a single groovy script

查看:134
本文介绍了如何访问单个groovy脚本中的所有soap请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个groovy脚本来测试我的所有服务。

我导入了WSDL,然后自动生成了所有的SOAP请求。



我想减少我的手册逐一测试所有SOAP服务的工作。



因此,如果可能的话,我想通过groovy来做到这一点。



在这里使用addressScript - 我想稍后访问所有测试用例中的所有SOAP请求。所以有可能通过上下文中的一些循环来实现它。以下是我尝试的示例代码。

我的主要动机是减少所有测试所有SOAP请求的手动工作。

  import org.apache.commons.httpclient.methods.PostMethod; 
import org.w3c.dom。*;


class示例{
static void main(String [] args){

String serviceInput =;
PostMethod post = new PostMethod();
post.setRequestHeader(Accept,application / soap + xml,application / dime,multipart / related,text / *);
post.setRequestHeader(SOAPAction,);


def req = context.testCase.getTestStepAt(context.currentStepIndex - 1).httpRequest.requestContent
log.info req

//这里我想访问循环中的所有SOAP请求,并按顺序测试所有服务

}
}


解决方案

从附加的图像看起来像 SOAP 请求步骤正在您的案例中使用。



这是 Groovy脚本

  import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep 
//循环所有测试套件的测试用例
context.testCase.testSuite.testCaseList.each {testKase - >
//遍历每个测试用例的所有测试步骤
testKase.testStepList.each {step - >
//检查请求类型是否为SOAP
if(步骤instanceof WsdlTestRequestStep){
//获取测试步骤的请求
def stepRequest = step.getPropertyValue('Request' )
log.info步骤$ {step.name}的请求是:\ n $ {stepRequest}
} else {
log.info'忽略步骤,因为它不是SOAP请求类型步骤'
}
}
}

不是真的当然,一旦你收到请求,你想做什么。无论如何, stepRequest 变量将有请求数据,现在只需要记录 ,就像你在上面的代码中看到的一样。


I am writing a groovy script to test my all services in one single step.

I imported the WSDL and then all the SOAP request are generated automatically.

I want to reduce my manual work of testing all the SOAP services one by one.

So, I want to do it via groovy if possible.

From here in addressScript - I want to access all the SOAP requests in all the test cases later. so is it possible to implement it via some looping in context ..? Below is sample code am trying .

My main moto is to reduce all the manual work of testing all SOAP requests one by one.

import org.apache.commons.httpclient.methods.PostMethod;
import org.w3c.dom.*;


    class Example {
       static void main(String[] args) {

    String serviceInput="";
    PostMethod post = new PostMethod(");
    post.setRequestHeader("Accept", "application/soap+xml,application/dime,multipart/related,text/*");
    post.setRequestHeader("SOAPAction", "");


    def req = context.testCase.getTestStepAt(context.currentStepIndex - 1).httpRequest.requestContent
    log.info req

    // here i want to access all the SOAP requests in loop , and to test all the services in sequence 

       }
    }

解决方案

From the image that you have attached, it looks like SOAP request steps are being used in your case.

Here is the Groovy Script.

import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep
//Loop thru all the test cases of test suite
context.testCase.testSuite.testCaseList.each { testKase ->
    //Loop thru all the test steps of each test case
    testKase.testStepList.each { step ->
           //Check if the request type is SOAP     
        if (step instanceof WsdlTestRequestStep) {
            //Get the request of test step
            def stepRequest = step.getPropertyValue('Request')
            log.info "Request of step ${step.name} is :\n ${stepRequest}"
        } else {
            log.info 'Ignoring step as it is not SOAP request type step'
        }
    }
}

Not really sure, what you wanted to do once you get the request. Anyways, stepRequest variable will have the request data, for now just logging as you see in the above code.

这篇关于如何访问单个groovy脚本中的所有soap请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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