How to access all soap request in a single groovy script

痴心易碎 提交于 2020-01-17 05:58:10

问题


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 

       }
    }

回答1:


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.



来源:https://stackoverflow.com/questions/42928383/how-to-access-all-soap-request-in-a-single-groovy-script

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