0

I am currently developing a set of tests using Protractor to test an AngularJS app that my company are developing. When I currently run through my tests, I am getting a failure on one of them, but can't figure out why... The error message says:

A Jasmine spec timed out. Resetting the WebDriver Control Flow.

The error message is shown at the end of the execution of the first of the following two test scripts, and the next thing to be shown in the console is the console.log() statement from the start of the second test:

it('should navigate to the Charts page', function() {
    console.log("Start Charts page test");
    browser.waitForAngularEnabled(false);
    browser.actions().mouseMove(chartsMenuBtn).perform();
    chartsMenuBtn.click();
    browser.waitForAngularEnabled(true);
    browser.call(closeDlg);
    expect(browser.getCurrentUrl()).toBe(VM + '/#/charts');
});

/*Test that 'Export' menu item works correctly */
it('should navigate to the Export page', function() {
    console.log("Start Export page test");
    browser.waitForAngularEnabled(true); //false);
    browser.actions().mouseMove(exportMenuBtn).perform();
    exportMenuBtn.click().then(function(){
        console.log("End Export page test (then call)");
        expect(browser.getCurrentUrl()).toBe(VM + '/#/export');

    });
    console.log("End Export page test");
});

Inside the first of these two test scripts, I am calling the function closeDlg() using the line: browser.call(closeDlg);- this function is defined in the same spec.js file as where these tests are written with:

function closeDlg(){
    browser.waitForAngularEnabled(false);
    console.log("closeDlg() function called ")
    var EC = protractor.ExpectedConditions;
    var chartConfigForm = element(by.className('class="ui-tab-container ui-tab-vertical'));
    var closeDlgBtn = element(by.buttonText('Cancel'));
    browser.call(function(){
        console.log("About to click closeDlgBtn ");
    });

    closeDlgBtn.click();

    browser.call(function(){
        console.log("just clicked closeDlgBtn ");
    });
    browser.call(function(){
        console.log("End of closeDlg() function ");
    });
}

and all of the console.log() statements from this function are displayed in the console, indicating that all of the code inside this function executes as expected.

This appear to suggest that the timeout is occurring on the expect(browser.getCurrentUrl()).toBe(VM + '/#/charts'); line, but I can see in the browser where the test scripts are being run that this is the current URL at the time that this line is executed.

After the line

End of closeDlg() function

is printed to the console from the closeDlg() function, that's when the timeout happens, which suggests that it's the line:

        expect(browser.getCurrentUrl()).toBe(VM + '/#/charts');

that's causing the script to timeout, since that is the next line that will be executed.

I have tried setting browser.waitforAngularEnabled(true); & browser.waitForAngularEnabled(false); in various places within the test script, but nothing seems to have resolved or made a difference to the timeout error at all.

Does anyone have any suggestions why I'm getting this? How can I fix it?

Noble-Surfer
  • 3,052
  • 11
  • 73
  • 118
  • 1
    Ok... This is almost the same question as [this one from you from last Friday](https://stackoverflow.com/questions/46973496/angularjs-testing-with-protractor-executing-asynchronous-scripts). Randomly switching on/off WaitForAngularEnabled() doesn't make sense at all... either your page is AngularJS and works with it, or it's not. Also the use of `browser.call()`, `console` and `.then()` looks like you never went through any tutorial of Protractor or JavaScript. From my point of view the way you handle the ControlFlow in your test leads to almost unpredictable results. Tip: Tutorials first! – Ernst Zwingli Nov 01 '17 at 10:52
  • Thanks for your comment. I thought that this was a different problem due to the fact that I had fixed that last one. However, looking through my tests, it seems that the issue this time was caused by the line: `browser.waitForAngularEnabled(true);` in the `Export page` test. Switching this to `false` got the test passing. – Noble-Surfer Nov 01 '17 at 11:35
  • 1
    I'm glad it worked for you and I'm confused, that less than 1 hour after posting you found your own solution (first try, then post). Also check my suggested code. It's much slimmer less complex and far more stable. What I'd like to say is, that your kind of fixes will just lead to the next problem a few lines later... because you let protractor randomly synchronizd with the page it's just a matter of a few more lines until it's out of sync again and you're going to post a new question. – Ernst Zwingli Nov 01 '17 at 11:42
  • This is actually the 3rd or 4th time he's posted the exact same question with the exact same code, he asked [here](https://stackoverflow.com/questions/46950444/jasmine-spec-timed-out-while-waiting-for-ec-visibilityof-a-form-unhandled-prom) and [also here](https://stackoverflow.com/questions/46914497/angularjs-testing-using-protractor-how-to-close-a-dialog-that-opens-automatical) – Gunderson Nov 01 '17 at 13:08

2 Answers2

2

You should check YouTube for some Protractor Tutorials as they introduce nicely the meaning of Promises and how Protractor works.

Further check these answers here to learn about some Protractor specific issues:

After all here my suggestion to your code:

beforeAll(function(done){
    browser.waitForAngularEnabled(false); //in case it doesn't work without this line.
    var EC = protractor.ExpectedConditions;
});

it('should navigate to the Charts page', function(done) {
    // var chartsMenuBtn = ?? //this button-definition is missing in your example.
    var closeDlgBtn = element(by.buttonText('Cancel'));
    chartsMenuBtn.click();
    //browser.wait(EC.visibilityOf(closeDlgBtn),5000); //try first without, but it might be needed.
    closeDlgBtn.click(); //no call to a function. Just click the button.
    expect(browser.getCurrentUrl()).toBe(VM + '/#/charts');
    done();
});

/*Test that 'Export' menu item works correctly */
it('should navigate to the Export page', function(done) {
    // var exportMenuBtn = ?? //this button-definition is missing in your example.
    exportMenuBtn.click();
    //browser.waitForAngular(); //a help-line, if you need to tell Protractor, that he must wait for all promises to be resolved first.
    expect(browser.getCurrentUrl()).toBe(VM + '/#/export');
    done();
});
Ernst Zwingli
  • 1,402
  • 1
  • 8
  • 24
0

The issue here was actually caused by the second test- the line:

browser.waitForAngularEnabled(true);

should have been:

browser.waitForAngularEnabled(false);

inside the Export page test. Once I changed this, the timeout issue was resolved, and my test script passed as expected.

Noble-Surfer
  • 3,052
  • 11
  • 73
  • 118