问题
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!
回答1:
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.
来源:https://stackoverflow.com/questions/34887086/force-protractor-to-wait-for-seed-data-to-load