Question

I am attemping to get the last row of a ng-repeat(ed) table via protractor to test and ensure the object I just created in a previous test run shows up. I have gotten as far as getting all of the text of the row but cannot seem to figure out through trial and error how to get each column of the last row as part of the array so I can verify each piece and then in the last column I have buttons to click which will be the next step.

The code I have so far is:

var elems = element.all(by.repeater('alert in alerts'));
elems.last().then(function(elm) {
    console.log(expect(elm.getText()).toMatch('/testRunner/'));
});

As mentioned above, the expected output/output I want to check against is 'textRunner' and instead I get the entire row of text as such:

testRunner testing the runner 5 minutes No View Edit Enable

EDIT Here is my final code:

var rows = element.all(by.repeater('alert in alerts'));
rows.last().then(function(row) {
    var rowElems = row.findElements(by.tagName('td'));
    rowElems.then(function(cols){
        expect(cols[0].getText()).toContain('testRunner');
        expect(cols[1].getText()).toContain('testing the runner');
        expect(cols[4].getText()).toContain('5 minutes');
    });
});
Was it helpful?

Solution

var rows = element.all(by.repeater('alert in alerts'));
rows.last().then(function(row) {
    var rowElems = row.findElements(by.tagName('td'));
    rowElems.then(function(cols){
        expect(cols[0].getText()).toContain('testRunner');
        expect(cols[1].getText()).toContain('testing the runner');
        expect(cols[4].getText()).toContain('5 minutes');
    });
});

OTHER TIPS

Assuming your are using a <table>, and your different values are in <td>, you could check values by using the by.tagName locator strategy.

var rows = element.all(by.repeater('alert in alerts'));
var row = rows.last();
var rowElems = row. findElements(by.tagName('td'));
expect(rowElems.get(0).getText()).toMatch('/testRunner/');
expect(rowElems.get(1).getText()).toMatch('/testing/');
expect(rowElems.get(2).getText()).toMatch('/the/');
expect(rowElems.get(3).getText()).toMatch('/runner/');
expect(rowElems.get(4).getText()).toMatch('/5/');
expect(rowElems.get(5).getText()).toMatch('/minutes/');
expect(rowElems.get(6).getText()).toMatch('/No/');
expect(rowElems.get(7).getText()).toMatch('/View/');
expect(rowElems.get(8).getText()).toMatch('/Edit/');
expect(rowElems.get(9).getText()).toMatch('/Enable/');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top