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();
}
解决方案
设法自己解决了这个问题,并在这里为所有遇到同样问题的人发布了答案:
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!"
推荐阅读
- java - 为什么 Lombok 在覆盖通用 getter 时会生成额外的 Getter?
- r - 从 R 导出西里尔字符?
- python - 我可以在异步协程上使用阻塞锁吗?
- tensorflow - tensorflow.keras.preprocessing.text.Tokenizer.texts_to_matrix 有什么作用?
- ios - 尝试在 Network.Framework 中使用 NWConnection 时出现问题
- javascript - 如何将随机大小的图像排列成等长的行?
- powershell - 将 PowerShell 变量传递给文件路径
- html - 将数据传递给 ionic 5 自定义元素标签
- javascript - poseNet on react native 导致 FileReader 错误
- android - 如何修复此错误类“列表”
' 没有实例获取器 'fruitsItemsList'。接收方:“_GrowableList”的实例(长度:1)?