Ed *_*hop 7 mocha.js chai selenium-webdriver typescript
我正在尝试增加mocha测试的超时,因为它们是构成自动UI测试套件一部分的Web请求,因此可能需要比默认的2000ms更长的时间.
如果我调用mocha并将--timeout设置为5000ms左右,但默认的2000ms是不够的,那么代码本身效果很好.
我希望能够设置每个测试套件的超时,以便超时成为成功标准的一部分,这可能因具体情况而异.
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!");
});
});
})
Run Code Online (Sandbox Code Playgroud)
bas*_*rat 16
使用function
an的intead arrow
然后只调用this.timeout(5000);
eg
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!");
});
});
Run Code Online (Sandbox Code Playgroud)
这是因为()=>
捕获周围环境this
.更多http://basarat.gitbooks.io/typescript/content/docs/arrow-functions.html
basarat 答案的另一种选择,沿着使用不同语法的类似路线(这实际上以不同的方式混淆了!):
describe('When we take a look at the stack overflow home page', () => {
it('does not have crazy cat text in it!', () => {
expect('#h-top-questions').dom.to.not.contain.text("Just cats here!");
}).timeout(5000);
});
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2313 次 |
最近记录: |