diff --git a/packages/volto/cypress/support/commands.js b/packages/volto/cypress/support/commands.js index 6ae8849820..f8ba71f310 100644 --- a/packages/volto/cypress/support/commands.js +++ b/packages/volto/cypress/support/commands.js @@ -716,11 +716,10 @@ Cypress.Commands.add('clearSlate', (selector) => { return cy .get(selector) .focus() - .click({ force: true }) // fix sporadic failure this element is currently animating - .wait(1000) - .type('{selectAll}') - .wait(1000) - .type('{backspace}'); + .click({ force: true }) + .type('{selectAll}', { delay: 20 }) + .type('{backspace}', { delay: 20 }) + .wait(200); }); Cypress.Commands.add('getSlate', (createNewSlate = false) => { @@ -784,6 +783,15 @@ Cypress.Commands.add('typeInSlate', { prevSubject: true }, (subject, text) => { ); }); +Cypress.Commands.add( + 'typeWithDelay', + { prevSubject: 'element' }, + (subject, text, options) => { + const delay = options && options.delay ? options.delay : 20; + cy.wrap(subject).type(text, { delay }); + }, +); + Cypress.Commands.add('lineBreakInSlate', { prevSubject: true }, (subject) => { return ( cy @@ -873,7 +881,9 @@ Cypress.Commands.add('addNewBlock', (blockName, createNewSlate = false) => { }); Cypress.Commands.add('navigate', (route = '') => { - return cy.window().its('appHistory').invoke('push', route); + cy.intercept('GET', '**/*').as('navGetCall'); + cy.window().its('appHistory').invoke('push', route); + cy.wait('@navGetCall'); }); Cypress.Commands.add('store', () => { diff --git a/packages/volto/cypress/tests/core/basic/locking.js b/packages/volto/cypress/tests/core/basic/locking.js index c47ddff1f1..d414667777 100644 --- a/packages/volto/cypress/tests/core/basic/locking.js +++ b/packages/volto/cypress/tests/core/basic/locking.js @@ -96,15 +96,16 @@ describe('Document locking', () => { cy.visit('/logout'); cy.wait('@logout'); + cy.findByRole('alert') + .get('.toast-inner-content') + .should('contain', 'You have been logged out'); + cy.get('.toast-dismiss-action').click(); // As another editor I can see the locked document cy.autologin('editor2', 'password'); cy.visit('/document'); cy.wait('@content'); - - cy.findByRole('alert') - .get('.toast-inner-content') - .contains('This item was locked by Editor 1 on'); + cy.get('.toolbar-body').should('be.visible'); // As another editor I can unlock the document cy.findByLabelText('Unlock').click(); @@ -114,14 +115,11 @@ describe('Document locking', () => { cy.findByLabelText('Edit').click(); // As another editor I can edit the document - cy.clearSlateTitle().type('New title by Editor 2'); + cy.clearSlateTitle().typeWithDelay('New title by Editor 2'); cy.get('#toolbar-save').click(); - // cy.waitForResourceToLoad('document'); cy.wait('@saveDoc'); cy.wait('@getDoc'); - // cy.pause(); - cy.url().should('eq', Cypress.config().baseUrl + '/document'); cy.contains('New title by Editor 2'); cy.get('h1.documentFirstHeading').should('not.be.empty'); diff --git a/packages/volto/cypress/tests/core/blocks/listing/blocks-listing.js b/packages/volto/cypress/tests/core/blocks/listing/blocks-listing.js index 87580ff787..c16f2c95e7 100644 --- a/packages/volto/cypress/tests/core/blocks/listing/blocks-listing.js +++ b/packages/volto/cypress/tests/core/blocks/listing/blocks-listing.js @@ -1077,38 +1077,42 @@ describe('Listing Block Tests', () => { cy.wait('@save'); cy.wait('@content'); - // The wait is needed to solve the flakyness introduced because that component - // is removed momentarilly from the DOM when saving - cy.wait(1000); //test second pagination click - cy.get('.ui.pagination.menu a[value="2"]').first().click(); + cy.get('.ui.pagination.menu a[value="2"]') + .first() + .should('be.visible') + .click(); //test f5 cy.reload(); cy.isInHTML({ parent: '.listing-item', content: 'My Folder 3' }); cy.url().should('include', '=2'); // const listing2 = cy.get('.ui.pagination.menu').last(); //test third pagination click on second listing - cy.get('.ui.pagination.menu a[value="3"]').first().click(); + cy.get('.ui.pagination.menu a[value="3"]') + .first() + .should('be.visible') + .click(); //test f5 cy.reload(); cy.isInHTML({ parent: '.listing-item', content: 'My Folder 3' }); cy.url().should('include', '=2'); cy.url().should('include', '=3'); //on logo click go to home page and remove ?page=2 from path - cy.get('.logo').first().click(); + cy.get('.logo').first().should('be.visible').click(); cy.url().should('not.include', '=2'); cy.url().should('not.include', '=3'); - // we need to wait for the page to load otherwise we navigate /my-page - // followed by / from the logo click - cy.wait(1000); - cy.navigate('/my-page'); - cy.wait(1000); - cy.get('.ui.pagination.menu a[value="2"]').first().click({ force: true }); - cy.get('.ui.pagination.menu a[value="3"]').first().click({ force: true }); + cy.get('.ui.pagination.menu a[value="2"]') + .first() + .should('be.visible') + .click({ force: true }); + cy.get('.ui.pagination.menu a[value="3"]') + .first() + .should('be.visible') + .click({ force: true }); cy.go(-1); - cy.wait(1000); + cy.wait('@content'); cy.isInHTML({ parent: '.listing-item', content: 'My Folder 3' }); cy.url().should('not.include', '=3'); cy.go(-1); diff --git a/packages/volto/news/5998.internal b/packages/volto/news/5998.internal new file mode 100644 index 0000000000..ccb5323741 --- /dev/null +++ b/packages/volto/news/5998.internal @@ -0,0 +1,3 @@ +Modified `locking` and `block-listing` cypress tests +to use more `assertions` instead of wait times in order to improve +the reliability of the tests. @ichim-david \ No newline at end of file