I implemented page objects with some chain methods.
Page looks like this
class Table {
getTable() {
return cy.get('table#tblItem');
}
getListRow() {
return this.getTable()
.within(($tbl) => {
cy.get('tbody').scrollTo('bottom', { ensureScrollable: false, duration: 1000 });
return cy.wrap($tbl).find('tbody#itemBody tr');
});
}
}
And in cypress spec file, I do assertion to verify if the row list has items
Table.getListRow()
.then((lstRowItem) => {
expect(lstRowItem).have.length.greaterThan(1);
})
But I always get the result of method 'getTable()', not 'getListRow()'. The test failed because it gets value 1 of the table.
How can I get correct return of this chain method.
Thank you
Tableis a class, not an instance andgetListRow()is a method on an instance. You need to create a Table object as inconst t = new Table(). Then, you can callt.getListRow().