Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.

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 ?

share|improve this question
    
Did you get an answer for this issue? –  Girish Sortur Aug 29 at 7:27
    
Nope not yet, I was on a short break, so I am going to resume working on this... –  AKFourSeven Sep 2 at 8:58

2 Answers 2

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.

share|improve this answer
    
The ingoreSynchronization bit is already included in the conf, as you can see above, removing driverfrom 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 at 12:46
    
Hoping that your website is non-angular, did you try removing the waitForAngular() function and see if it fixes? –  Girish Sortur Aug 28 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 at 13:38
    
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? –  Girish Sortur Aug 28 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 2 at 8:39

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(); 
  });
});
share|improve this answer
    
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 at 12:43
    
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 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 at 14:46
    
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 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 2 at 8:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.