Wednesday, 29 April 2015

angularjs Protractor


When you do e2e test for angular by Protractor, sometimes you may find protractor can't give you the full accessing of all you html elements, for example, if you want to test scroll bar.


http://stackoverflow.com/questions/26102132/access-window-object-browser-scope-from-protractor

If you want to get a value, you should add "return" at the beginning and use call back:

 browser.executeScript('return document.body.scrollTop').then(function(scrollTop){
       console.log("scrollTop = " + scrollTop);
});

If you want to assert this value, you didn't need : do it in the callback:

expect(browser.executeScript('return document.body.scrollTop')).toEqual(130)

If you want to run a script or multi scripts:

browser.executeScript('document.body.style.height = "100000px"; window.scrollTo(0,document.body.scrollHeight)').then(function(){

}


No comments:

Post a comment