0

Hi I am working on an app that has a non-angular interface and new modules with angular on it. It is in a transition phase. I was trying to use protractor for my tests, but some require to be logged and the login page is in PHP. I already knew that something was to be done to test a non-angular page which I did in my conf:

  exports.config =  {
    specs: ['app/**/*.e2e.js'],
    baseUrl: 'http://localhost:8099/ma#',
    maxSessions: 1,
    framework: 'jasmine2',
    // rootElement: 'myApp',
    multiCapabilities: [
      {
        browserName: 'chrome',
        chromeOptions: {
            args: [
                '--disable-cache',
                '--disable-application-cache',
                '--disable-offline-load-stale-cache',
                '--disk-cache-size=0',
                '--v8-cache-options=off'
            ]
        }
      }
    ],
    jasmineNodeOpts: {
      isVerbose: false,
      showColors: true,
      includeStackTrace: true,
      defaultTimeoutInterval: 50000
    },
    // getPageTimeout: 500000,
    onPrepare: function () {
      browser.driver.ignoreSynchronization = true;

      browser.driver.wait(browser.driver.get('http://localhost:8099/Authentication.php'));
      browser.driver.sleep(1000);
      browser.driver.findElement(by.id('input_login')).sendKeys('login');
      browser.driver.findElement(by.id('input_password')).sendKeys('pass');
      browser.driver.findElement(by.id('submit_button')).click();
      return browser.wait(function(){
        browser.get('/ma#/99/page/');
        browser.waitForAngular();
      }, 1000);
    }
  };

Then in my test I do the following:

describe('Test Spec', function () {
  it('should get the correct title', function () {
expect(browser.getCurrentUrl()).toBe('http://localhost:8099/ma#/99/page/');
  });

});

But all I get are various errors to do with timeouts such as:

Error: Error: Wait timed out after 14074ms

or

 Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.

or the infamous

Uncaught exception: Error while waiting for Protractor to sync with the page: "angular could not be found on the window"

I am lost here, can anybody enlighten me ?

AKFourSeven
  • 1,305
  • 3
  • 18
  • 31

2 Answers2

1

Since there are some async executions involved, you need to use jasmine's async callback as follows:

describe('Test Spec', function () {
  it('should get the correct title', function (done) {
    expect(browser.getCurrentUrl()).toBe('http://localhost:8099/ma#/99/page/');
    // this is the callback, use it in a proper place when all validations are done/complete
    // usually you call it inside another callback from other async execution i.e. ajax request
    done(); 
  });
});
leo.fcx
  • 6,137
  • 2
  • 21
  • 37
  • it did not work, I am still getting timeouts and it also seems like the webdrive is reloading the page many times (the display is flickering)... Thanks anyway... – AKFourSeven Aug 28 '15 at 12:43
  • 1
    As I stated in the inline comments, `done()` should be used in a place where you think everything in the test is done ... for instance, a combination between @Girish Sortur solution and mine might work. – leo.fcx Aug 28 '15 at 14:03
  • Yes, I did combined both at the time I gave you that answer and it was not succesful, I'll try to keep on trying vairous things in those areas, it already helps to have new things to try. – AKFourSeven Aug 28 '15 at 14:46
  • 1
    If you provide more code from your `spec` file? It would help ... note that async callback could also be used in beforeEach calls too – leo.fcx Aug 28 '15 at 14:50
  • That is actually the complete code of my spec, there isn't much more apart from additional tests but seeing as even the first one does not work I found it useless to include them... I am not sure as to how the async callback would look with a before each, I'd call `browser.getCurrentUrl()` and then store it and reuse it in the tests, is that what you meant ? – AKFourSeven Sep 02 '15 at 08:42
0

If its a non-angular page you are testing then you should be removing the waitForAngular() function from your conf file. If you are testing a hybrid angular+non-angular page then use below line to avoid waiting for angular in your non-angular tests only and to avoid declaring it globally -

browser.ignoreSynchronization = true;

To resolve Async callback issues, increase your wait time so that protractor waits until its request returns back in the form of promise like this

return browser.wait(function(){
    browser.get('/ma#/99/page/');
}, 20000); //increase time limit here to increase wait time

Hope this helps.

Community
  • 1
  • 1
giri-sh
  • 6,934
  • 2
  • 25
  • 50
  • The `ingoreSynchronization` bit is already included in the conf, as you can see above, removing `driver`from it did not get me anywhere, and the waiting time was at 20000 previously but it did not changed anything, I still get the same result... Could there be a library that is breaking the flow of protractor ? – AKFourSeven Aug 28 '15 at 12:46
  • 1
    Hoping that your website is non-angular, did you try removing the `waitForAngular()` function and see if it fixes? – giri-sh Aug 28 '15 at 13:11
  • Yep it was crashing when I get to the angular pages, because protractor needs to wait for angular on those page (that's my personal guess) – AKFourSeven Aug 28 '15 at 13:38
  • 1
    So you have a combination of angular and non-angular pages and you are verifying it in the same test? or is it that angular is in one page and non-angular in the other? – giri-sh Aug 28 '15 at 13:43
  • I have non-angular login page and then I access an angular page where I have new modules. So I need to login first to be able to complete some of my tests. – AKFourSeven Sep 02 '15 at 08:39