代码之家  ›  专栏  ›  技术社区  ›  oligofren

无论设置如何,始终在10秒时超时

  •  1
  • oligofren  · 技术社区  · 7 年前

    我正在运行一个简单的WebDriverIO脚本,插入任何数量的异步行为都会使其在10秒阈值(或之前?)超时。我想控制超时设置,但无论我尝试什么,我都无法增加它。

    browser.timeouts('implicit', 30000) (或 script pageLoad unknown error: unknown type of timeout:pageLoad .

    only other timeouts I have found

    • mochaOpts.timeout
    • 等待超时

    it.only('should be able to register', ()=>{
      // Mocha timeout
      this.timeout(50000)
    
      browser.url('/encounter/new');
    
      browser.waitUntil( function() {
        return browser.isExisting('[name=lastName]');
      });
    
      browser.setValue('#problem', 'something fishy'); 
    
      // this is problematic: comment this out and everything works
      // also works with very small timeouts
      browser.executeAsync(function(done){
        setTimeout(done, 1000);
      });
    
      browser.click('#appdetailsheader button');
      console.log(browser.getUrl(), browser.log('browser'))
    
      browser.waitUntil( function() {
        return !browser.isExisting('[name=lastName]');
      });
    
      console.log(browser.getTitle(), browser.getUrl());
      console.log(browser.log('browser'))
    });
    
    1 回复  |  直到 7 年前
        1
  •  2
  •   iamdanchiv    7 年前


    为此:

     // Mocha timeout
     this.timeout(50000);
    

    !!! arrow function 摩卡咖啡不鼓励这样做。了解更多信息 here .

    解决方案 (根据您的设置选择):

    • WebdriverIO test-runner 并设置 mochaOpts: { timeout: <desiredTimeout>} ,或者您甚至可以从测试运行中覆盖它: wdio wdio.config.js --mochaOpts.timeout=<desiredTimeout>
    • 设置您的 timeout describe 声明,甚至更好,在 before 挂钩: before(function() { this.timeout(<desiredTimeout>); (...)});
    • 如果您使用Mocha运行测试用例,请将超时传递到CLI命令中(如果您使用它来运行测试): mocha yourTestFile.js --timeout <desiredTimeout> ,或更改其在您的 mocha.opts

    注:


      browser.waitUntil( function() {
          return browser.isExisting('[name=lastName]');
      });
    

    !!! 这将始终等待 element name="lastName" 默认情况下 1000 ms 在超时之前。该值可以通过以下方式更改: waitforTimeout

    解决方案

    • 明确给出您的 waitUntil... / waitfor... browser.waitUntil( function() { return browser.isExisting('[name=lastName]');}, <desiredTimeout>, <errorMessage>); ;
    • 使用运行脚本 WebdriverIO测试运行程序 并设置 waitforTimeout: <desiredTimeout> wdio wdio.config.js --waitforTimeout=<desiredTimeout>

    最后,我试着运行了几个具有淫秽超时值的测试用例( 50000 ms )对于你提到的每一个问题,它都像预期的那样起作用。

    waitforTimeout示例 :

    日志 ( 1 failing (57s) ):

    [chrome #0-0]         ConnectWeb Devices Content Test Suite
    [chrome #0-0]           1) "before all" hook
    [chrome #0-0]
    [chrome #0-0]
    [chrome #0-0] 1 failing (57s)
    [chrome #0-0]
    [chrome #0-0] 1) ConnectWeb Devices Content Test Suite "before all" hook:
    [chrome #0-0] Oups! An error occured.
    Timed out waiting for element ('span[connectqa-device="events"]') to exist
    

    注: 我以前从未在WebdriverIO中使用过Selenium超时( implicit pageLoad , script )但是我以前从来没有这样的必要性 对于我的测试场景来说非常有效。

    本声明 inserting any amount of async behaviour is making it time out at the 10 sec threshold sync: true 但在幕后,一切仍然是异步的。