From 44058f8b855ddffb1451241f0c28fb0cf3d9845c Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Wed, 1 Mar 2023 07:32:53 +0100 Subject: [PATCH] enhance(e2e): more resilient version of `visit('/')` (#10128) --- cypress/e2e/basic.cy.js | 14 +++++++------- cypress/support/commands.js | 7 ++++++- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/cypress/e2e/basic.cy.js b/cypress/e2e/basic.cy.js index fc3e6f35bc..b1b856119c 100644 --- a/cypress/e2e/basic.cy.js +++ b/cypress/e2e/basic.cy.js @@ -10,11 +10,11 @@ describe('Before setup instance', () => { }); it('successfully loads', () => { - cy.visit('/'); + cy.visitHome(); }); it('setup instance', () => { - cy.visit('/'); + cy.visitHome(); cy.intercept('POST', '/api/admin/accounts/create').as('signup'); @@ -43,11 +43,11 @@ describe('After setup instance', () => { }); it('successfully loads', () => { - cy.visit('/'); + cy.visitHome(); }); it('signup', () => { - cy.visit('/'); + cy.visitHome(); cy.intercept('POST', '/api/signup').as('signup'); @@ -79,11 +79,11 @@ describe('After user signup', () => { }); it('successfully loads', () => { - cy.visit('/'); + cy.visitHome(); }); it('signin', () => { - cy.visit('/'); + cy.visitHome(); cy.intercept('POST', '/api/signin').as('signin'); @@ -101,7 +101,7 @@ describe('After user signup', () => { userId: this.alice.id, }); - cy.visit('/'); + cy.visitHome(); cy.get('[data-cy-signin]').click(); cy.get('[data-cy-signin-username] input').type('alice'); diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 04a6d98b01..91a4d7abe6 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -24,6 +24,11 @@ // -- This will overwrite an existing command -- // Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) +Cypress.Commands.add('visitHome', () => { + cy.visit('/'); + cy.get('button', { timeout: 30000 }).should('be.visible'); +}) + Cypress.Commands.add('resetState', () => { cy.window(win => { win.indexedDB.deleteDatabase('keyval-store'); @@ -43,7 +48,7 @@ Cypress.Commands.add('registerUser', (username, password, isAdmin = false) => { }); Cypress.Commands.add('login', (username, password) => { - cy.visit('/'); + cy.visitHome(); cy.intercept('POST', '/api/signin').as('signin');