3

I have to test a flow where angular must do a hard redirect to bitly before resuming testing of the page that is returned.

This causes the UnknownError: javascript error: document unloaded while waiting for result error that is much discussed on the web.

However, I cannot find a workaround. The problem occurs between these two lines:

    element(by.id('signup-btn')).click();
    expect(element(by.id('accept-btn')).isDisplayed()).toBeTruthy();

The first line submits a form that results in a hard redirect (as in $window.location.href='/something') back the web app to a page that is tested by the second line. But the redirect borks projector.js.

Is there a way to do this?

metalaureate
  • 7,572
  • 9
  • 54
  • 93
  • Can you wait for the redirect to complete, then `protractor.waitForAngular()` before invoking the `expect`? (I think this will keep the element lookup from tripping over the totally non-angular page.) – P.T. May 01 '15 at 00:59
  • 1
    Have you looked at their example config with handling non-angular pages (I would treat the step above as if angular didn't exist)? I use this to handle a non-angular login page that does also do a redirect. Note it has to be in the onPrepare: https://github.com/angular/protractor/blob/master/spec/withLoginConf.js – cerd May 01 '15 at 04:33
  • My problem is that the 'signup' process includes a number of asynchronous steps handled by a service, which angular misconstrues as completed half way through. One workaround is to skip these redirects when the user is a test account, and use my protractor script to do the redirect using browser.get(), because protractor knows where that redirect should go because it is generated by its dummy data. – metalaureate May 01 '15 at 13:26
  • 2
    Waiting for url to be changed may also help here (http://stackoverflow.com/a/29398054/771848). – alecxe May 01 '15 at 17:35

1 Answers1

0

Instead of asserting with expect you can use the wait functionality

First declare a module that defines your global max time like this.

var Transitions = function(){};

//Sleep function to counter the custom animation  that has been addes

Transitions.prototype.maxTimeToLook = 30000;

exports.Transitions = new Transitions();

This will be the max timeout that protractor will look for an element. Then you can use a expected conditions function like this instead of expect

    browser.wait(protractor.ExpectedConditions.presenceOf(element(by.id('accept-btn'))), sync.maxTimeToLook);

The problem that you are facing is because you are using expect when you click on to the button the expect condition checks for element to be rendered on the page. One workaround that works in my tests is that you use presence of

AS per the API docs https://angular.github.io/protractor/#/api?view=ExpectedConditions.prototype.stalenessOf

ExpectedConditions.prototype.presenceOf

An expectation for checking that an element is present 
on the DOM of a page. This does not necessarily mean that 
the element is visible.

If presence of doesn't work. Maybe you can use other expected condition methods mentioned here

https://angular.github.io/protractor/#/api?view=ExpectedConditions

SandyRocks
  • 269
  • 4
  • 15