量angular器:testing总是超时,不显示诺言输出

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); }); 

在确定我的testing运行正常之前,我需要计算一个值。

在我的testing中,我总是在控制台中看到“hallo”。 然后我得到一个

 > 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()诺言! 这是为什么???

永远不会从承诺parsingfunction返回 。 而且,你不必延期:

 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); });