最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

测试总是超时,不显示输出的承诺

运维笔记admin18浏览0评论

测试总是超时,不显示输出的承诺

测试总是超时,不显示输出的承诺

        browser.sleep(4000);
        var discount_type = element(by.id("discount_type"));
        var discount_value= element(by.id("discount_value"));
        var grandTotal    = element(by.id("grand-total"));
        var subtotal      = element(by.id("subtotal"));
        var delivery_fee  = element(by.id("delivery_fee"));

        var last = protractor.promise.defer();

        console.log("hallo");
        subtotal.getText().then(function(sub) {
          console.log("#############");
          console.log(sub);
          delivery_fee.getText().then(function(fee) {
            console.log(fee);
            var calc = parseFloat(sub) - parseFloat(fee) - parseFloat(config.promocodes.referral.discount);
            console.log(calc);
            last.fulfill(calc);
          }); 
        }); 
        last.then(function(calc) { 
            console.log("final wait");
            expect(grandTotal.getText()).toBe("$" + calc); 
        }); 

我需要计算的值之前,我可以肯定,我的测试运行正常。

在我的测试中,我总能看到“你好”在控制台中。然后,我得到一个

> hallo
 A Jasmine spec timed out. Resetting the WebDriver Control Flow.
> F
> 
> Failures: 1) Refer a user and apply referral code should assign
> referral discount to user   Message:
>     Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.   Stack:
>     Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
>         at Timer.listOnTimeout (timers.js:92:15)

看来代码永远不会进入subtotal.getText()承诺!这是为什么???

回答如下:

你永远不自许分辨率函数返回。而且,你不必有一个延期:

var last = subtotal.getText().then(function(sub) {
  return delivery_fee.getText().then(function(fee) {
    return parseFloat(sub) - parseFloat(fee) - parseFloat(config.promocodes.referral.discount);
  }); 
}); 
last.then(function(calc) { 
    expect(grandTotal.getText()).toBe("$" + calc); 
}); 
发布评论

评论列表(0)

  1. 暂无评论