Reputation: 133
I am new to the angular/protractor world so this is a really basic question. According to this spec, we can write protractor test for a web element like below:
var foo = element(by.id('foo'));
expect(foo.getText()).toEqual('Inner text');
However, foo.getText() returns a promise type, not a string, how can 'expect' compare that returned promise object against another string? Is there any documentation that explains this usage?
Upvotes: 1
Views: 363
Reputation: 474271
Yes, the expect()
, if used with Protractor
, understands promises - it would resolve a promise before making an expectation making writing Protractor tests easier. This is actually done in a separate project which Protractor
depends on - jasminewd2
which patches jasmine's expect()
to resolve the promises and wraps jasmine's describe()
, it()
and other test control block functions to be executed inside the Control Flow.
Note that, it also supports promises on both sides of the assertion, you can do, for instance:
let elementText1 = $('.ng-scope p').getText();
let elementText2 = $('#transformedtext>h4').getText();
expect(elementText1).toEqual(elementText2);
As far as Protractor
documentation goes, this is partially described here.
Upvotes: 4