Den*_*son 5 jasmine angularjs protractor
我有一些字符串,我使用量角器/ jasmine/angularJS提取并转换为整数.我现在正在尝试将这些添加在一起并在期望声明中进行比较.但是我这样做会有一些承诺错误.
var result0 = element.all(by.binding('Inboxes.Inbox.Count')).first().getText().then(parseFloat);
result0.then((value) => console.log("count: ", value));
var result1 = element.all(by.binding('InboxItem.Count')).get(0).getText().then(parseFloat);
result1.then((value) => console.log("count: ", value));
var result2 = element.all(by.binding('InboxItem.Count')).get(1).getText().then(parseFloat);
result2.then((value) => console.log("count: ", value));
var result3 = element.all(by.binding('InboxItem.Count')).get(2).getText().then(parseFloat);
result3.then((value) => console.log("count: ", value)).then(expect(result1 + result2 + result3).toEqual(result0));
//compare badge counts to Inbox badge count
expect(result1 + result2 + result3).toEqual(result0);
});
});
});
Run Code Online (Sandbox Code Playgroud)
我收到以下承诺错误.我认为既然承诺已经满足并且下面的计数打印出来(41,7,14和20)我可以将底部3(reulst1-3)加在一起并与result0进行比较,结果是结果总数1-3 .我有这些承诺的时间,因为我是新手,并不太了解它们.
Started
count: 41
count: 7
count: 14
count: 20
F
Failures:
1) Workflow Application When selecting Alerts panel should expand the Inbox panel and Postings
Message:
Expected 'ManagedPromise::859 {[[PromiseStatus]]: "pending"}ManagedPromise::896 {[[PromiseStatus]]: "pending"}ManagedPromise::933 {[[PromiseStatus]]: "pending"}' to equal ManagedPromise::822 {[[PromiseStatus]]: "pending"}.
Run Code Online (Sandbox Code Playgroud)
您正在尝试将承诺添加在一起,而不是实际解决的值。
在这种情况下,我将使用protractor.promise.all()立即解决实现期望所需的所有承诺:
protractor.promise.all([result0, result1, result2, result3]).then(function (values) {
expect(values[1] + values[2] + values[3]).toEqual(values[0]);
});
Run Code Online (Sandbox Code Playgroud)
而且,为了简化这一点,您可以将spread()解析值放入“then”函数参数中:
protractor.promise.all([result0, result1, result2, result3]).then(spread(function (value0, value1, value2, value3) {
expect(value1 + value2 + value3).toEqual(value0);
}));
Run Code Online (Sandbox Code Playgroud)
请注意,与 不同的是q,protractor.promise它没有spread()内置的,您必须有一个自定义的。