量角器执行挂起

时间:2017-09-27 10:03:10

标签: angular jasmine protractor

我有以下代码:

it('Should be able to sign in', function() {
    // Find page elements
    var userNameField = browser.findElement(By.id('email'));
    var userPassField = browser.findElement(By.id('password'));
    browser.sleep('1000');
    var userLoginBtn = browser.findElement(By.id('loginbtn'));

    // Fill input fields
    userNameField.sendKeys('abc');
    userPassField.sendKeys('123');

    // Ensure fields contain what we've entered
    expect(userNameField.getAttribute('value')).toEqual('abc');
    expect(userPassField.getAttribute('value')).toEqual('123');

    // Click to sign in
    userLoginBtn.click();
    expect(browser.getCurrentUrl()).toMatch('/user/dashboard');
});

it('Should be able to logout', function () {

    element(by.id('logout')).click();
    expect(browser.getCurrentUrl()).toMatch('/login');
});

问题在于它没有达到第二个'它',但是失败了:

Failed: Timed out waiting for asynchronous Angular tasks to finish after 11 seconds. This may be because the current page is not an Angular application. Please see the FAQ for more details: https://github.com/angular/protractor/blob/master/docs/timeouts.md#waiting-for-angular
While waiting for element with locator - Locator: By(css selector, *[id="logout"])

如果我添加:

browser.waitForAngularEnabled(false);

然后它继续进行最后一次测试并且有效,但这是正确的解决方案吗?

1 个答案:

答案 0 :(得分:0)

是的,你必须禁用angular,因为你使用的是browser.findElement(By.id(' email'));我假设页面没有使用Angular;

如果您需要导航到不使用Angular的页面,可以通过设置`browser.waitForAngularEnabled(false)来关闭等待Angular

Timeouts