量角器:点击后如何正确等待?

Protractor: How to properly wait after a click?

我正在使用 Protractor 进行端到端测试。测试应该首先输入太短的用户名和密码,并且由于 Angular 验证器在单击提交按钮(已禁用)时被拒绝并保持不变(这有效!),然后它应该输入正确长度的用户名还有一个正确长度的密码,点击提交按钮并且不会被重定向,因为它是一个错误的登录。这失败了...最后一个测试需要输入正确的登录详细信息并单击提交,应该会重定向到仪表板。 根据这个答案 就可以解决我似乎抛出

的问题
- Failed: script timeout
    (Session info: chrome=79.0.3945.130)
    (Driver info: chromedriver=79.0.3945.16 (93fcc21110c10dbbd49bbff8f472335360e31d05-refs/branch-heads/3945@{#262}),platform=Windows NT 10.0.18362 x86_64)```

我的两个测试都出错。 我该如何解决? 我的测试是这样写的:

it('should enter too short username and password and NOT get redirected => stay put', () => {
   element(by.css('#inputUser')).sendKeys('bah');
   element(by.css('#inputPassword')).sendKeys('bah');
   const btn = element(by.css('#loginSubmit'));
   btn.click();
   const curUrl = browser.getCurrentUrl();
   expect(curUrl).toBe('http://localhost:4200/avior/login');
 });

  it('should enter incorrect username and password and NOT get redirected => stay put', () => {
    const ele1 = element(by.css('#inputUser'));
    const ele2 = element(by.css('#inputPassword'));
    const btn = element(by.css('#loginSubmit'));
    ele1.clear();
    ele2.clear();
    ele1.sendKeys('bah');
    ele2.sendKeys('bahbahbah');
    btn.click();
    browser.waitForAngular();
    const curUrl = browser.getCurrentUrl();
    expect(curUrl).toBe('http://localhost:4200/avior/login');
  });

  it('should enter correct username and password and get redirected to /avior/dashboard', () => {
    const ele1 = element(by.css('#inputUser'));
    const ele2 = element(by.css('#inputPassword'));
    const btn = element(by.css('#loginSubmit'));
    ele1.clear();
    ele2.clear();
    ele1.sendKeys('Chad');
    ele2.sendKeys('chadchad');
    btn.click();
    browser.waitForAngular();
    const curUrl = browser.getCurrentUrl();
    expect(curUrl).toBe('http://localhost:4200/avior/dashboard');
  });

更新 jwt 令牌作为 cookie 发送作为响应,这可能是问题的一部分。我似乎无法在网上找到有关如何使用 Protractor 处理 cookie 的信息..

在量角器中等待

等待元素出现

this.waitForElementPresent = function (element) {
    return browser.wait(() => (element.isPresent()), 30000);
}

等待元素显示

 this.waitForElementDisplayed = function (element) {
    return browser.wait(() => (element.isDisplayed()), 30000);
}

睡眠条件

this.sleep = function (sec) {
    browser.sleep(sec * 1000);
}

预期条件

this.waitForElementVisibility = function () {
    let EC = ExpectedConditions;
    return browser.wait(EC.visibilityOf(), 30000);
}

根据这个问题 在按钮点击之前添加 browser.waitForAngularEnabled(false); 似乎已经解决了错误..