且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何访问单个groovy脚本中的所有soap请求

更新时间:2023-12-05 16:44:58

从附加的图像看起来像 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.