尝试断言元素数组中找到的文本时返回错误
AssertionError: expected [ Array(1) ] to include 'This profile exists already and has two places.'
我在页面对象文件中声明了 Webelement 引用
我创建了一个步骤,其中包含一些代码来验证元素数组中的文本
这是在页面对象中声明的 webelement 引用:
get importErrorsList(){
return element.all(by.css('[ng-if="error.error.detailMessage"]'));
}
这就是我尝试检查 Web 元素数组中的文本的方式
directoriesPageObj.importErrorsList.getText().then(function(text) {
console.log('test console output: ' + text);
expect(text).to.contain(errorText);
callback();
});
实际:我收到断言错误
预期:测试通过。
请注意,在步骤的代码中,我有一个console.log
片段,它输出一个字符串,其中包含搜索以下内容的字符串:测试控制台输出:com.reputation.imex.imp.ImportException:此配置文件已存在,并且有两个位置。此配置文件不支持使用 CSV 导入
importErrorsList
返回ElementArrayFinder
。
如果应用程序可能只返回一个与 css selecror 匹配的元素,请将您的方法更改为:
get importErrorsList(){
return element.all(by.css('[ng-if="error.error.detailMessage"]'));
}
但是,如果您可以ElementArrayFinder
将expect
更改为:
expect(text).to.deep.contain(errorText);
这是最终对我有用的:
expect(directoriesPageObj.importErrorsList.getText()).to.eventually.contain(errorText).and.notify(callback);