I need to take a value from a table that changes after every page refresh. For example CPU for Chrome
describe('test dynamic table and check Chrome CPU', () => {
it('passes', () => {
cy.visit('some url')
cy.contains('span', 'CPU')
.parent()
.within(() => {
cy.contains('[role=cell]', 'Chrome')
})
})
})
Table:
UPDATE: FYI After refreshing the page, you will get columns and row changing place:
You can do like this:
cy.contains('span', 'Chrome')
.parent()
.within(() => {
cy.contains('[role=cell]', '%')
.invoke('text')
.then((text) => {
cy.log(text) //Logs 8.3%
//removing % and converting into number and asserting
expect(+text.replace(/%/g, '')).to.be.greaterThan(5)
expect(+text.replace(/%/g, '')).to.be.lessThan(15)
expect(+text.replace(/%/g, '')).to.eq(8.3)
})
})