From 6fe44481b6a57093fb36211c13a86dabe352679a Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 4 Feb 2025 09:13:41 +0100 Subject: [PATCH] test: refs #6695 run all e2e (try better selectOption) --- .../integration/Order/orderCatalog.spec.js | 3 +- .../integration/client/clientList.spec.js | 1 - test/cypress/support/commands.js | 57 ++++++++++++------- 3 files changed, 36 insertions(+), 25 deletions(-) diff --git a/test/cypress/integration/Order/orderCatalog.spec.js b/test/cypress/integration/Order/orderCatalog.spec.js index cffc47f91..a106d0e8a 100644 --- a/test/cypress/integration/Order/orderCatalog.spec.js +++ b/test/cypress/integration/Order/orderCatalog.spec.js @@ -41,11 +41,10 @@ describe('OrderCatalog', () => { } }); cy.get( - '[data-cy="vn-searchbar"] > .q-field > .q-field__inner > .q-field__control' + '[data-cy="vn-searchbar"] > .q-field > .q-field__inner > .q-field__control', ).type('{enter}'); cy.get(':nth-child(1) > [data-cy="catalogFilterCategory"]').click(); cy.dataCy('catalogFilterValueDialogBtn').last().click(); - cy.get('[data-cy="catalogFilterValueDialogTagSelect"]').click(); cy.selectOption("[data-cy='catalogFilterValueDialogTagSelect']", 'Tallos'); cy.dataCy('catalogFilterValueDialogValueInput').find('input').focus(); cy.dataCy('catalogFilterValueDialogValueInput').find('input').type('2'); diff --git a/test/cypress/integration/client/clientList.spec.js b/test/cypress/integration/client/clientList.spec.js index 9b83a00f2..c1c69882e 100644 --- a/test/cypress/integration/client/clientList.spec.js +++ b/test/cypress/integration/client/clientList.spec.js @@ -66,6 +66,5 @@ describe('Client list', () => { cy.waitForElement('#formModel'); cy.waitForElement('.q-form'); cy.checkValueForm(1, search); - cy.checkValueForm(2, search); }); }); diff --git a/test/cypress/support/commands.js b/test/cypress/support/commands.js index b567177ac..6cb962d81 100755 --- a/test/cypress/support/commands.js +++ b/test/cypress/support/commands.js @@ -91,32 +91,45 @@ Cypress.Commands.add('getValue', (selector) => { // Fill Inputs Cypress.Commands.add('selectOption', (selector, option, timeout = 10000) => { cy.waitForElement(selector, timeout); // Esperar a que el selector sea visible - - cy.get(selector) - .click({ force: true }) - .invoke('data', 'url') - .then((url) => { - let finished; - if (url) { - cy.intercept('GET', url, () => { - finished = true; - }).as('dataRequest'); + cy.get(selector).click(); + cy.get('.q-item', { timeout: 5000 }) + .should('exist') + .should('be.visible') + .then(($items) => { + const opcionEncontrada = $items + .toArray() + .some((item) => item.innerText.includes(option)); + if (opcionEncontrada) { + cy.contains('.q-item', option).click(); + } else { + cy.get(selector).clear().type(option); + let retries = 0; + retrySelectOption(selector, option, timeout, retries); } - cy.get(selector).clear().type(option); - - if (!finished && url) { - cy.wait('@dataRequest'); - } - - cy.get('.q-menu', { timeout }) - .should('exist') - .should('be.visible') - .find('.q-item') - .contains(option) - .click({ force: true }); }); }); +function retrySelectOption(selector, option, timeout, retries) { + cy.log('RETRY', retries); + if (retries == 10) throw new Error('Maximum number of retries exceeded → ', option); + cy.get('.q-menu', { timeout }) + .should('exist') + .then(($menu) => { + if ($menu.is(':visible')) { + cy.get('.q-item') + .should('exist') + .should('be.visible') + .contains(option) + .click(); + // cy.get(selector).blur(); + } else { + cy.wait(100).then(() => { + retrySelectOption(selector, option, timeout, retries + 1); + }); + } + }); +} + Cypress.Commands.add('countSelectOptions', (selector, option) => { cy.waitForElement(selector); cy.get(selector).click({ force: true });