如何与Groovy并行运行SoapUI测试步骤

时间:2018-05-09 11:54:10

标签: multithreading groovy soapui

SoapUI可以选择并行运行测试套件和测试用例,但是没有这样做可以通过测试步骤来实现。

如何在我的测试用例中使用Groovy测试步骤实现这样的功能?

这是我目前的代码:

    import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner

//Get all Soap type test steps within the testCases
for ( testStep in testRunner.testCase.getTestStepsOfType(com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep.class)){
    //Print out the name for the testStep
    tsname = testStep.getName();
    log.info tsname;

    //thread = new Thread("$tsname")
    def th = new Thread("$tsname") {
                    @Override
            public void run(){
            //Set the TestRunner to the respective TestCase
            TestRunner = new com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner(testRunner.testCase, null);
            //Run them all and then rejoin the threads
            log.info("thread: " + tsname)
            TestRunner.runTestStepByName(tsname);
            def soapResponse = TestRunner.getTestCase().getTestStepByName(tsname).getProperty("Response");
            log.info "soapResponse: " + soapResponse;
            th.join();
            }
    }
    th.start();
    th.join();
}

1 个答案:

答案 0 :(得分:2)

管理自己解决这个问题并在这里为所有遇到同样问题的人发布答案:

import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep

List<String> steps = testRunner.testCase.getTestStepsOfType(com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep.class)
def map = [:]

//define the threads list, this will hold all threads
def threads = []

def kickEm = steps.each{ step ->

    def th = new Thread({

        stepName = step.getName();
        log.info "Thread in start: " + step.getName();
        //Set the TestRunner to the respective TestCase
        TestRunner = new com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner(testRunner.testCase, null);
        //Run the corresponding teststep
        TestRunner.runTestStepByName(step.getName());
        //Get the response of the current step
        def soapResponse = context.expand(TestRunner.getTestCase().getTestStepByName(step.getName()).getPropertyValue('Response')) as String;
        log.info "In thread "+step.getName()+" soapResponse: " + soapResponse
        //Put this into a map, the key is the stepname and the value is its response, so we can retrieve it all outside the each loop
        map.put(step.getName(), soapResponse);
    })

   log.info "Putting new Thread({..}) th back into the threads list";
   threads << th;
}

threads.each { it.start(); }

threads.each { it.join(); }

log.info "Map: "

map.each { step, response ->
    log.info "Step: ${step} has the response ${response}"
    };

log.info "Done!"