我正在尝试增加 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/