0
0
Cypresstesting~10 mins

Why custom commands reduce duplication in Cypress - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add a custom command in Cypress.

Cypress
Cypress.Commands.[1]('login', (email, password) => {
  cy.get('#email').type(email);
  cy.get('#password').type(password);
  cy.get('button[type=submit]').click();
});
Drag options to blanks, or click blank then click option'
Aregister
Bcreate
Cadd
Ddefine
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'create' or 'register' instead of 'add' causes errors.
Misspelling the method name.
2fill in blank
medium

Complete the code to use the custom 'login' command in a test.

Cypress
describe('User Login', () => {
  it('logs in successfully', () => {
    cy.[1]('user@example.com', 'password123');
    cy.url().should('include', '/dashboard');
  });
});
Drag options to blanks, or click blank then click option'
Alogin
Bauthenticate
CsignIn
DenterCredentials
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different command name than defined.
Forgetting to call the command on 'cy'.
3fill in blank
hard

Fix the error in the custom command definition to avoid duplication.

Cypress
Cypress.Commands.add('login', (email, password) => {
  cy.get('#email').type(email);
  cy.get('#password').[1](password);
  cy.get('button[type=submit]').click();
});
Drag options to blanks, or click blank then click option'
Atype
Benter
Cfill
Dinput
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like 'input' or 'fill'.
Misspelling 'type'.
4fill in blank
hard

Fill both blanks to create a custom command that clears and types text.

Cypress
Cypress.Commands.add('clearAndType', (selector, text) => {
  cy.get(selector).[1]();
  cy.get(selector).[2](text);
});
Drag options to blanks, or click blank then click option'
Aclear
Btype
Cclick
Dfocus
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'click' or 'focus' instead of 'clear'.
Typing before clearing the input.
5fill in blank
hard

Fill all three blanks to create a custom command that logs in and verifies URL.

Cypress
Cypress.Commands.add('loginAndCheck', (email, password, urlPart) => {
  cy.get('#email').[1](email);
  cy.get('#password').[2](password);
  cy.get('button[type=submit]').click();
  cy.url().should([3], urlPart);
});
Drag options to blanks, or click blank then click option'
Atype
Binclude
Ccontain
Dclick
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'click' instead of 'type' for inputs.
Using 'contain' which is not a valid assertion method in Cypress.
Forgetting to check URL after login.