Check page content and controls in a configured browser test project.
Before starting: HTML selectors, JavaScript and a running local website.
Practice project: Extend the examples into a small Cypress study demo. Explain the setup, one normal case and one failure or boundary case.
Start here: concepts and guided practice
- Cypress: check the page a learner sees
A browser test can check rendered content. cy.visit opens the local route and should verifies the heading. Cypress retries linked queries and assertions according to its rules.
Configured Cypress end-to-end project with baseUrl pointing to your disposable local site. Create /study.html containing <h1>Study board</h1><button data-testid="save">Save</button>.
describe("study board", () => { it("shows a heading", () => { cy.visit("/study.html"); cy.get("h1").should("have.text", "Study board"); }); });Check the output
The test passes when the supplied page is served at the configured baseUrl.Rename the heading and observe the failure.
- Cypress: use a stable test selector
A dedicated data attribute lets a test find a control without depending on its color or layout classes. This checks that the button is usable; it does not prove a save request succeeded.
Configured Cypress end-to-end project with baseUrl pointing to your disposable local site. Create /study.html containing <h1>Study board</h1><button data-testid="save">Save</button>.
it("offers a save control", () => { cy.visit("/study.html"); cy.get('[data-testid="save"]') .should("be.visible").and("not.be.disabled"); });Check the output
The test passes with the supplied enabled button.Add disabled to the fixture button; confirm the test fails.
Open the Cypress learning path on DevStudyHub · Play coding games on this blog
No comments:
Post a Comment
Please do not enter any spam link in the comment box.