Reputation: 243
Hei,
I'm using protractor to run e2e tests, and would like to have something of the sort:
expect(element(by.model('someModel')).getText()).toContain(asyncMethodResult());
I would like to avoid doing:
asyncMethodResult().then(function(result){
expect(element(by.model('someModel').getText()).toContain(result);
});
Also possibly run an async request in a beforeEach which also 'blocks' further execution until done
Is that doable? is something like https://www.npmjs.com/package/wait.for the only way to do so?
[Update] For the sake of answer:
it('test spec', function () {
var expectFn = function (x, t) {
var deferred = Q.defer();
setTimeout(function () {
console.log('Timeout complete:', x, t);
deferred.resolve(x);
}, t);
return deferred.promise;
};
expect(expectFn(3, 1000)).toEqual(expectFn(4, 2000));
}
Passes or fails correctly (depending on x values) if:
browser.manage().timeouts().implicitlyWait(Y); //where Y > promise timeout value
In this case protractor waits for 'Y' millis, then compares the values, otherwise compares always passes.
If the implicitWait is less than the timeout, then it always passes immetiatly
Upvotes: 3
Views: 2183