3

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.

Ben Aston
  • 53,718
  • 65
  • 205
  • 331
  • What is the `get()` method on `ElementFinder` called for? I don't recall this method exists on an `ElementFinder`. Thanks. – alecxe Jun 25 '15 at 14:07
  • This line may be of use? https://github.com/angular/protractor/blob/6ebc4c3f8b557a56e53e0a1622d1b44b59f5bc04/lib/element.js#L247 – Ben Aston Jun 25 '15 at 14:10
  • Yeah, but this is `ElementArrayFinder` (the result of `element.all()`). – alecxe Jun 25 '15 at 14:10
  • Ok, I have update the code to use `element.all`. The omission was an error in converting my actual code to something pared down for this question. – Ben Aston Jun 25 '15 at 14:15

1 Answers1

3
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.

Ben Aston
  • 53,718
  • 65
  • 205
  • 331