Search code examples
angularjstestingselenium-webdriverprotractorend-to-end

Error while waiting for the protractor to sync with the page: "Cannot read property 'get' of undefined"


My test target page has SSO integrated login. Once I hit the page, SSO integrated windows authentication will occur then directed to home page.

I tried to turn Sync off and it works for first test to check title but for second test, it will return error unable to locate element and when I turn on Sync, it will return out of sync error and undefined error.

describe('Test area to ', function () {

var menuObjects = require('../page/MenuObjects.js');

it('Verify Page Title', function () {
    menuObjects.setSyncOff(); 
    browser.get('/home/');
    expect(browser.getTitle()).toEqual('Home');
    browser.driver.sleep(3000);
});

it('Navigate ', function () {
    menuObjects.setSyncOn();
    menuObjects.menuButton.click();        
});
});

Error message for Navigate - with menuObjects.setSyncOn();

Error while waiting for Protractor to sync with the page: "Cannot read property 'get' of undefined"

Error message for Navigate - with menuObjects.setSyncOff();

NoSuchElementError: No element found using locator: By.id("menu-link")

ng-app is included in div within body:

<body style="width: 100%">
<div class="frame" style="width: 100%">
    <div class="container-fluid" style="width: 100%">
        <div class="" style="width: 100%">
            <div style="width: 100%">
                <!--_AngularBaseLayout: BEGIN-->                    

<div ng-app="myHomeApp" ng-cloak class="ng-cloak">
     <div ng-view id="ng-view"> </div>
</div>

Any suggestion?


Solution

  • If ng-app is not defined on html or body, you need to let protractor know about it by setting rootElement configuration setting:

    exports.config = {
      seleniumAddress: env.seleniumAddress,
    
      baseUrl: env.baseUrl,
    
      ...
    
      // Selector for the element housing the angular app.
      rootElement: 'div#nested-ng-app'
    };
    

    This would make playing around with switching syncing on and off not necessary - protractor would wait for angular "to settle down" before proceeding to the further test execution.


    If this doesn't help with NoSuchElementError error, you can explicitly wait for the element to become present with the help of presenceOf "Expected Condition":

    var EC = protractor.ExpectedConditions;
    
    var elm = browser.wait(EC.presenceOf($('#menu-link')), 5000);