我在 selenium 测试中有以下函数,并且 setTimeout 函数总是比应有的速度快 25% 左右。在本例中,需要等待 20 秒,函数在 15 秒后完成。
test.describe('basic login test',function(){
this.timeout(timeout);
// variables
test.before(...);
test.it.only('Test', function(done){
testLoginPage.load().then(...)
.then(...).then(...)
.then(...).then(...)
.then(function(){
var first = "1st: " + new Date().getTime();
console.log(first);
setTimeout(function(){
driver.getTitle().then(function(title){
assert.equal(title, 'Tittle', 'Error.');
});
console.log(first);
console.log("2nd: " + new Date().getTime());
done();
}, 20000);
}).then(...)
});
test.after();
});
输出:
1st: 1457706590459
1st: 1457706590459
2nd: 1457706605462
最佳答案
不可能,但以下情况除外。
您正在使用的代码或库具有覆盖的自定义
setTimeout
函数,它正在调用实际setTimeout
函数运行时间更短。您正在使用
JavaScript
运行时(非常旧),存在非常非常严重问题。其他一些
function
正在中间打印它(不过看起来不像您的代码)
关于javascript - setTimeout 函数比应有的速度要快,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35941946/