Created
August 23, 2020 02:06
-
-
Save andy23512/2bc596fb6a98f0ac53fea010dd75437e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Url = string; | |
export function getTexts(targetSection: string) { | |
return cy | |
.get('.parent') | |
.find('.section') | |
.then(($sections) => { | |
const result: { [key: string]: string[] } = {}; | |
$sections | |
.each((_, section) => { | |
const $section = Cypress.$(section); | |
const sectionText = $section.text(); | |
if (sectionText === targetSection) { | |
result[$section.text()] = $section | |
.next('.child') | |
.find('.child-label') | |
.map((_, value) => Cypress.$(value).text()) | |
.get(); | |
} | |
}) | |
.get(); | |
return result; | |
}); | |
} | |
it('loads examples', () => { | |
const url: Url = './index.html'; | |
cy.visit(url); | |
getTexts('Google').then((texts) => { | |
console.log(texts); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment