la selección automática para el campo de autocompletar
it('Test to grab the autocomplete values', ()=> { cy.visit('https://jqueryui.com/autocomplete/'); cy.get('#tags').type('c') cy.get('#ui-id-2').first().click() }) })muestra que se hizo clic pero no se elige
Pude ver que hay un iframe, para tratar con iframe tienes que usar el código:
cy.get('iframe.demoframe').its('0.contentDocument').its('body')Entonces su código debería verse así:
cy.visit('https://jqueryui.com/autocomplete/') cy.get('iframe.demo-frame') .its('0.contentDocument') .its('body') .find('#tags') .type('c') cy.get('iframe.demo-frame') .its('0.contentDocument') .its('body') .find('li') .first() .click() Ahora, si desea condensar aún más su secuencia de comandos, puede usar los comandos personalizados de Cypress. Vaya a cypress/support/command.js y escriba:
Cypress.Commands.add('getIframe', (iframe) => { return cy .get(iframe) .its('0.contentDocument.body') .should('be.visible') .then(cy.wrap) })Y tu prueba será:
cy.visit('https://jqueryui.com/autocomplete/') cy.getIframe('iframe.demo-frame').find('#tags').type('c') cy.getIframe('iframe.demo-frame').find('li').first().click()Su código está básicamente bien, pero debe ejecutarlo dentro del iframe
cy.visit('https://jqueryui.com/autocomplete/') cy.get('iframe.demo-frame') .its('0.contentDocument.body') .within(() => { cy.get('#tags').type('c') cy.get('#ui-id-2').first().click() cy.get('#tags').should('have.value', 'ActionScript') })