强制量角器等待种子数据加载 [英] Force protractor to wait for seed data to load

查看:76
本文介绍了强制量角器等待种子数据加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须为测试加载一些种子数据.在测试开始运行之前,我很难确保种子数据已完全加载.

I have to load some seed data for my tests. I'm having a really hard time making sure the seed data has loaded completely before the tests begin running.

在beforeAll块中,我调用为我的API编写的适配器,该适配器清除所有数据,加载指定的种子数据文件,然后运行从量角器测试文件传入的回调.

In the beforeAll block I'm calling an adapter I wrote for my API that clears out any data, loads a specified file of seed data and then runs a callback passed in from the protractor test file.

我无法将测试用例包含在回调中(这似乎与重构Promise相似,是一个阻塞问题),或者量角器无法识别它们.

I can't include the test cases in a callback (this seems like it would be a similar blocking issue to refactoring to promises) or protractor doesn't recognize them.

有人可以建议我在测试开始之前确保我的API已经成功播种的方法吗?

Can anyone suggest a way I can make sure my API has been successfully seeded before the tests begin?

谢谢!

推荐答案

如果您将Jasmine 2.1或更高版本与Protractor一起使用,则可以使用

If you are using Jasmine 2.1 or higher with Protractor you can make use of the done() function in your beforeAll.

因此,如果您有一个名为seedMyDataAsync()的函数,该函数将回调函数作为参数,则可以执行以下操作:

So if you have a function called seedMyDataAsync() that takes a callback function as a parameter, you could do something as simple as this:

beforeAll( function(done) {
    seedMyDataAsync(done);
});

done()函数是Jasmine 2.0引入的,但是直到Jasmine 2.1才在beforeAll()中可用.

The done() function was introduced with Jasmine 2.0, but wasn't available for beforeAll() until Jasmine 2.1.

从文档中:

调用beforeAll,afterAll,beforeEach,afterEach,它可以接受一个可选的单个参数,异步工作完成后应调用该参数.

Calls to beforeAll, afterAll, beforeEach, afterEach, and it can take an optional single argument that should be called when the async work is complete.

默认情况下,茉莉花5秒等待异步规范完成,然后再导致超时失败.如果超时在完成之前被调用,则当前规范将被标记为失败,并且套件执行将继续,就像调用了完成一样.

By default jasmine will wait for 5 seconds for an asynchronous spec to finish before causing a timeout failure. If the timeout expires before done is called, the current spec will be marked as failed and suite execution will continue as if done was called.

这篇关于强制量角器等待种子数据加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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