尝试使用sendkeys键入文本时出现错误,或者在弹出的情况下单击按钮,在Mocha中使用typescript promise链接。
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));
});
});
&#34;点击按钮&#34;正在控制台窗口中打印。但之后得到错误如下图所示。 Mocha error in promise chaining
答案 0 :(得分:0)
您似乎期望等待超过设置的超时(120000ms),因此您应该将超时设置为更长的时间。
了解如何操作here: Mocha Timeouts
根据图像,您的超时设置为120000毫秒(2秒)
现在,我现在不知道browser.wait
的工作原理。但根据代码,您似乎期望等待超过120000毫秒:
browser.waitForAngularEnabled
browser.wait
60000ms browser.wait
&#34;点击按钮&#34; 30000ms browser.wait
再次为 30000ms 现在你没有得到&#34;搜索&#34;记录可能是由于在调用composeNewMessage之前等待很长时间。