Home:ALL Converter>Protractor tests won't run on Angular 4 site without waitForAngularEnabled(false)

Protractor tests won't run on Angular 4 site without waitForAngularEnabled(false)

Ask Time:2019-03-12T01:30:04         Author:Arshad Muhammed

Json Formatter

I have a website under test which is built with Angular 4.

My protractor tests won't run on them unless I specify waitForAngularEnabled(false) or ignoreSynchronization = true.

I have verified with the developer and the tech lead that the site is fully Angular.

Developer said that even though the site is developed with Angular, to the browser it is sent as a 'bundle'. (I am not sure what it means in dev terms).

Below is my spec file:

 describe('****** Home Page Tests', function() {
        var frontpage = require("./Front_page.js");

        beforeEach(function() {
            browser.waitForAngularEnabled(true)
            browser.get('mytesturl',50000);
            frontpage.Front_page_link.click()

        })

        it('Should go to **** page', function(){

            frontpage.Journey_button.click()
            browser.getCurrentUrl().then(function(url){
                expect(url).toContain('journey/get-started')
            })
        })

    });

Below is my config file:

    var Jasmine2HtmlReporter = require('protractor-jasmine2-html-reporter');


exports.config = {
    seleniumAddress : 'http://localhost:4444/wd/hub',
    restartBrowserBetweenTests: false,
    //framework: 'jasmine2',

    specs : [ 'spec.js' ],

    onPrepare : function() {

        browser.driver.manage().window().maximize()
        jasmine.getEnv().addReporter(new Jasmine2HtmlReporter({
            savePath : 'target/screenshots'
        }));
    },

    allScriptsTimeout : 50000,


    jasmineNodeOpts : {
        showColors : true,
        defaultTimeoutInterval : 100000,
        isVerbose : true
    }

};

This is the error I get:

Failed: script timeout: result was not received in 50 seconds

Author:Arshad Muhammed,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/55107347/protractor-tests-wont-run-on-angular-4-site-without-waitforangularenabledfalse
ganqqwerty :

Any action on an element selected by By.css or $ or $$ or whatever causes protractor to first wait for angular to stabilize by calling the waitForAngular function. What does it mean to 'wait for angular to stabilize'? \n\nThis function is waiting for all pending http-queries and all unfinished timeouts and doesn't allow the script to proceed further if they are found. \n\nSo basically most of the time you can just user browser.sleep(3000) most of the times, because the majority of timeouts happen in animations and such, and most of http-queries will be finished after 3 seconds. \n\nHowever sometimes the timeouts will not be finished in 3 seconds: such as in cases of long polling or some features implementd using super-long timeouts. In our application we had the auto-logout feature implemented. After login, the service would check the expiration date of the JWT token and wait for (ExpirationDate-CurrentDate) before logging the user out. As you can imagine, it was a huge timeout, 36-hours timeout! After we removed it, everything worked like a charm. \n\nDon't do that, implement these features differently. Search for all occurences of setTimeout, setInterval, timeout, interval in your code and deal with them. ",
2019-05-22T07:13:31
yy