gpt4 book ai didi

protractor - 如何检查是否在 Protractor 的列中找到文本

转载 作者:行者123 更新时间:2023-12-04 17:09:27 27 4
gpt4 key购买 nike

我试图断言名称显示在表的列中。我写了一个 inResults将遍历列的文本以查看名称是否存在的函数。这是我正在尝试的:

页面对象:

this.names = element.all(by.repeater('row in rows').column('{{row}}'));

this.inResults = function(nameString) {
var foundit = '';
this.names.each(function(name) {
name.getText().then(function(it) {
console.log(it); // each name IS printed...
if(it == nameString) {
console.log('it\'s TRUE!!!!'); // this gets printed...

foundit = true;
}
});
});
return foundit; // returns '' but should be true?
};

规范期望:
expect(friendPage.inResults('Jo')).toBeTruthy();

两个控制台语句都按预期打印......但我的期望失败为 foundit的值仍然是 '' .我已经尝试了多种方法,但都没有奏效。我错过了什么?

最佳答案

我已经设计出我认为更好/更清洁的方法来解决这个问题。它不那么复杂,并且在方法中不需要定位器/css 代码。

friend .page.js

// locator
this.friendName = function(text) { return element.all(by.cssContainingText('td.ng-binding', text)) };

// method
this.inResults = function(name) {
return this.friendName(name).then(function(found) {
return found.length > 0;
});
};

friend .spec.js
expect(friendPage.inResults('Jo')).toBeTruthy();

我已将此添加到我的 protractor_example project on GitHub ...

关于protractor - 如何检查是否在 Protractor 的列中找到文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25826067/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com