From c50a138e04953a0ea7d53425f7207b25ea6f2fa0 Mon Sep 17 00:00:00 2001 From: Jennifer Shehane Date: Fri, 10 Jan 2025 11:40:24 -0500 Subject: [PATCH] Add tests for actionability retries for click and type --- .../cypress/e2e/commands/actions/click.cy.js | 46 +++++++++++++++++++ .../cypress/e2e/commands/actions/type.cy.js | 46 +++++++++++++++++++ packages/driver/cypress/e2e/issues/2831.cy.js | 31 ------------- 3 files changed, 92 insertions(+), 31 deletions(-) delete mode 100644 packages/driver/cypress/e2e/issues/2831.cy.js diff --git a/packages/driver/cypress/e2e/commands/actions/click.cy.js b/packages/driver/cypress/e2e/commands/actions/click.cy.js index 5e909247cd38..0ef45d4962c6 100644 --- a/packages/driver/cypress/e2e/commands/actions/click.cy.js +++ b/packages/driver/cypress/e2e/commands/actions/click.cy.js @@ -1723,6 +1723,52 @@ describe('src/cy/commands/actions/click', () => { cy.get('#dom').invoke('css', 'scrollBehavior').then((scrollBehavior) => expect(scrollBehavior).to.eq('smooth')) }) }) + + describe('retries in after hook when failures', () => { + it('clicks element in hook', (done) => { + cy.on('fail', (err) => { + expect(err.message).contain('expected true to be false') + done() + }) + + expect(true).to.be.false + }) + + after(() => { + const onClick = cy.stub() + + const $button = cy.$$('#button') + + $button.on('click', onClick) + + cy.get('#button').click().then(() => { + expect(onClick).to.be.calledOnce + }) + }) + }) + + describe('retries in afterEach hook when failures', () => { + it('clicks element in hook', (done) => { + cy.on('fail', (err) => { + expect(err.message).contain('expected true to be false') + done() + }) + + expect(true).to.be.false + }) + + afterEach(() => { + const onClick = cy.stub() + + const $button = cy.$$('#button') + + $button.on('click', onClick) + + cy.get('#button').click().then(() => { + expect(onClick).to.be.calledOnce + }) + }) + }) }) describe('assertion verification', () => { diff --git a/packages/driver/cypress/e2e/commands/actions/type.cy.js b/packages/driver/cypress/e2e/commands/actions/type.cy.js index a750f673e0cb..a8c13ee329eb 100644 --- a/packages/driver/cypress/e2e/commands/actions/type.cy.js +++ b/packages/driver/cypress/e2e/commands/actions/type.cy.js @@ -478,6 +478,52 @@ describe('src/cy/commands/actions/type - #type', () => { cy.get(':text:first').type('foo', { scrollBehavior: false, timeout: 200 }) }) + + describe('retries in after hook when failures', () => { + it('types in element in hook', (done) => { + cy.on('fail', (err) => { + expect(err.message).contain('expected true to be false') + done() + }) + + expect(true).to.be.false + }) + + after(() => { + const input = cy.$$('input:text:first') + + input.val('') + + expect(input).to.have.value('') + + cy.get('input:text:first').type('foo').then(($input) => { + expect($input).to.have.value('foo') + }) + }) + }) + + describe('retries in afterEach hook when failures', () => { + it('types in element in hook', (done) => { + cy.on('fail', (err) => { + expect(err.message).contain('expected true to be false') + done() + }) + + expect(true).to.be.false + }) + + afterEach(() => { + const input = cy.$$('input:text:first') + + input.val('') + + expect(input).to.have.value('') + + cy.get('input:text:first').type('foo').then(($input) => { + expect($input).to.have.value('foo') + }) + }) + }) }) describe('input types where no extra formatting required', () => { diff --git a/packages/driver/cypress/e2e/issues/2831.cy.js b/packages/driver/cypress/e2e/issues/2831.cy.js deleted file mode 100644 index d525a1ea8e6e..000000000000 --- a/packages/driver/cypress/e2e/issues/2831.cy.js +++ /dev/null @@ -1,31 +0,0 @@ -describe('page', () => { - context('after click clicks', () => { - it('passes', () => { - cy.visit('https://example.cypress.io').then(() => { - expect(false).to.be.false - }) - }) - - after(() => { - cy.get('.home-list') - .contains('Querying').click() - - cy.url().should('include', '/querying') - }) - }) - - context('after click does not click', () => { - it('fails', () => { - cy.visit('https://example.cypress.io').then(() => { - expect(false).to.be.true - }) - }) - - after(() => { - cy.get('.home-list') - .contains('Querying').click() - - cy.url().should('include', '/querying') - }) - }) -})