cypress-enterprise-commands
Version:
Reusable Cypress custom commands for enterprise web applications
36 lines (35 loc) • 1.57 kB
JavaScript
;
Cypress.Commands.add('clearAndTypeByPlaceholder', (textToType) => {
if (typeof textToType !== 'string') {
throw new Error(`clearAndTypeByPlaceholder: Invalid 'textToType'. Expected a string, but received ${typeof textToType}.`);
}
cy.log(`Attempting to clear and type "${textToType}" into input with placeholder containing "search".`);
cy.get('input[placeholder*="earch"]') // Selects an input element where the 'placeholder' attribute contains 'search'
.first() // Use .first() to target the first matching element if multiple exist
.should('be.visible') // Ensure the element is visible
.and('not.be.disabled') // Ensure the element is not disabled
.clear() // Clear any existing text in the input field
.type(textToType); // Type the provided text into the input field
cy.log(`Successfully typed "${textToType}" into the search input.`);
});
Cypress.Commands.add("inputTextArea", (index, text) => {
cy.get("textarea")
.eq(index)
.scrollIntoView()
.should("be.visible")
.clear()
.type(text);
});
Cypress.Commands.add("inputDecimal", (index, value) => {
cy.get('input[inputmode="decimal"]')
.eq(index)
.scrollIntoView()
.clear()
.type(value.toString());
});
Cypress.Commands.add("inputText", (attr, str) => {
cy.getByTestAttribute(attr).scrollIntoView().click({ force: true });
cy.getByTestAttribute(attr).scrollIntoView()
.clear({ force: true })
.type(str, { force: true });
});