9

Maybe this isn't possible, I don't really understand how node works yet. I'd like to be able to run an assertion on the document object after a page has been fetched in protractor. Is such a thing possible, and if so how?

thanks!

Iain Duncan
  • 1,738
  • 16
  • 17

2 Answers2

15

Ok, found the answer, so am answering my own question for others:

You can execute javascript using browser.executeScript and then use the return value in your promise resolution, like so:

browser.executeScript('return document._config').then( function(_config){
        expect( _config.epid ).toBe( 1 );
    });
Iain Duncan
  • 1,738
  • 16
  • 17
4

The feature you are looking for is called executeScript or executeAsyncScript. They will help you execute an arbitrary piece of javascript in the browser.

Take a look at these links: http://angular.github.io/protractor/#/api?view=webdriver.WebDriver.prototype.executeScript http://angular.github.io/protractor/#/api?view=webdriver.WebDriver.prototype.executeAsyncScript

Andres D
  • 8,910
  • 2
  • 26
  • 31