防止 Protractor 在 promise 被解决之前完成 [英] Prevent Protractor from finishing before promise has been resolved
问题描述
我有一些异步 WebDriverJS 处理被跳过,因为测试在解决它们之前就完成了.如何让量角器等待?
例如:(这两个测试都应该失败(潜在票证提交)
it('test promise', function (done) {var d = protractor.promise.defer();d.fulfill(true)d.promise.then(函数(项目){console.log("履行", item);});期望(d.promise).toBe(假);console.log("测试完成");});it('用超时测试承诺', function (done) {var d = protractor.promise.defer();设置超时(函数(){console.log("履行");d.fulfill(true)}, 3000);d.promise.then(函数(项目){console.log("履行", item);});期望(d.promise).toBe(假);console.log("测试完成");});
如果您需要更多信息,请告诉我...?
这将返回 true.. 如果您删除超时并设置完成,它将起作用...
量角器端
11 天前已合并解决此问题
你可以让它与 createFlow
一起工作,但解决方案会简单得多,只需在 fulfill
之后调用 done()
,如下所示:
it('用 setTimeout 测试承诺', function(done) {var d = protractor.promise.defer();设置超时(函数(){console.log("履行");d.fulfill('ok');完毕();}, 3000);期望(d).toBe('ok');});
目前在 master 分支上,所以希望它在 protractor >= 0.23.0 中发布/p>
Web 应用端(信息丰富)
I have some async WebDriverJS processing that is being skipped because the test is completing before they are are being resolve. How do I get protractor to wait ?
e.g.: (both of these tests should fail (potential ticket submitted)
it('test promise ', function (done) {
var d = protractor.promise.defer();
d.fulfill(true)
d.promise.then(function (item) {
console.log("fulfill", item);
});
expect(d.promise)
.toBe(false);
console.log("test done");
});
it('test promise with timeout ', function (done) {
var d = protractor.promise.defer();
setTimeout(function () {
console.log("fulfill");
d.fulfill(true)
}, 3000);
d.promise.then(function (item) {
console.log("fulfill", item);
});
expect(d.promise)
.toBe(false);
console.log("test done");
});
Let me know if you need more information ... ?
This will return true.. if you remove the timeout and just set fulfill it will work...
Protractor side
The fix for this has been merged 11 days ago
You can have it working with createFlow
but solution will be much simpler, just call done()
after fulfill
like this:
it('test promise with setTimeout ', function(done) {
var d = protractor.promise.defer();
setTimeout(function() {
console.log("fulfill");
d.fulfill('ok');
done();
}, 3000);
expect(d).toBe('ok');
});
Currently on master branch so expect this to be shipped in protractor >= 0.23.0
Web app side (informative)
Protractor doesn't know how to wait for setTimeout
But does know how to wait for $timeout
这篇关于防止 Protractor 在 promise 被解决之前完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!