Javascript setTimeout函数比它应该的更快
我在selenium测试中有以下函数,setTimeout函数的执行速度总是比实际速度快25%。在这种情况下,您需要等待20秒,15秒后功能完成Javascript setTimeout函数比它应该的更快,javascript,node.js,selenium,webstorm,Javascript,Node.js,Selenium,Webstorm,我在selenium测试中有以下函数,setTimeout函数的执行速度总是比实际速度快25%。在这种情况下,您需要等待20秒,15秒后功能完成 test.describe('basic login test',function(){ this.timeout(timeout); // variables test.before(...); test.it.only('Test', function(done){ testLoginPage.lo
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
- 另一个
正在其间打印它(但从代码上看不是这样)函数
console.log(“1st:+newdate().getTime())代码>@Buaban编辑和rafaelcastrocouto我很确定…不可能。你能试试这个吗:给一个变量分配开始时间。第二次打印时,也要第一次打印。这只是为了验证,如果没有其他函数或回调函数在做这件事。是的,那是不可能的,你是对的。我很不好意思这么说,但我的解决办法是重新启动Windows操作系统:-/。谢谢你的时间,对此我很抱歉。