如何使用量角器向流控制队列添加承诺? [英] How do you add a promise to the flow control queue using protractor?

查看:16
本文介绍了如何使用量角器向流控制队列添加承诺?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的测试中,在使用量角器运行一些 ui 测试之前,我正在调用外部库以将数据播种到我们的后端.

In my test I am calling and outside library to seed data into our backend before running some ui tests using protractor.

'use strict'

var dataBuilder = require('data_builder.js');

describe('test', function () {
  var testData = {
    name: 'foo',
    title: 'bar',
    ...
  };

  beforeEach(function () {
    //create test data on the backend
    dataBuilder.create(testData).then(function (id) {
      testData.id = id.id;
    });
  });



  it('test something', function () {
    ...
  });

因此,在 it() 实际完成之前,dataBuilder 返回的承诺不会得到解决.如何将dataBuilder返回的promise添加到webDriver的流控中?

As such the promise returned by the dataBuilder isn't resolved before the it() actually finishes. How can I add the promise returned by the dataBuilder into webDriver's flow control?

推荐答案

Protractor 在 protractor 对象上公开 WebDriverJS 承诺,因此您可以使用 flow.await 方法或创建新的承诺并使用 <代码>flow.execute.

Protractor exposes WebDriverJS promises on the protractor object so you could use either the flow.await method or create a new promise and use flow.execute.

前者可以实现如下:

flow = protractor.promise.controlFlow()

flow.await(dataBuilder.create(testData)).then( function(id) {
    testData.id = id.id;
})

您可以在此 博文.

这可以在 it 函数本身中完成,或者如果这对所有测试都是通用的,请考虑将其放在量角器配置的 onPrepare 函数中.

This could be done in the it function itself or if this is common to all your tests consider placing it in the onPrepare function of your protractor config.

这篇关于如何使用量角器向流控制队列添加承诺?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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