So I have a question checking for the text that lo...
# e2e-testing
g
So I have a question checking for the text that loads on a page. I have a test that will visit a page and using
cy.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:
Copy code
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