Protractor : Read Table contents

前端 未结 2 711
孤城傲影
孤城傲影 2020-12-10 17:35

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.



        
相关标签:
2条回答
  • 2020-12-10 17:44

    Use all() in conjunction with 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"]);
    
    0 讨论(0)
  • 2020-12-10 17:47

    Easiest way would be as below:

    var tabledata = element.all(by.css("./table"));
    
    // get rows 
    var rows = tabledata.all(by.tagName("tr"));
    
    // get cell values
    var cells = rows.all(by.tagName("td"));
    
    expect(cells.get(0).getText()).toEqual("something")
    expect(cells.get(1).getText()).toEqual("something")
    expect(cells.get(2).getText()).toEqual("something")
    

    I implemented it and it is working for me.

    0 讨论(0)
提交回复
热议问题