Javascript setTimeout函数比它应该的更快

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

我在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
    运行时(非常旧),有一个非常关键的问题

  • 另一个
    函数
    正在其间打印它(但从代码上看不是这样)


硒或webstorm不会改变设置时间。。。确保没有其他可能记录日期和清除超时的函数。您能告诉我为什么代码中有3个console.log,但有2个输出吗?能否为每个console.log添加一个id,例如
console.log(“1st:+newdate().getTime())@Buaban编辑和rafaelcastrocouto我很确定…不可能。你能试试这个吗:给一个变量分配开始时间。第二次打印时,也要第一次打印。这只是为了验证,如果没有其他函数或回调函数在做这件事。是的,那是不可能的,你是对的。我很不好意思这么说,但我的解决办法是重新启动Windows操作系统:-/。谢谢你的时间,对此我很抱歉。