Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Test for scrolling

In my angular application, I have a page that has nav links on the side, that, when clicked, scrolls the page down to a matching element.

How do I write e2e test for this in protractor? Is there something like "Grab the first visible h1" or something like that?

like image 347
bioball Avatar asked Jun 10 '14 22:06

bioball


1 Answers

You can use javascript's window.pageYOffset for this. Here's how I've done it in one of my own test case:

    browser.driver.sleep(2000);
    browser.executeScript('return window.pageYOffset;').then(function(pos) {
        expect(pos).to.be.at.most(100);
    });

Where 100 is my expected position.

Note: I'm using mocha and chai instead of jasmine. So, just change the last line accordingly. Also I'm waiting 2 seconds for my scrolling to complete.

like image 145
Priyanshu Chauhan Avatar answered Sep 28 '22 05:09

Priyanshu Chauhan