stackdev
stackdev

Reputation: 27

Protractor: How do you retrieve data from multiple cells from multiple rows?

I am trying to get data and assert it from multiple cells from multiple rows.

I have a table with 10 rows and 13 cells in each row. I need to get values and assert only from cells 1, 2, 3 and 5.

This is the code I have:

let rows = element.all(by.tagName('tr'));
    let data = rows.map((row) => { 
        let cells = row.all(by.tagName('td'));
        return {
            position: cells.get(1).getText(),
            category: cells.get(2).getText(),
            value: cells.get(3).getText(),
            points: cells.get(5).getText()
        }        
    })

    expect(data).to.deep.equal([
        {position: "1", category: "test1", value: "11", points: "3"},
        {position: "2", category: "test2", value: "12", points: "5"},
        {position: "3", category: "test3", value: "13", points: "3"},
        {position: "4", category: "test4", value: "14", points: "5"},
        {position: "5", category: "test5", value: "15", points: "3"},
        {position: "6", category: "test6", value: "16", points: "5"},
        {position: "7", category: "test7", value: "17", points: "3"},
        {position: "8", category: "test8", value: "18", points: "5"},
        {position: "9", category: "test9", value: "19", points: "3"},
        {position: "10", category: "test10", value: "20", points: "5"}
    ]);

How can I fix this? Currently I get this error:

AssertionError: expected { Object (flow_, stack_, ...) } to deeply equal [ Array(10) ]

Upvotes: 0

Views: 82

Answers (1)

Infern0
Infern0

Reputation: 2814

Why you dont use just expect([]).toEqual([])

If you have trouble with the object, try with stringify.

expect(JSON.stringify(data)).toEqual('[{"....."}]');

or

expect(JSON.stringify(data)).toMatch('[{"....."}]');

Upvotes: 1

Related Questions