Protractor Locator Time Out exception for AngularJs application

自古美人都是妖i 提交于 2019-12-24 08:24:38

问题


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();
    });
});


来源:https://stackoverflow.com/questions/42630602/protractor-locator-time-out-exception-for-angularjs-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!