As I am new to this UI automation/cypress world, need help to setting up the assertion on javascript object return by cypress-ag-grid package
My code is reading ag-grid data
cy.get("#myGrid").getAgGridData().should((data)=>{
cy.log(data)
})
Which is printing below object in console
[
{ id: 1, name: "tata", saftyRating: "50" },
{ id: 2, name: "maruti", saftyRating: "50" },
{ id: 3, name: "ford", saftyRating: "45" }
]
My cypress code is:
cy.get("#myGrid").getAgGridData().should((data)=>{
data.forEach(({ saftyRating }) => {
cy.wrap(+saftyRating).should('be.gt', 50);
})
});
This is working fine till the moment I try make it generic parameterized typescript function which is as below:
columnValueAssertion(colname:string, asserttype:string,value:number){
cy.get("#myGrid").getAgGridData().should((data)=>{
data.forEach(({ colname }) => {
cy.wrap(+colname).should(asserttype, value);
})
});
}
And calling it as:
columnValueAssertion('saftyRating',"be.eq",50)
It is throwing assert error:
-assert NaN is not equal to **50**
And when I am replacing the colname
by saftyRating
it is working fine Not sure how convert this to parameterized function
Comments
Post a Comment