我在SoapUI中创建了一个测试步骤。我需要设置一个长时间的延迟,例如5分钟。我的意思是,在测试步骤之间没有延迟,我只需要等待一个步骤的响应。我该如何做?
将套接字超时设置为300000毫秒。 SoapUI文档
TestStep
设置套接字超时时间,但是您可以通过使用TestStep
和groovy TestStep
来实现。 您可以按照以下步骤操作:
TestCase
中创建TestStep
并将其禁用,因为您将从groovy运行它。Groovy testStep
,在运行testStep
之前更改全局套接字超时时间,并在执行后再次设置默认值,使用com.eviware.soapui.SoapUI
class。groovy
代码:import com.eviware.soapui.SoapUI
import com.eviware.soapui.settings.HttpSettings
import com.eviware.soapui.model.testsuite.TestStepResult.TestStepStatus
// get the settings
def settings = SoapUI.getSettings();
// save the possible previous timeout
def bk_timeout = settings.getString(HttpSettings.SOCKET_TIMEOUT,"");
// set the new timeout... in your case 5 minutes in miliseconds
settings.setString(HttpSettings.SOCKET_TIMEOUT,"300000");
// save the new settings
SoapUI.saveSettings();
// get the testStep by name
def testStep = testRunner.testCase.getTestStepByName('Test Request')
// run it
def result = testStep.run( testRunner, context )
if( result.status == TestStepStatus.OK )
{
// ... if all ok
}
// when finish set the timeout to default value again
settings.setString(HttpSettings.SOCKET_TIMEOUT, bk_timeout)
SoapUI.saveSettings()
您的测试用例将如下所示:
groovy
更改设置是否按预期工作,可以尝试修改属性并检查首选项SOAPUI
文件在$USER_HOME\soapui-settings.xml
中是否更改(显然为了测试它,请不要再次备份原始值,如示例中的:)
)。TestCase Options有一个套接字超时设置,适用于该测试。您无法仅为一个步骤设置此设置。
我已经找到了一种设置testCase套接字超时的方法。
在testCase的设置脚本中使用以下代码:
testRunner.testCase.settings.setString("HttpSettings@socket_timeout","10000")
这个值将影响testCase中的所有步骤。
全局SOCKET_TIMEOUT值不受此影响。