protractorJS chai - 如何使用 getText() 断言数组中元素的文本包含字符串?
protractorJS chai - How do i use getText() to assert the text of elements within an array contains a string?
尝试针对在元素数组中找到的文本进行断言时返回错误
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"]'));
}
这就是我尝试检查网络元素数组中文本的方式
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
returns ElementArrayFinder
.
如果应用程序可能 return 只有一个元素匹配 css 选择器,请将您的方法更改为:
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);
尝试针对在元素数组中找到的文本进行断言时返回错误
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"]'));
}
这就是我尝试检查网络元素数组中文本的方式
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
returns ElementArrayFinder
.
如果应用程序可能 return 只有一个元素匹配 css 选择器,请将您的方法更改为:
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);