防止 Protractor 在 promise 解决之前完成 [英] Prevent Protractor from finishing before promise has been resolved

查看:53
本文介绍了防止 Protractor 在 promise 解决之前完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些异步 WebDriverJS 处理被跳过,因为测试在解决之前已经完成.如何让量角器等待?

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 ... ?

这将返回true..如果您删除超时并设置完成它会起作用...

This will return true.. if you remove the timeout and just set fulfill it will work...

推荐答案

Protractor side

对此的修复已11 天前合并

您可以使用 createFlow 但解决方案会简单得多,只需在 fulfill 之后调用 done() 像这样:

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

目前在 master 分支上,所以希望它会在 protractor >= 0.23.0

Currently on master branch so expect this to be shipped in protractor >= 0.23.0

量角器 不知道如何设置等待时间

但是知道如何<等待$timeout/a>

But does know how to wait for $timeout

这篇关于防止 Protractor 在 promise 解决之前完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆