Skip to content

Instantly share code, notes, and snippets.

@jonnyparris
Created April 15, 2020 14:11
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 jonnyparris/2b34c17ce9062a9294dcdd7a97198124 to your computer and use it in GitHub Desktop.
Save jonnyparris/2b34c17ce9062a9294dcdd7a97198124 to your computer and use it in GitHub Desktop.
Cypress util commands
Cypress.Commands.add('getInputByName', name => {
return cy.get(`[name="${name}"]`);
});
Cypress.Commands.add('getByTestTag', tag => {
return cy.get(`[data-test-id="${tag}"]`);
});
Cypress.Commands.add('clickRecaptcha', () => {
cy.window().then(win => {
win.document
.querySelector("iframe[src*='recaptcha']")
.contentDocument.getElementById('recaptcha-token')
.click();
});
});
Cypress.Commands.add('fillInput', (label, input, options = {}) => {
return cy
.contains(label, options)
.parent()
.find('input:visible')
.clear()
.type(input);
});
Cypress.Commands.add('fillInputByName', (name, newVal, options = {}) => {
return cy
.get(`input[name="${name}"]:visible`, options)
.clear()
.type(newVal);
});
Cypress.Commands.add('fillSelectorInput', (label, input, options = {}) => {
return cy
.contains(label, options)
.parent()
.click()
.get('.v-select-list')
.contains(input)
.click();
});
Cypress.Commands.add('fillFormWith', formData => {
cy.get('form').within(() => {
for (const key in formData) {
if (formData.hasOwnProperty(key)) {
const value = formData[key];
cy.fillInput(key, value);
}
}
});
});
Cypress.Commands.add('clickLastVisibleButtonContaining', buttonText => {
cy.get(`button:contains(${buttonText}):visible`)
.last()
.click();
});
Cypress.Commands.add('advanceSignupStep', () => {
cy.clickLastVisibleButtonContaining('next');
});
Cypress.Commands.add('loginViaUI', () => {
cy.visit('/en');
cy.fillInput('E-mail', 'test.customer@mail.de');
cy.fillInput('Password', ']CXR(4Uh$@:XxH6}');
cy.contains(/login/i).click();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment