【问题标题】:Fail the test script, if the time taken to complete the test crosses 30 seconds如果完成测试所用的时间超过 30 秒,则测试脚本失败
【发布时间】:2019-04-02 06:41:38
【问题描述】:

要求是特定的 selenium 脚本必须在 30 秒内完成执行。如果超过 30 秒,脚本应该会失败。不是测试步骤,但整个脚本必须在 30 秒内运行(不是隐式或显式等待)

【问题讨论】:

    标签: selenium


    【解决方案1】:

    如果您在 Java 和 TestNG 中使用 Selenium,那么您可以在测试注释中使用 timeOut 参数

    例如

    @Test(timeOut = 30000)
    public void testMethod(){
         // do's
    }
    

    这就是您可以在 XML 中配置以在给定时间内完成测试的方式

    <suite name="Time test Suite" time-out="30000" verbose="1" >
      <test name="Timeout Test" >
        <classes>
          <class name="com.howtodoinjava.test.TimeoutSuite" />
        </classes>
      </test>
    </suite>
    

    更多详情请咨询this

    【讨论】:

      【解决方案2】:

      setScriptTimeout

      setScriptTimeout 设置在引发错误之前等待异步脚本完成执行的时间量。如果超时为负数,则允许脚本无限期运行。

      • 定义:

        WebDriver.Timeouts setScriptTimeout(long time, java.util.concurrent.TimeUnit unit)
        
        Parameters:
         time - The timeout value.
         unit - The unit of time.
        
        Returns:
         A self reference.
        
      • 用法:

        • Java

          driver.manage().timeouts().setScriptTimeout(1800, TimeUnit.SECONDS);
          
        • Python

          driver.set_script_timeout(30)
          

      可以在What does Selenium .set_script_timeout(n) do and how is it different from driver.set_page_load_timeout(n)?找到相关讨论

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-09-02
        • 1970-01-01
        • 1970-01-01
        • 2021-12-04
        • 2015-02-03
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多