3

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?

user2388556
  • 287
  • 1
  • 7
  • 17
  • Where is the element that is supposed to have the id `menu-link`? Assuming your menuObjects.setSyncOn is toggling `browser.ignoreSynchronization`, try accessing webdriver directly while it is off via `browser.driver.get`. – Aaron Apr 28 '15 at 15:50
  • Yes, I was setting ignoreSynchronization true false. id `menu-link` is located at 11th div tag from body. – user2388556 Apr 29 '15 at 00:18

1 Answers1

2

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);
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • Thanks @alecxe. Getting close. I did found post with rootElement and tried it but for some reason, it didn't work and now, seems to be working when I put it below baseUrl. In my current Navigate Test, I have updated below code and seems to be clicking but protractor is still reporting element not visible `browser.waitForAngular();` `var EC = protractor.ExpectedConditions;` `browser.wait(EC.presenceOf($('#menu-link')), 5000);` `menuObjects.menuButton.click().then(function() {` `menuObjects.firstButton.click(); ` `});` – user2388556 Apr 29 '15 at 01:38
  • Btw, I've added rootElement: 'div#nested-ng-app' and still using syncing off. Otherwise, sync page error will still appear. – user2388556 Apr 29 '15 at 01:44
  • looks like issue is definitely with rootElement, I also tried this [solution](http://stackoverflow.com/questions/20059943/running-into-error-while-waiting-for-protractor-to-sync-with-the-page-with-basic) but doesn't seems to be working :( – user2388556 Apr 29 '15 at 03:10
  • @user2388556 thanks, `div#nested-ng-app` was an example locator, you need to use your own locator to get to the element where `ng-app` is defined. – alecxe Apr 29 '15 at 10:44
  • Yeah, I did try following `div#nested-myHomeApp`, `div#nested-ng-cloak`, `.ng-cloak`, `#ng-cloak` and `div#ng-cloak` but for some reason, I still need to set sync off :( – user2388556 Apr 30 '15 at 01:13
  • Ok, issue resolved now. Issue with locator and I have updated [ng-app] for rootElement to locate attribute and works perfectly fine now. Sync on off were taken and no issue with windows integrated authentication as well. Thanks again for your help! @alecxe – user2388556 Apr 30 '15 at 02:03