0
0
Cypresstesting~20 mins

App Actions pattern in Cypress - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
App Actions Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the test result of this Cypress App Action?
Consider this Cypress App Action that logs in a user and verifies the dashboard heading. What will be the test execution result?
Cypress
class LoginActions {
  login(username, password) {
    cy.get('#username').type(username);
    cy.get('#password').type(password);
    cy.get('button[type=submit]').click();
    return this;
  }
  verifyDashboard() {
    cy.get('h1').should('contain.text', 'Dashboard');
    return this;
  }
}

const login = new LoginActions();

describe('User Login Test', () => {
  it('logs in and verifies dashboard', () => {
    cy.visit('/login');
    login.login('user1', 'pass123').verifyDashboard();
  });
});
ATest fails because the login method does not return a promise to chain verifyDashboard.
BTest fails because cy.get('#username') selector is invalid.
CTest fails due to missing cy.visit() before login action.
DTest passes because the dashboard heading is correctly asserted after login.
Attempts:
2 left
💡 Hint
Check if the methods return 'this' to allow chaining and if the selectors are valid.
assertion
intermediate
2:00remaining
Which assertion correctly verifies a success message in an App Action?
You want to create an App Action method that checks if a success alert with text 'Saved successfully' is visible. Which assertion is correct?
Cypress
class SaveActions {
  verifySuccess() {
    // Which assertion is correct here?
  }
}
Acy.get('.alert-success').should('be.visible').and('contain.text', 'Saved successfully');
Bcy.get('.alert-success').should('be.visible').and('have.value', 'Saved successfully');
Ccy.get('.alert-success').should('have.text', 'Saved successfully').and('be.visible');
Dcy.get('.alert-success').should('contain', 'Saved successfully').and('visible');
Attempts:
2 left
💡 Hint
Use correct chaining of Cypress assertions and valid assertion names.
🔧 Debug
advanced
2:00remaining
Why does this App Action fail to click the submit button?
This App Action method is supposed to click a submit button but fails with 'Timed out retrying' error. What is the likely cause?
Cypress
class FormActions {
  submit() {
    cy.get('button.submit').click();
  }
}

// Test code
const form = new FormActions();
form.submit();
AThe selector 'button.submit' does not match any element because the button uses an ID, not a class.
BThe click() command is missing a wait() before it to ensure the button is visible.
CThe submit() method does not return 'this' so chaining fails.
DThe test is missing cy.visit() to load the page before calling submit().
Attempts:
2 left
💡 Hint
Check if the selector matches the actual button element in the HTML.
framework
advanced
2:00remaining
Which App Actions pattern improves test readability and reuse in Cypress?
You want to organize your Cypress tests using the App Actions pattern. Which approach best follows this pattern?
AUse global functions without returning anything to perform actions.
BWrite all Cypress commands directly inside test cases without abstraction.
CCreate classes with methods for user actions that return 'this' to allow chaining in tests.
DPut all selectors and commands inside Cypress custom commands only.
Attempts:
2 left
💡 Hint
Think about how to make tests readable and maintainable with chaining.
🧠 Conceptual
expert
2:00remaining
What is the main benefit of using the App Actions pattern in Cypress tests?
Why do testers prefer the App Actions pattern when writing Cypress tests for complex applications?
AIt automatically generates test reports with screenshots and logs.
BIt centralizes user interactions into reusable methods, improving test readability and reducing duplication.
CIt replaces the need for assertions by validating UI elements implicitly.
DIt allows tests to run faster by skipping unnecessary commands.
Attempts:
2 left
💡 Hint
Consider how organizing actions helps maintain tests as apps grow.