这也许是一个愚蠢的问题,但是我很难找到我需要的答案。我有个中继器计数的测试。我想返回count变量,这样我就可以将它传递给另一个测试,以便在for循环中使用。
我试过的是:
this.countsInitialBookings = function() {
var j = 0;
browser.driver.sleep(3000);
bookingLists = element.all(by.repeater('booking in bookingsCtrl.bookings'));
bookingLists.count().then(function(count) {
//have also tried making bookingCount global and setting value to 0
var bookingCount = count;
});
return bookingCount;
};
这就是吐出outStarted的东西
.{ closure_uid_966269928: 651,
flow_:
{ events_: {},
closure_uid_966269928: 1,
activeFrame_:
{ events_: {},
closure_uid_966269928: 642,
flow_: [Circular],
parent_: [Object],
children_: [Object],
lastInsertedChild_: [Object],
pendingTask_: null,
isLocked_: false,
isBlocked_: false,
pendingCallback: false,
pendingRejection: false,
cancellationError_: null },
schedulingFrame_:
{ events_: {},
closure_uid_966269928: 642,
flow_: [Circular],
parent_: [Object],
children_: [Object],
lastInsertedChild_: [Object],
pendingTask_: null,
isLocked_: false,
isBlocked_: false,
pendingCallback: false,
pendingRejection: false,
cancellationError_: null },
shutdownTask_: null,
eventLoopTask_: null,
hold_:
{ _idleTimeout: 2147483647,
_idlePrev: [Object],
_idleNext: [Object],
_idleStart: 99601735,
_onTimeout: [Function: wrapper],
_repeat: true },
yieldCount_: 1 },
stack_: null,
parent_:
{ closure_uid_966269928: 649,
flow_:
{ events_: {},
closure_uid_966269928: 1,
activeFrame_: [Object],
schedulingFrame_: [Object],
shutdownTask_: null,
eventLoopTask_: null,
hold_: [Object],
yieldCount_: 1 },
stack_: null,
parent_:
{ closure_uid_966269928: 647,
flow_: [Object],
stack_: null,
parent_: [Object],
callbacks_: [Object],
state_: 'pending',
handled_: true,
pendingNotifications_: false,
value_: undefined },
callbacks_: [ [Object] ],
state_: 'pending',
handled_: true,
pendingNotifications_: false,
value_: undefined },
callbacks_: null,
state_: 'pending',
handled_: false,
pendingNotifications_: false,
value_: undefined }
.
2 specs, 0 failures
Finished in 17.516 seconds
[launcher] 0 instance(s) of WebDriver still running
[launcher] chrome #1 passed
Process finished with exit code 0发布于 2015-08-20 20:03:19
由于.count()是异步的,所以不可能从countsInitialBookings返回整数。相反,您应该返回承诺,然后您可以在以后使用该承诺来获得值。
this.countsInitialBookings = function() {
var j = 0;
browser.driver.sleep(3000);
bookingLists = element.all(by.repeater('booking in bookingsCtrl.bookings'));
return bookingLists.count()
};稍后..。
this.countsInitialBookings().then(function (count) {
console.log(count);
});
// do not attempt to get `count` out here, it's simply not possible.
// It will only be accessible inside the above callback.发布于 2015-08-20 22:09:47
就像凯文·B的回答一样。
你正在返回一个“承诺骨架”对象。管理你的承诺链是很重要的,以确保你是1)。返回异步调用2。))返回所需的任何值。)把承诺锁在正确的地方。
虽然我同意Kevin的回答,但让预订成为全球性的,或者改变它的范围,可能会导致另一种解决方案。
https://stackoverflow.com/questions/32126948
复制相似问题