I have a table that has a status column, I want to check the status of the fist row (which is at last column) . the status goes from "in progress" to pleted after some amount of time (max 5 min);
here is the DOM:
<tbody>
<tr>
<td>...</td>
<td> ... </td>
<td> in progress / plete </td> //status => want to check this cell.
</tr>
<tr>
<td>...</td>
<td> ... </td>
<td> ... </td> //status
</tr>
<tr>
<td>...</td>
<td> ... </td>
<td> ... </td> //status
</tr>
</tbody>
how to reach to the cell I want and use polling mechanism to see if the status pleted?
thank you for your help
I have a table that has a status column, I want to check the status of the fist row (which is at last column) . the status goes from "in progress" to pleted after some amount of time (max 5 min);
here is the DOM:
<tbody>
<tr>
<td>...</td>
<td> ... </td>
<td> in progress / plete </td> //status => want to check this cell.
</tr>
<tr>
<td>...</td>
<td> ... </td>
<td> ... </td> //status
</tr>
<tr>
<td>...</td>
<td> ... </td>
<td> ... </td> //status
</tr>
</tbody>
how to reach to the cell I want and use polling mechanism to see if the status pleted?
thank you for your help
Share Improve this question edited Apr 14, 2022 at 12:58 TesterDick 10.7k1 gold badge18 silver badges36 bronze badges asked Apr 14, 2022 at 0:41 Samira ArabgolSamira Arabgol 3892 gold badges9 silver badges31 bronze badges5 Answers
Reset to default 3The pattern for selecting row and column in Cypress would be
cy.get('tbody tr').eq(0) // first row
.find('td').eq(2) // third col
.should('contain', 'plete') // criteria to check
This waits for the defaultCommandTimeout
setting which is 4000 ms. To extend to 5 minutes add a 300000 timeout.
cy.get('tbody tr').eq(0)
.find('td').eq(2, {timeout:300000})
.should('contain', 'plete') // on fail retry above up to 5 minutes
But you might get errors with this depending on what changes in the DOM after status is updated. If the row or the table are refreshed with a new copy, you might need to bine the steps into one selector.
cy.get('tbody tr:nth-child(1) td:nth-child(3)', {timeout:300000})
.should('contain', 'plete')
It's not always clear which steps in a mand chain will be repeated when .should()
fails.
I would first check the "in progress" status to ensure the sequence is correct.
cy.contains('tbody tr:eq(0)', 'in progress')
cy.contains('tbody tr:eq(0)', 'plete', {timeout:300000})
You can also use within
to go inside the first tr
and wait for the desired amount of time for the text plete
to appear. Something like this:
For exact text match:
cy.get('tbody')
.find('tr')
.eq(0)
.within(() => {
//eq(0) gets the first tr
cy.get('td', {timeout: 300000}).eq(2).should('have.text', 'plete') //Exact text match
})
For Partial text match:
cy.get('tbody')
.find('tr')
.eq(0)
.within(() => {
//eq(0) gets the first tr
cy.get('td', {timeout: 300000}).eq(2).should('contain.text', 'plete') //partial text match
})
Cypress has built-in polling, no need to code a special routine.
This is all you need!
cy.contains('tbody tr:nth-of-type(1) td:nth-of-type(3)', 'plete', {timeout:300000})
No need for .find()
or .within()
, the selector 'tbody tr:nth-of-type(1) td:nth-of-type(3)'
takes care of searching the table hierarchy.
The cy.contains()
mand asserts that the text "plete"
should be in that cell, and the timeout automatically polls for 5 minutes.
It will pass earlier if the status changes earlier.
Note using .within()
can give you "detached from DOM" error if the whole row is replaced upon status change.
It's unclear how the cell in your table is updated. Is there a request sent in intervals or only when first loading the page?
If its former, then it would be simple as such
// assuming only table on page and last cell of first row is always the cell you want
cy.get('tbody')
.should('be.visible') // check table is fully loading in case
.find('tr')
.first() // same as .eq(0), just more readable
.find('td')
.last() // same as .eq(3), jut more readable
.should('be.visible')
.and('match.text', /plete/i) // can update mand timeout
If you are dealing with the latter, then you'll have to use recursion to check after each page reload. Remend using cypress-recurse
import { recurse } from 'cypress-recurse'
recurse ({
() => {
return cy.get('tbody tr:nth-child(0) td:nth-child(3)') // eq to above
.should('be.visible')
},
($el) => expect($el).to.have.text('plete'),
{
// can alter configurations
timeout: 30_000,
delay: 3_000,
post: { cy.reload() }
}
)
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744850512a4597098.html
评论列表(0条)