我想用柏树断言 ag 网格行中的文本,但无法获得正确的数据格式
I want to assert text in ag grid rows with cypress but not able to get correct data format
我想搜索一个 Apple 并断言如果 Apple 出现在行中至少一列。
cy.get('[row-id] [role=\"grid\"]').each((item) => {
expect(item.text()).to.have.text("Keyword")
失败日志
expected { Object (userInvocationStack, specWindow, ...) } to have text Apple
You attempted to make a chai-jQuery assertion on an object that is neither a DOM object or a jQuery object.
The chai-jQuery assertion you used was:
> text
The invalid subject you asserted on was:
> SeanLandsmanAppleCarrot
To use chai-jQuery assertions your subject must be valid.
This can sometimes happen if a previous assertion changed the subject.
.text() 方法将值作为单个字符串返回,因此断言失败。有没有办法让我获得价值“Sean Landsman Apple Carrot”而不是“SeanLandsmanAppleCarrot”
"我想搜索一个苹果并断言如果苹果出现在行中至少有一列"
行中的一列是一个“单元格”,在 DOM 中它是一个 span
和 class “ag-cell”,所以这个
cy.contains('span.ag-cell', 'Apple'); // Apple anywhere
只要有“苹果”就会成功。
很难判断这是否是您想要的。
可能是您想检查“Sean Landsman”行中是否有“Apple”,在这种情况下
cy.contains('span.ag-cell', 'Sean Landsman') // find the name
.parent('div.ag-row') // select the row
.contains('Apple'); // Apple in that row
但是如果你想检查整行文本怎么办?
cy.contains('span.ag-cell', 'Sean Landsman') // find the name
.parent('div.ag-row') // select the row
.find('span.ag-cell') // all the cells in that row
.then(cells => {
return [...cells].map(cell => cell.text()) // map them to their texts
})
.should('deep.eq', ['Sean Landsman', 'Apple', 'Carrot']);
// or might be ['', 'Sean Landsman', 'Apple', 'Carrot'] since there's a checkbox
我想搜索一个 Apple 并断言如果 Apple 出现在行中至少一列。
cy.get('[row-id] [role=\"grid\"]').each((item) => {
expect(item.text()).to.have.text("Keyword")
失败日志
expected { Object (userInvocationStack, specWindow, ...) } to have text Apple
You attempted to make a chai-jQuery assertion on an object that is neither a DOM object or a jQuery object.
The chai-jQuery assertion you used was:
> text
The invalid subject you asserted on was:
> SeanLandsmanAppleCarrot
To use chai-jQuery assertions your subject must be valid.
This can sometimes happen if a previous assertion changed the subject.
.text() 方法将值作为单个字符串返回,因此断言失败。有没有办法让我获得价值“Sean Landsman Apple Carrot”而不是“SeanLandsmanAppleCarrot”
"我想搜索一个苹果并断言如果苹果出现在行中至少有一列"
行中的一列是一个“单元格”,在 DOM 中它是一个 span
和 class “ag-cell”,所以这个
cy.contains('span.ag-cell', 'Apple'); // Apple anywhere
只要有“苹果”就会成功。
很难判断这是否是您想要的。
可能是您想检查“Sean Landsman”行中是否有“Apple”,在这种情况下
cy.contains('span.ag-cell', 'Sean Landsman') // find the name
.parent('div.ag-row') // select the row
.contains('Apple'); // Apple in that row
但是如果你想检查整行文本怎么办?
cy.contains('span.ag-cell', 'Sean Landsman') // find the name
.parent('div.ag-row') // select the row
.find('span.ag-cell') // all the cells in that row
.then(cells => {
return [...cells].map(cell => cell.text()) // map them to their texts
})
.should('deep.eq', ['Sean Landsman', 'Apple', 'Carrot']);
// or might be ['', 'Sean Landsman', 'Apple', 'Carrot'] since there's a checkbox