diff --git a/Dockerfile.e2e b/Dockerfile.e2e index 720f7414dc..1bd92ea1ff 100644 --- a/Dockerfile.e2e +++ b/Dockerfile.e2e @@ -50,5 +50,3 @@ COPY test/cypress test/cypress ENV CYPRESS_BROWSER=chrome ENV CHROME_BIN=/usr/bin/chromium - -CMD ["npx", "cypress", "run"] diff --git a/test/cypress/support/commands.js b/test/cypress/support/commands.js index 438f0ce8d2..814cafdf73 100755 --- a/test/cypress/support/commands.js +++ b/test/cypress/support/commands.js @@ -92,43 +92,40 @@ Cypress.Commands.add('getValue', (selector) => { Cypress.Commands.add('selectOption', (selector, option, timeout = 2500) => { cy.waitForElement(selector, timeout); - cy.get(selector, { timeout }) // Selecciona el elemento que tiene el atributo data-cy - .should('exist') // Verifica que el input exista - .should('be.visible') // Verifica que el input exista + cy.get(selector, { timeout }) + .should('exist') + .should('be.visible') .click() .then(($el) => { - if ($el.is('input')) { - return checkAriaControl($el); - } - checkAriaControl($el.find('input')); + cy.wrap($el.is('input') ? $el : $el.find('input')) + .invoke('attr', 'aria-controls') + .then((ariaControl) => selectItem(selector, option, ariaControl)); }); - - function checkAriaControl(input) { - cy.wrap(input) - .invoke('attr', 'aria-controls') // Obtiene el valor del atributo aria-controls - .then((ariaControl) => { - cy.log('ARIA', ariaControl); // Muestra el valor en la consola de Cypress - getItems(ariaControl).then((items) => { - cy.log('items: ', items); - const matchingItem = items - .toArray() - .find((item) => item.innerText.includes(option)); - if (!matchingItem) return findOption(selector, option, ariaControl); - cy.wrap(matchingItem).click(); - }); - }); - } }); +function selectItem(selector, option, ariaControl, hasWrite = true) { + if (!hasWrite) cy.wait(100); + + getItems(ariaControl).then((items) => { + const matchingItem = items + .toArray() + .find((item) => item.innerText.includes(option)); + if (matchingItem) return cy.wrap(matchingItem).click(); + + if (hasWrite) cy.get(selector).clear().type(option, { delay: 0 }); + return selectItem(selector, option, ariaControl, false); + }); +} + function getItems(ariaControl, startTime = Cypress._.now(), timeout = 2500) { + // Se intenta obtener la lista de opciones del desplegable de manera recursiva return cy - .get('#' + ariaControl, { timeout }) // Se asegura de que el selector aparezca en tiempo razonable + .get('#' + ariaControl, { timeout }) .should('exist') .find('.q-item') .should('exist') .then(($items) => { if (!$items?.length || $items.first().text().trim() === '') { - // 🔹 Si ha pasado más tiempo que el límite, falla el test if (Cypress._.now() - startTime > timeout) { throw new Error( `getItems: Tiempo de espera (${timeout}ms) excedido.`, @@ -141,18 +138,6 @@ function getItems(ariaControl, startTime = Cypress._.now(), timeout = 2500) { }); } -function findOption(selector, option, ariaControl) { - cy.get(selector).clear().type(option); - // cy.get('.q-menu').should('not.be.visible'); - getItems(ariaControl).then((items) => { - cy.log('findOption items: ', items); - const matchingItem = items - .toArray() - .find((item) => item.innerText.includes(option)); - cy.wrap(matchingItem).click(); - }); -} - Cypress.Commands.add('countSelectOptions', (selector, option) => { cy.waitForElement(selector); cy.get(selector).click({ force: true });