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

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

问题描述

在我的测试中我打电话和外部库使用量角器运行一些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 () {
    ...
  });

这样的dataBuilder返回的诺言之前没有得到解决()实际上完成。如何添加由dataBuilder返回到的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?

推荐答案

量角器公开量角器对象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;
})

你可以看到在这个博客后者的例子帖子

这可能会在函数本身来完成,或者如果这是共同的所有测试考虑将其放置在上prepare 您量角器配置的功能。

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天全站免登陆