What are the methods we can use to wait for an ang

2019-05-31 18:31发布

问题:

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