What are the methods we can use to wait for an angular site to be loaded in order to test it with protractor?

混江龙づ霸主 提交于 2019-12-08 03:32:54

问题


What are the methods we can use to wait for an Angular site to be loaded in order to test it with protractor in order to avoid this error caused by jasmine : A Jasmine spec timed out. Resetting the WebDriver Control Flow ? I'm able to make the login and go to home page that test is passed, but from the second test i have problems of jasmine.


回答1:


I have configured this problem by adding this function into my config file :

    onPrepare: function() {
      return browser.getProcessedConfig().then(function(config) {
        var browserName = config.capabilities.browserName;
        browser.manage().timeouts().setScriptTimeout(60000);
      });
    });



回答2:


You can use the browser object of Protractor to wait for angular.

As soon as you load your page add the following :

browser.waitForAngular();



回答3:


This error means that your test took too much time and exceeded the default Jasmine spec timeout interval which is 30 seconds by default (It looks like you've configured the timeout to be 60 seconds). It can be configured in the jasmineNodeOpts object in your Protractor config:

jasmineNodeOpts: {defaultTimeoutInterval: timeout_in_millis},

The solution is usually use-case specific and it usually indicates there is an error in the test code. In order to fully understand what is going, we would need to see the code itself.

In your particular case, for starters, you should try moving the "ignore synchronization" and the browser.get() part into the beforeEach. Also, since you are turning the sync off, you need to wait for the element to be present on the page before interacting with it:

describe("my app", function () {
    beforeEach(function () {
        browser.ignoreSynchronization = true;
        browser.get("...");
    });

    it("should make the login test", function () { 
        // ...
        var EC = protractor.ExpectedConditions;
        var username = element(by.model("credentials.username"));
        browser.wait(EC.presenceOf(username), 10000);

        username.sendKeys("RET02");
        // ...
    });
});

And, I am not sure if you really need to turn the synchronization off since this is an AngularJS page you are working with.




回答4:


Can you wait for a url? Let's assume that when you click on the login button your page is redirected to another url. So you can wait for the expected url. Example:

browser.driver.wait(function() {
        return browser.driver.getCurrentUrl().then(function(url) {
            // Dashboard is the loaded url after login (in this example)
            return /Dashboard/.test(url);
        });
    }, 60000);

This code waits for the page browser.baseUrl/Dashboard to be loaded, for 60 seconds



来源:https://stackoverflow.com/questions/37008132/what-are-the-methods-we-can-use-to-wait-for-an-angular-site-to-be-loaded-in-orde

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