The conveyor does not scroll to the control element
While trying to write some protractor tests for ionic, the implemented selector element( by.css('.selector'));
no longer scrolls the element. Which, when not displayed in the browser, automatically fails the test.
Took me a little to figure it out. Using ptor.sleep(2000)
to delay the page after browser.get('domain');
and then if I go through the sections where the items are tested, they go through (as expected).
I believe it has something to do with ionically capturing scroll events.
Has anyone encountered this before or had some sort of scrollTo implementation for all elements?
sample test
"use strict";
/* Tests */
var ptor = protractor.getInstance();
describe( "Register page", function ()
{
browser.get( "#/register" );
ptor.sleep(2000);
it( "Check SMS Preference", function ()
{
var smsLabelConfirm = element( by.css( ".sms-confirm" ) ),
smsLabelDeny = element( by.css( ".sms-deny" ) ),
smsInputConfirm = element ( by.id( "sms-confirm" ) ),
smsInputDeny = element ( by.id( "sms-deny" ) );
smsLabelConfirm.click();
expect( smsInputConfirm.getAttribute( "checked" ) ).toBe( "true" );
expect( smsInputDeny.getAttribute( "checked" ) ).toBe( null );
smsLabelDeny.click();
expect( smsInputConfirm.getAttribute( "checked" ) ).toBe( null );
expect( smsInputDeny.getAttribute( "checked" ) ).toBe( "true" );
} );
});
source to share
Ended up using the answer given here: How to set focus on a section of my webpage, then scroll down
Changed so that the function simply takes an element as an argument for reuse. Seems to work.
var ptor = protractor.getInstance();
var scrollIntoView = function (element) {
arguments[0].scrollIntoView();
};
describe( "Register page", function ()
{
browser.get( "#/register" );
ptor.sleep(2000);
it( "Check SMS Preference", function ()
{
var smsLabelConfirm = element( by.css( ".sms-confirm" ) ),
smsLabelDeny = element( by.css( ".sms-deny" ) ),
smsInputConfirm = element ( by.id( "sms-confirm" ) ),
smsInputDeny = element ( by.id( "sms-deny" ) );
browser.executeScript(scrollIntoView, smsLabelConfirm);
smsLabelConfirm.click();
expect( smsInputConfirm.getAttribute( "checked" ) ).toBe( "true" );
expect( smsInputDeny.getAttribute( "checked" ) ).toBe( null );
smsLabelDeny.click();
expect( smsInputConfirm.getAttribute( "checked" ) ).toBe( null );
expect( smsInputDeny.getAttribute( "checked" ) ).toBe( "true" );
} );
});
source to share