diff --git a/cypress/integration/list/list.spec.js b/cypress/integration/list/list.spec.js index 5e697359f..3d85375a3 100644 --- a/cypress/integration/list/list.spec.js +++ b/cypress/integration/list/list.spec.js @@ -361,9 +361,8 @@ describe('Lists', () => { }) cy.visit('/lists/1/kanban') - cy.get('.kanban .bucket .tasks .task') + cy.getAttached('.kanban .bucket .tasks .task') .contains(tasks[0].title) - .should('exist') .click() cy.url() diff --git a/cypress/support/commands.js b/cypress/support/commands.js new file mode 100644 index 000000000..ccdc6f366 --- /dev/null +++ b/cypress/support/commands.js @@ -0,0 +1,17 @@ +/** + * getAttached(selector) + * getAttached(selectorFn) + * + * Waits until the selector finds an attached element, then yields it (wrapped). + * selectorFn, if provided, is passed $(document). Don't use cy methods inside selectorFn. + * + * Source: https://github.com/cypress-io/cypress/issues/5743#issuecomment-650421731 + */ +Cypress.Commands.add('getAttached', selector => { + const getElement = typeof selector === 'function' ? selector : $d => $d.find(selector); + let $el = null; + return cy.document().should($d => { + $el = getElement(Cypress.$($d)); + expect(Cypress.dom.isDetached($el)).to.be.false; + }).then(() => cy.wrap($el)); +}); diff --git a/cypress/support/index.js b/cypress/support/index.js index a51369df0..74c1400d7 100644 --- a/cypress/support/index.js +++ b/cypress/support/index.js @@ -1,2 +1,3 @@ +import './commands' import 'cypress-file-upload'