Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding Protractor and WebDriverJS control flow

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.

like image 770
Ben Aston Avatar asked May 16 '26 20:05

Ben Aston


1 Answers

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.

like image 80
Ben Aston Avatar answered May 18 '26 10:05

Ben Aston



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!