角量角器中的错误处理
Error Handling in Angular Protractor
我是量角器的新手,用于自动化 angularJs 应用程序。我正在尝试从元素列表中选择一个元素。我正在尝试进行错误处理,但由于承诺,没有任何工作符合我的预期。
在下面的代码中,如果我传递了一个无效的 categoryName,它永远不会打印错误,而是转到验证部分(期望)并失败。
请帮助我理解这一点以及如何解决此问题。我尝试使用回调,但没有运气。我也尝试过捕捉,仍然没有运气。感谢这里的任何帮助。谢谢
this.elements = element.all(by.css('.xyz'));
this.selectCategory = function (categoryName) {
this.elements.each(function (category) {
category.getText().then(function (text) {
if (text === categoryName) {
log.info("Selecting Category");
category.click();
}
}, function (err) {
log.error('error finding category ' + err);
throw err;
});
})
};
使用filter()
并检查匹配的元素数量:
var filteredCategories = this.elements.filter(function (category) {
return category.getText().then(function (text) {
return text === categoryName;
});
});
expect(filteredCategories.count()).toEqual(1);
filteredCategories.first().click();
如果要记录无效案例,可以这样做。
this.selectCategory = function (categoryName) {
var filteredCategories = this.categoryElements.filter(function (category) {
return category.getText().then(function (text) {
return text === categoryName;
})
})
filteredCategories.count().then(logInvalidCategory)
expect(filteredCategories.count()).toEqual(1);
filteredCategories.first().click();
}
function logInvalidCategory(count) {
if(count === 0) {
log.info("Invalid Category");
}
}
相关文章:
- javascript:如何在antlr生成的Lexer中进行错误处理
- 生成pdf或其他非html文件时的错误处理
- sailsjs在创建两个模型时的错误处理
- 为什么没有调用我的流错误处理程序
- 错误处理try&catch+回调
- EventSource中的错误处理
- Angular JS中的通用Ajax错误处理-拦截器
- Sinon Mocha节点错误处理
- 如果文件不存在,fs.watch是否有错误处理程序
- Javascript初始化和错误处理
- AngularJS错误处理:根据错误数组显示错误
- JQuery 图像错误处理
- BreezeJS中央错误处理程序和自动重试
- 文件下载html与错误处理FileNotFound
- 使用mongoose保存多个文档时的错误处理
- Node.js如何知道回调的第一个参数是否是错误处理程序
- Meteor JavaScript-错误处理
- AJAX自定义错误处理代码问题
- 正在获取丢失的错误处理程序套接字消息,无法读取属性'timerID'使用Node.js和Socket.i
- 为什么不't JavaScript库使用错误处理