npm.io
1.0.10 • Published 2 years ago

cypress-test-helper

Licence
ISC
Version
1.0.10
Deps
2
Size
28 kB
Vulns
0
Weekly
0

Benefits of Using cypress-test-helper library

  • Enhanced Readability: Custom commands improve test code readability by replacing repetitive code with concise and self-explanatory functions.

  • Reduced Code Duplication: Custom commands eliminate the need to duplicate code in different test scenarios, reducing redundancy and improving code maintainability.

  • Encapsulated Complex Logic: Custom commands allow complex test logic to be encapsulated, making it easier to understand and reuse throughout the test suite.

  • Simplified Cypress Tests: These utility functions simplify Cypress tests by providing concise and reusable methods for locating and interacting with DOM elements.

Available Custom Commands

Custom commands available in this library:

shouldExist
  • Description: Asserts that an element exists in the DOM.

  • Example:

cy.get("selector").shouldExist();
shouldBeVisible
  • Description: Asserts that an element is visible in the viewport.

  • Example:

cy.get("selector").shouldBeVisible();
shouldBeHidden
  • Description: Asserts that an element is hidden in the viewport.

  • Example:

cy.get("selector").shouldBeHidden();
shouldBeEnabled
  • Description: Asserts that an element is enabled in the viewport.

  • Example:

cy.get("selector").shouldBeEnabled();
shouldBeDisabled
  • Description: Asserts that an element is disabled in the viewport.

  • Example:

cy.get("selector").shouldBeDisabled();
shouldBeChecked
  • Description: Asserts that an element is checked in the viewport.

  • Example:

cy.get("selector").shouldBeChecked();
shouldBeUnChecked
  • Description: Asserts that an element is unchecked in the viewport.

  • Example:

cy.get("selector").shouldBeUnChecked();
shouldHaveText
  • Description: Asserts that an element contains the specified text.

  • Example:

cy.get("#elementWithText").shouldHaveText("Expected Text");
shouldHaveHref
  • Description: Asserts that an element has the specified href attribute.

  • Example:

cy.get("#link").shouldHaveHref("/about");
verifyTextDisplayed
  • Description: Asserts that an element is visible and contains the specified text.

  • Example:

cy.verifyTextDisplayed("Welcome to Cypress Custom Commands!");
verifyTextboxValue
  • Description: Asserts that a textbox has the specified value.

  • Example:

cy.verifyTextboxValue("Default Text");
verifyElementDoesNotExist
  • Description: Asserts that an element does not exist in the DOM.

  • Example:

cy.verifyElementDoesNotExist("#nonExistentElement");
shouldHavePlaceHolder
  • Description: Asserts that an input element has the specified placeholder text.

  • Example:

cy.get("#inputWithPlaceholder").shouldHavePlaceHolder("Enter your text");

Cypress Utility Functions

Documentation for a set of utility functions that can be used in Cypress tests to locate and interact with DOM elements:

textboxByLabel:

  • Description: Locates a textbox by its associated label text.
  • Usage:
cy.textboxByLabel("Email Address").type("johndoe@example.com");

textboxByRoleName:

  • Description: Locates a textbox by its aria-label attribute.
  • Usage:
cy.textboxByRoleName("Search Field").type("Search Query");

dropdownByRoleName:

  • Description: Locates a dropdown by its aria-label attribute.
  • Usage:
cy.dropdownByRoleName("Select Category").select("Electronics");

linkByText:

  • Description: Locates a link by its visible text content.
  • Usage:
cy.linkByText("Learn More").click();

buttonByText:

  • Description: Locates a button by its visible text content.
  • Usage:
cy.buttonByText("Submit").click();

buttonByRoleName:

  • Description: Locates a button by its aria-label attribute.
  • Usage:
cy.buttonByRoleName("Add to Cart").click();

byLabel:

  • Description: Locates an element by its associated label text.
  • Usage:
cy.byLabel("Username").type("johndoe");

byText:

  • Description: Locates an element by its visible text content.
  • Usage:
cy.byText("Welcome to the Dashboard").should("be.visible");

byDataCy:

  • Description: Locates an element by its data-cy attribute.
  • Usage:
cy.byDataCy("login-button").click();

Keywords