Skip to content

Instantly share code, notes, and snippets.

@sujaykundu777
Last active May 17, 2020 15:39
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 sujaykundu777/2af6424c8a253bd461a4b8024fbd6913 to your computer and use it in GitHub Desktop.
Save sujaykundu777/2af6424c8a253bd461a4b8024fbd6913 to your computer and use it in GitHub Desktop.
cypress sample test cases
// example test case
describe("Test Case Name", () => {
// Test case goes here
it("test case name", () => {
// cypress commands goes here
cy.visit("/");
});
});
// describe block
describe("Test case aNAme", () => {
// test cases (it) goes here
});
// it block
it("test case name", () => {
// cypress (cy) commands goes here
});
// Below are the cypress commands you can use by copy pasting in to your test cases as required
// Visit the website/url
cy.visit("/");
// select a element (heading)
cy.get('h1'); // h1
cy.get('h2'); // h2
cy.get('h3'); // h3
cy.get('h4'); // h4
cy.get('h5'); // h5
cy.get('h6'); // h6
// Select a DOM (input) element
cy.get('input[name="name"]') // using name
cy.get('input[class="class1"]') // using class
cy.get('input[id="id1"]') // using id
cy.get('input[type="email"]') // using type
// type text after selecting a input
cy.get('input[name="name"]').type("Enter text here")
cy.get('input[class="class1"]') .type("Enter text here")
cy.get('input[id="id1"]').type("Enter text here")
cy.get('input[type="email"]').type("Enter text here")
// selecting a button and clicking
cy.get('button').click()
// submit form
cy.get('form').submit()
// find a nested element
// <ul>
// <li id="1"> firstone
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment