javascript - UnhandledPromiseRejectionWarning:未处理的承诺拒绝。警告在量角器控制台中使用 aync 和等待时不受欢迎
问题描述
我已经使用量角器编写了以下自动化代码。
this.promoteToOperationaltSandboxes3 = async function(){
const allMainPanel = element.all(by.className('tropos-appbox-main-panel col-md-12'));
console.log(typeof allMainPanel);
console.log('In the wait function , number of the main panels is '+allMainPanel.length);
const allLitags = await allMainPanel[0].all(by.className('dropdown-menu ng-scope')).all(by.tagName('li'));
console.log('In the wait function , number of the litags is '+allLitags.length);
}
我在我的一个规范文件中调用这个函数,就像这样。
await appsPage.promoteToOperationaltSandboxes3();
在执行此功能时,即使浏览器没有打开并将错误显示为 ;
消息:TypeError:无法读取未定义的属性“全部”堆栈:TypeError:无法读取未定义的属性“全部”
此外,在日志中,我可以看到消息:
在等待功能中,主面板的数量未定义。
任何人都可以帮助我解决这些问题并帮助我更好地处理承诺。
解决方案
您应该先更改allMainPanel
以获取索引:
const allMainPanel = element.all(by.className('tropos-appbox-main-panel col-md-12')).get(0);
然后allLitags
也可能分成2个单独的变量:
const allLitags = allMainPanel.all(by.className('dropdown-menu ng-scope'));
const liElement = await allLitags.all(by.tagName('li'));
推荐阅读
- azure - 由于订阅密钥无效,访问被拒绝
- asp.net-core - 如何在多个 ASP.NET Core 视图中重用 html 元素?
- azure - Azure devops 上传带有链接测试的错误(id/名称)
- java - 休眠会话保持开放以检索多对一 POJO
- django - Django通用视图,检查请求是否与创建者在同一组中
- android - 如何在适配器中调用片段方法
- c++ - 如何将指针链接到 std::vector 元素
- java - ExecutorService 不休眠
- java - 包含 @ManyToOne 关系的 @Embeddable 类的 JPA criteriaBuilder
- php - 仅使用 fopen() 和 fclose() 清除文件是否安全?