Force protractor to wait for seed data to load
Asked Answered
U

1

2

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.

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.

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.

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

Thanks!

Unknow answered 19/1, 2016 at 21:18 Comment(1)
If you need your seed data before anything happens (launching any tests), just do a sync xhr (instead of async I asume).Westwardly
C
3

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

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

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

From the documentation:

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.

Cofsky answered 20/1, 2016 at 5:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.