【问题标题】:How set timeout for one test step in soapui?如何在soapui中为一个测试步骤设置超时?
【发布时间】:2014-10-22 03:45:36
【问题描述】:

我在soapui 中创建了一个测试步骤。我需要为它设置一个长时间的延迟,比如 5 分钟。我的意思是测试步骤之间没有延迟,我只需要等待一个响应。我该怎么做?

【问题讨论】:

    标签: testing soapui


    【解决方案1】:

    将 Socket Timeout 设置为 300000 毫秒。 SoapUI Documentation

    【讨论】:

    • 它适用于soapui中的所有请求/响应,但我只想要一个测试
    • 如果没有设置超时。默认超时是多少?
    • 60 秒是默认值。
    • 你可以设置0表示不超时
    【解决方案2】:

    TestCase Options 具有该测试的 Socket 超时设置。不能只设置一个步骤。

    【讨论】:

    • 谢谢,我可以为一个测试用例设置 timeout :)
    【解决方案3】:

    正如其他答案所说,无法为TestStep 设置套接字超时,但是您可以使用TestStepgroovy TestStep 来解决这个问题。您可以按照以下步骤进行操作:

    1. 在您的 TestCase 中创建 TestStep 并禁用它,因为您将从 groovy 运行它。
    2. 创建一个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 级别存在套接字超时,我认为可以制作一个类似的 groovy 脚本来更改此属性。我检查它,如果存在,我会更新我的答案。
    【解决方案4】:

    我找到了一种设置 testCase 套接字超时的方法。

    在 testCase 的设置脚本中使用以下代码:

    testRunner.testCase.settings.setString("HttpSettings@socket_timeout","10000")
    

    testCase 内的所有步骤都将受此值影响。

    全局 SOCKET_TIMEOUT 值不受此影响。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-09
      • 2017-09-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多