Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I access the document or window objects from within a protractor test?

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!

like image 683
Iain Duncan Avatar asked Oct 31 '14 01:10

Iain Duncan


2 Answers

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 );
    });
like image 62
Iain Duncan Avatar answered Oct 08 '22 07:10

Iain Duncan


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

like image 42
Andres D Avatar answered Oct 08 '22 07:10

Andres D