Skip to content

Instantly share code, notes, and snippets.

@andy23512
Created August 23, 2020 02:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andy23512/2bc596fb6a98f0ac53fea010dd75437e to your computer and use it in GitHub Desktop.
Save andy23512/2bc596fb6a98f0ac53fea010dd75437e to your computer and use it in GitHub Desktop.
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