Protractor Locator Time Out exception for AngularJ

2019-07-28 20:15发布

问题:

We are trying to automate a publicly accessible website and click on one of the links, but the test fails with TimeOut Exception while locating the element as below:

From: Task: Protractor.waitForAngular() - Locator: By(link text, MY ACCOUNT) Sample conf and spec file below. Requesting help on how to solve this issue.

conf.js

exports.config = {
                seleniumAddress: 'http://localhost:4444/wd/hub',
                capabilities: {
                                'browserName': 'chrome'
                },             
                specs: ['test.js']
};

test.js

describe('test', function() {

                it('should navigate', function(done) {
                                browser.get('https://ww2.tracfone.com');
                                element(by.linkText('MY ACCOUNT')).click();
                                done();
                });
};

回答1:

Found the root cause for the issue you were seeing for your webPage. Looks like your site continuously polls $timeout or $http, Protractor will wait indefinitely and time out.

I have monitored the http traffic below and see that your app polls at frequent intervals and Protractor just waits. Checkout the screen grab below.(The green marks in the timeline indicating $http calls to - https://ww2.tracfone.com/cgi-bin/tealeaf.pl )

More details on why you are seeing this error is documented here. ok. Coming to the different solutions for this, there are multiple work-arounds for this. I will just talk in brief about the alternatives and leave it to you to choose the best one.

  1. IgnoreSynchronization: Turn this flag - browser.ignoreSynchronization to false before the browser.get() and continue with the test flow and set the flag to true again for other pages Check here

  2. Interval.js : I am no expert on this but you can explore more here

You should use the $interval for anything that polls continuously (introduced in Angular 1.2rc3).

  1. Try with different timeOut configurations and see if your app polling stops after some time

    allScriptsTimeout: 120000, getPageTimeout: 120000, jasmineNodeOpts: { defaultTimeoutInterval: 120000 }



回答2:

I setup a sample project based on the items you've posted and this test appears to be working for me.I'm not sure why you are getting the timeout that is usually associated with pages that are not angular but setting browser.ignoreSynchronization = true helped get past this error.

var ec = protractor.ExpectedConditions;
var timeout = 60000;

describe('test', function() {
    it('should navigate', function(done) {

        browser.ignoreSynchronization = true;
        browser.get('https://ww2.tracfone.com')

        var myAccount = element(by.linkText('MY ACCOUNT'));
        browser.wait(ec.visibilityOf(myAccount)).then(function() {
            myAccount.click();
        })
        done();
    });
});