selenium-webdriver - 如何在 typescript 测试中增加每个套件的 Mocha 超时

标签 selenium-webdriver typescript mocha.js chai

我正在尝试增加 mocha 测试的超时时间,因为它们是构成自动化 UI 测试套件一部分的网络请求,因此可能需要比默认 2000 毫秒更长的时间。

如果我调用 mocha 并将 --timeout 设置为 5000 毫秒左右,但默认的 2000 毫秒是不够的,那么代码本身就很好用。

我希望能够为每个测试套件设置超时,以便超时成为成功标准的一部分,这可能因具体情况而异。

before(()=>{
  var sw = require('selenium-webdriver');
  this.driver = new sw.Builder().withCapabilities(sw.Capabilities.chrome()).build();
  var c = require('chai');
  c.use(require('chai-webdriver')(this.driver));
  this.expect = c.expect;
  return this.driver.getWindowHandle();
})

after(() => {
  return this.driver.quit();
})

describe('Looking at github', () => {
  beforeEach(() => {
    this.driver.get('http://stackoverflow.com/');
  })
  describe('When we take a look at the stack overflow home page', () => {
    return it('It does not have crazy cat text in it!', () => {
      return this.expect('#h-top-questions').dom.to.not.contain.text("Just cats here!");
    });
  });
})

最佳答案

使用 function 而不是 arrow 然后调用 this.timeout(5000); 例如

describe('When we take a look at the stack overflow home page', () => {
    return it('It does not have crazy cat text in it!', function() {
      this.timeout(5000);
      return this.expect('#h-top-questions').dom.to.not.contain.text("Just cats here!");
    });
  });

这是因为 ()=> 捕获了周围的 this。更多 http://basarat.gitbooks.io/typescript/content/docs/arrow-functions.html

关于selenium-webdriver - 如何在 typescript 测试中增加每个套件的 Mocha 超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31418005/

相关文章:

java - 使用 WebDriverWait Boolean 的 NullPointerException

java - 如何通过Selenium和Page Factory实现AjaxElementLocatorFactory?

typescript - 导入 vue typescript 类型定义

typescript - 接口(interface)属性上的类型缩小(删除空选项)

node.js - Mocha 单元测试: where to create variables

node.js - 更改后 Mocha 不会重新运行我的测试

java - 无法使用 EventFiringWebDriver 检索 WebDriver Wrapper

selenium - 在 selenium 中向上滚动页面到顶部

angular - 参数属性只允许在构造函数实现中使用

javascript - 如何 stub 未直接传递给调用函数的函数?