gifted-bear-34349
09/19/2022, 4:06 PMcy.contains('Some text).should('exist')
checks to see if the text we want is displaying on the page. I refactored it to look like this:
before(() => {
cy.fixture("users.json").then(() => {
cy.login(Cypress.env("username"), Cypress.env("password"));
cy.intercept({
method: 'GET',
url: apiUrl
}).as('body');
cy.visitApp("/help?lang=eng");
});
});
it("fsy_help_page : Smoke Test", function () {
cy.get("h1").contains("Help").should("exist");
cy.wait('@body').then((intercept) => {
let pageText = intercept.response.body.body;
//removes all the html tags present in text
let cleanPageText = pageText.replaceAll(/<(.+?)>/g, "").replaceAll(/ | /g, " ").split("\n").filter(entry => entry.trim() != '');
cleanPageText.forEach(paragraph => {
cy.contains(paragraph).should('exist');
});
});
cy.get('main').within((body) => {
if (body.find('a').length > 0) {
cy.get('a').each(($el) => {
cy.wrap($el).should("have.attr", "href");
})
}
});
});
I was wondering if there is a functional difference between the two approaches