强制量角器等待种子数据加载
Force protractor to wait for seed data to load
我必须为我的测试加载一些种子数据。我很难确保种子数据在测试开始前已完全加载 运行。
在 beforeAll 块中,我正在调用我为我的 API 编写的适配器,该适配器清除所有数据,加载指定的种子数据文件,然后运行从量角器测试文件传入的回调。
我不能在回调中包含测试用例(这似乎是一个与重构承诺类似的阻塞问题)或者量角器无法识别它们。
任何人都可以建议一种方法来确保我的 API 在测试开始之前已成功播种吗?
谢谢!
如果您在 Protractor 中使用 Jasmine 2.1 或更高版本,您可以在 beforeAll
.
中使用 done() 函数
因此,如果您有一个名为 seedMyDataAsync()
的函数,该函数将回调函数作为参数,您可以执行如下简单的操作:
beforeAll( function(done) {
seedMyDataAsync(done);
});
Jasmine 2.0 引入了 done()
函数,但在 Jasmine 2.1 之前 beforeAll()
不可用。
来自文档:
Calls to beforeAll, afterAll, beforeEach, afterEach, and it can take an optional single argument that should be called when the async work is complete.
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.
我必须为我的测试加载一些种子数据。我很难确保种子数据在测试开始前已完全加载 运行。
在 beforeAll 块中,我正在调用我为我的 API 编写的适配器,该适配器清除所有数据,加载指定的种子数据文件,然后运行从量角器测试文件传入的回调。
我不能在回调中包含测试用例(这似乎是一个与重构承诺类似的阻塞问题)或者量角器无法识别它们。
任何人都可以建议一种方法来确保我的 API 在测试开始之前已成功播种吗?
谢谢!
如果您在 Protractor 中使用 Jasmine 2.1 或更高版本,您可以在 beforeAll
.
因此,如果您有一个名为 seedMyDataAsync()
的函数,该函数将回调函数作为参数,您可以执行如下简单的操作:
beforeAll( function(done) {
seedMyDataAsync(done);
});
Jasmine 2.0 引入了 done()
函数,但在 Jasmine 2.1 之前 beforeAll()
不可用。
来自文档:
Calls to beforeAll, afterAll, beforeEach, afterEach, and it can take an optional single argument that should be called when the async work is complete.
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.