protractorJS chai - How do i use getText() to assert the text of elements within an array contains a string?
当尝试对元素数组中找到的文本进行断言时,我收到返回错误
1 | AssertionError: expected [ Array(1) ] to include 'This profile exists already and has two places.' |
我在页面对象文件中声明了webelement引用
我创建了一个包含一些代码的步骤,以验证元素数组中的文本
这是在页面对象中声明的webelement引用:
1 2 3 | get importErrorsList(){ return element.all(by.css('[ng-if="error.error.detailMessage"]')); } |
这是我尝试检查Web元素数组中的文本的方式
1 2 3 4 5 | directoriesPageObj.importErrorsList.getText().then(function(text) { console.log('test console output: ' + text); expect(text).to.contain(errorText); callback(); }); |
实际:我得到断言错误
预期:
测试通过。
请注意,在该步骤的代码中,我有一个
这最??终对我有用:
如果应用程序可能仅返回与css selecror匹配的一个元素,则将您的方法更改为:
1 2 3 | get importErrorsList(){ return element.all(by.css('[ng-if="error.error.detailMessage"]')); } |
但是如果您适合