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 ?

2
  • Did you get an answer for this issue? Commented Aug 29, 2015 at 7:27
  • Nope not yet, I was on a short break, so I am going to resume working on this... Commented Sep 2, 2015 at 8:58

2 Answers 2

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(); 
  });
});
Sign up to request clarification or add additional context in comments.

5 Comments

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...
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.
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.
If you provide more code from your spec file? It would help ... note that async callback could also be used in beforeEach calls too
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 ?
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.

5 Comments

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 ?
Hoping that your website is non-angular, did you try removing the waitForAngular() function and see if it fixes?
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)
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?
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.