量角器:阅读表格内容 [英] Protractor : Read Table contents

查看:162
本文介绍了量角器:阅读表格内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在为我的角度js应用程序编写e2e测试,我无法弄清楚这一点。我有一张包含数据的表格。我想提取第一行数据。

I've been writing e2e tests for my angular js app and am unable to figure this out. I've got a table with data in it. I want to extract the first rows data.

<table>
    <tr>
        <td><\td>
        <td><\td>
        <td><\td>
    </tr>
</table>

我在量角器 elementExplorer 中这样做了打印出所有3列的值

I did this in protractors elementExplorer and it prints out the values of all 3 columns

element.all(by.repeater('item in items.list')).get(0).getText()
James
Byrne
1

如果我这样做,它会输出第一列值

If I do this, it prints out the first column value

element.all(by.repeater('item in items.list')).get(0).element(by.css('td')).getText()
WARNING - more than one element found for locator By.cssSelector("td") - the first result will be used
James

我的问题是,如何获得其他栏目?

My Question is, how do I get the values of the other columns?

推荐答案

使用 all() map()

var row = element.all(by.repeater('item in items.list')).first();
var cells = row.all(by.tagName('td'));

var cellTexts = cells.map(function (elm) {
    return elm.getText();
});

然后,您可以将其断言为列文本数组:

Then, you can assert it to be an array of column texts:

expect(cellTexts).toEqual(["The first text", "The second text", "The third text"]);

这篇关于量角器:阅读表格内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆