Mocha 中的承诺链接错误

Promise chaining error in Mocha

在 Mocha 中使用 typescript promise 链尝试使用 sendkeys 或单击弹出窗口中的按钮键入文本时出错。

composeNewMessage(mailCount: number, recepientsName: any, subject: string, messageContent: string,
  recipientLink?: ElementFinder, ccName?: any, bccName?: any,
  ccRecipientLink?: ElementFinder, bccRecipientLink?: ElementFinder): promise.Promise<void> {
  return browser.wait(ExpectedConditions.elementToBeClickable(this.listView.composeMsgBtn), 60000, 'Compose button to be clickable')
      .then(() => this.composeMsgBtn.click())
      .then(() => this.toButton.click())
      .then(() => util.log('To button clicked'))
      .then(() => recipientLink.click())
      .then(() => browser.wait(ExpectedConditions.invisibilityOf(this.loadingBar), 30000, 'Loading bar to be invisible'))
      .then(() => this.searchNameInput.sendKeys(recepientsName))
      .then(() => util.log('Search'))
      .then(() => this.contactList.contacts.get(0).click())
      .then(() => browser.wait(ExpectedConditions.elementToBeClickable(this.contactList.saveButton), 30000, 'Save button to be clickable'))
      .then(() => this.contactList.saveButton.click());
}

describe('Logging in', () => {
it('should', (done: MochaDone) => {
      login
        .login(user, name, USER_PASSWORD)
        .then(() => util.log('Logged in.'))
        .then(() => nav.navigate('sat'))
        .then(() => util.log('Navigated to sat.'))
        .then(() => browser.waitForAngularEnabled(true))
        .then(() => composeView.composeNewMessage(3, [predefinedStudent1, predefinedStudent2], 'Test sub', MSG_CONTENT, contactList.studentLinkInRecipients))
        .then(() => composeView.listView.composeMsgBtn.click())
        .then(() => done())
        .catch((err) => done(err));
  });
});

"To button clicked" 正在控制台 window 中打印。但是之后出现如下图所示的错误。 Mocha error in promise chaining

增加测试的超时时间

您似乎希望等待超过设置的超时时间 (120000ms),因此您应该将超时时间设置得更长一些。

阅读操作方法 here: Mocha Timeouts

分析

根据图像,您的超时设置为 120000 毫秒(2 秒)

现在,我不知道 browser.wait 是如何工作的。但是根据代码,您似乎希望等待超过 120000 毫秒:

  1. 在调用 composeNewMessage 之前,您等待 angular browser.waitForAngularEnabled
  2. 然后是第一个 browser.wait 60000ms
  3. browser.wait 在记录 "To button clicked" 30000ms
  4. 后再次
  5. browser.wait 又一次 30000ms

现在您没有 "search" 登录的原因可能是在调用 composeNewMessage 之前等待了很长时间。