Добавить
Уведомления

Get Text From A List Of Elements

Imagine you have several elements, and you want to extract the text from each element. You can grab the elements using the cy.get command. That gives you a jQuery object. You can iterate over it by converting it to a plain array using Cypress.$.makeArray, or by using a Lodash method Cypress._.map. Once you extract the strings, you can compare the array of strings to the expected list. function getTexts ($el) { return Cypress._.map($el, 'innerText') } cy.get('.matching') .should('have.length', 3) .then(getTexts) .should('deep.equal', ['first', 'third', 'fourth']) Find this recipe at https://glebbahmutov.com/cypress-examples

12+
16 просмотров
2 года назад
12+
16 просмотров
2 года назад

Imagine you have several elements, and you want to extract the text from each element. You can grab the elements using the cy.get command. That gives you a jQuery object. You can iterate over it by converting it to a plain array using Cypress.$.makeArray, or by using a Lodash method Cypress._.map. Once you extract the strings, you can compare the array of strings to the expected list. function getTexts ($el) { return Cypress._.map($el, 'innerText') } cy.get('.matching') .should('have.length', 3) .then(getTexts) .should('deep.equal', ['first', 'third', 'fourth']) Find this recipe at https://glebbahmutov.com/cypress-examples

, чтобы оставлять комментарии