4

I have this code:

<div class="input-group" data-cy="k-item">
  <input type="text" placeholder="my_placeholder" value="my_value">
  <div data-cy="delete-field" role="button" tabindex="-1" class="r_field">
    <i class="close"></i>
  </div>
</div>

I have my cypress code for clicking on "close" and check that the item when submit is deleted in the table:

cy.getBySel('k-item').within(() => {
    cy.getBySel('delete-field').click().click()
   })
 cy.getBySel('register').click()
 cy.intercept('GET', 'route_intercepted').as('getRoute')
 cy.wait('@getRoute')
 cy.get('table').should('not.contain', 'my_item')
})

The test is passing in my local and even in headless mode but when in pipeline it is failing saying:

AssertionError: Timed out retrying after 4000ms: Expected not to find content: 'my_item' within the selector: 'table' but continuously found it.

I think the item is not getting deleted after the submit. I am experiencing the same issue with force:true. Have anyone experienced this issue please and also is there any other way to make the same tests more robust.

Fody
  • 23,754
  • 3
  • 20
  • 37
ZombiePie
  • 299
  • 1
  • 4
  • 14
  • Have you found a solution or the root cause for this behavior? I'm observing something very similar in my tests and I just cannot find a way to get it working. – Robert Strauch Nov 21 '22 at 07:20

4 Answers4

2

Add another assertion for an element on the page that is not delayed in rendering. This could be a header, spinner, etc. but must be something immediately rendered, not something async as this list of items appears to be.

cy.wait('@getRoute')
// add another assertion here
cy.get('table').should('not.contain', 'my_item')
Fody
  • 23,754
  • 3
  • 20
  • 37
Kevin Old
  • 969
  • 1
  • 9
  • 20
1

How about you increase the timeout to 7 seconds and try. Mostly in CI systems since the resources are shared so the execution speed might vary, If the line below works locally then my best guess is increasing the timeout should do the job.

cy.get('table', {timeout: 7000}).should('not.contain', 'my_item')
Alapan Das
  • 17,144
  • 3
  • 29
  • 52
  • 1
    Can you add information on _why_ increasing the timeout could solve the problem? – agoff Apr 05 '22 at 15:00
  • I have tried both the answers i am still getting the error.. I am feeling that the delete is really not happening thats why the item is still showing in the table. My issue is that its passing everywhere apart the pipeline. – ZombiePie Apr 06 '22 at 09:45
1

Try moving the intercept to the top of the test. It's a "listener" so it should be set up before the delete event is triggered.

cy.intercept('GET', 'route_intercepted').as('getRoute')

cy.getBySel('k-item').within(() => {

  cy.getBySel('delete-field').click()
  cy.getBySel('register').click()

  cy.wait('@getRoute')
  cy.get('table').should('not.contain', 'my_item')
})

Also the alias wait needs an @, but I presume that was a typo.

Fody
  • 23,754
  • 3
  • 20
  • 37
0

You have to wait the response on the wait call and just then you can check your element:

cy.getBySel('k-item').within(() => {
    cy.getBySel('delete-field').click().click();
})
cy.getBySel('register').click();
cy.intercept('GET', 'route_intercepted').as('getRoute');
cy.wait('@getRoute').then(()=>{ //wait the response of your GET, then check
    cy.get('table').should('not.contain', 'my_item');
   })
})
Fseee
  • 2,476
  • 9
  • 40
  • 63
  • Actually i am still seeing the item in the list thats why i am saying the item is not getting deleted. But this is happening only in the CI .. – ZombiePie Apr 09 '22 at 16:26
  • 1
    I intercepted the delete route and it was not found, meaning that when it is clicking on register the delete is not happening. Does anyone have any idea how i can have a more robust test for the delete part? i tried even forcing it but it seems like the delete is not that easy. ``` cy.getBySel('k-item').within(() => { cy.getBySel('delete-field').within(() => { cy.get('.close').parent().click({force: true}).click() }) }) ``` – ZombiePie Apr 11 '22 at 08:30