1

Using protractor and jasmine(wd) we want to check that a table on the web page contains expected values. We get fetch the table from the page using a CSS selector:

var table = element(by.css('table#forderungenTable')).all(by.tagName('tr'));

We then set our expectations:

table.then(function(forderungen){
...
    forderungen[2].all(by.tagName('td')).then(function(columns){
        expect(columns[1].getText()).toEqual('1');
        expect(columns[5].getText()).toEqual('CHF 277.00');
    });
});

Is it possible to change this code so that we don't have to pass functions to then, in the same way that using jasminewd means that we don't have to do this? See this page, which states:

Protractor uses jasminewd, which wraps around jasmine's expect so that you can write:

expect(el.getText()).toBe('Hello, World!')

Instead of:

el.getText().then(function(text) {
    expect(text).toBe('Hello, World!');
});

I know that I could write my own functions in a way similar to which jasminewd does it, but I want know if there is a better way to construct such expectations using constructs already available in protractor or jasminewd.

Ant Kutschera
  • 6,257
  • 4
  • 29
  • 40

1 Answers1

1

You can actually call getText() on an ElementArrayFinder:

var texts = element(by.css('table#forderungenTable')).all(by.tagName('tr')).get(2).all(by.tagName('td'));

expect(texts).toEqual(["text1", "text2", "text3"]);
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195