Can someone help me understand how WebDriverJS/Protractor works in this case?
function MyPageObject(buttonElementFinder) {
this.getButtonByIndex = function(index) {
return {
myButton: buttonElementFinder.get(index)
}
}
}
1. describe('My button', function() {
2.
3. it('should contain the text foo', function() {
4. var myElementFinder = element.all(by.css('.foo'));
5. var pageObject = new MyPageObject(myElementFinder);
6. var button = pageObject.getButtonByIndex(0);
7. expect(button.text()).toBe('foo');
8. });
9.
10. });
Does the WebDriverJS control flow have an action added to it on line 6 because of the .get method of ElementFinders?
I presume the expect also adds another item to the control flow too on line 7?
Edit: I have update the code to use element.all.
var myElementFinder = element.all(by.css('.foo'));
myElementFinder is a ElementArrayFinder and is simply an object. Nothing async is happening here.
var pageObject = new MyPageObject(myElementFinder);
Obvious.
var button = pageObject.getButtonByIndex(0);
This will return an ElementFinder from buttonElementFinder.get. Nothing async is happening here.
expect(button.text()).toBe('foo');
button.text() returns a promise from Webdriver.schedule, which in turn is using the control flow which is retrieved using webdriver.promise.controlFlow(), which exposes an execute function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With