I'm trying to get the x and y values for an element on the page while running my Protractor test.
it('should keep the left nav links floating along with the page', function() {
var navDiv = element(by.id('pd_page_nav'));
var initTop = navDiv.getLocation().y;
var initLeft = navDiv.getLocation().x;
browser.get("en-us/learn#dpacreditresource");
var currTop = navDiv.getLocation().y;
var currLeft = navDiv.getLocation().x;
expect(initLeft).toBe('');
expect(initTop).toBe('');
expect(currLeft).toBe(initLeft);
expect(currTop).toBeGreaterThan(initTop);
});
I'm getting errors like 'Expected undefined to be ''.' What am I missing?
Apparently, getLocation() returns a promise, so the proper way to write the call is as below.
it('should keep the left nav links floating along with the page', function () {
var initTop = 0;
var initLeft = 0;
element(by.id('pd_page_nav')).getLocation().then(function (navDivLocation) {
initTop = navDivLocation.y;
initLeft = navDivLocation.x;
browser.get("en-us/learn#dpacreditresource");
element(by.id('pd_page_nav')).getLocation().then(function (navDivLocation2) {
var currTop = navDivLocation2.y;
var currLeft = navDivLocation2.x;
expect(currLeft).toBe(initLeft);
expect(currTop).toBeGreaterThan(initTop);
});
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With