Protractor- ElementFinder返回意外值

时间:2016-05-05 09:43:34

标签: protractor

我正在编写一个量角器测试用例来比较显示数据的名称与搜索到的名称相同。

即使我的测试用例工作正常,我也无法理解发生了什么。因为当我希望比较名称时,它会按预期进行比较,但是当我在console.log中打印elementFinder的(rowData)(i have attached the output screen shot here)值时,它会显示一些我无法理解的值的巨大列表?

PS:我是量角器的新手。

This is the testCase:

it('should show proper data for given last name', function () {
            var searchValue='manning';
            searchBox.sendKeys(searchValue);
            search.click();
            element.all(by.binding('row.loanNumber')).count().then(function(value) {
                var loanCount = value;
                for (var i = 0; i < loanCount; i++) {
                    var rowData = element.all(by.binding('row.borrowerName')).get(i).getText();
                    expect(rowData).toMatch(searchValue.toUpperCase()); 
                    console.log(rowData,'*****',searchValue.toUpperCase());
                    
                }
            });
        });`

并就我的代码风格提出宝贵的建议

1 个答案:

答案 0 :(得分:2)

rowData是一个promise(不是值),所以当你在console.log中时,你得到了promise对象

Protractor修补Jasmine以自动解决expect()内的承诺,这样它就知道如何解析该值并与预期结果进行比较。

如果你想控制console.log的值,你需要用.then()来解析承诺以获得价值。

rowData.then(function(rowDataText) { console.log(rowDataText); )}

当他们开始使用量角器时,这几乎是每个人的第一个问题。如果你想要很好地理解如何操纵它们,你将想要了解promises的工作原理。

相关问题