【发布时间】:2014-10-22 03:45:36
【问题描述】:
我在soapui 中创建了一个测试步骤。我需要为它设置一个长时间的延迟,比如 5 分钟。我的意思是测试步骤之间没有延迟,我只需要等待一个响应。我该怎么做?
【问题讨论】:
我在soapui 中创建了一个测试步骤。我需要为它设置一个长时间的延迟,比如 5 分钟。我的意思是测试步骤之间没有延迟,我只需要等待一个响应。我该怎么做?
【问题讨论】:
将 Socket Timeout 设置为 300000 毫秒。 SoapUI Documentation
【讨论】:
TestCase Options 具有该测试的 Socket 超时设置。不能只设置一个步骤。
【讨论】:
正如其他答案所说,无法为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 检查更改设置是否按预期工作,您可以尝试修改属性并检查$USER_HOME\soapui-settings.xml 中的首选项SOAPUI 文件是否更改(显然为了测试它不备份与示例 :) 中的原始值相同。
【讨论】:
which will change the global socket timeout - 似乎它会影响所有soapui项目。我的意思是,如果有另一个测试并行运行,他们将“看到”修改后的全局超时。例如,当几个测试用例包含该代码时,它们可以同步设置全局超时,并且对于其中的几个,它可能比需要的要小。将TestCase超时设置为SiKing建议更好吗?
我找到了一种设置 testCase 套接字超时的方法。
在 testCase 的设置脚本中使用以下代码:
testRunner.testCase.settings.setString("HttpSettings@socket_timeout","10000")
testCase 内的所有步骤都将受此值影响。
全局 SOCKET_TIMEOUT 值不受此影响。
【讨论】: