Bird
Raised Fist0
Cypresstesting~20 mins

App Actions pattern in Cypress - Practice Problems & Coding Challenges

Choose your learning style10 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.

Practice

(1/5)
1. What is the main benefit of using the App Actions pattern in Cypress tests?
easy
A. It automatically generates test data for each test run.
B. It speeds up test execution by running tests in parallel.
C. It replaces the need for assertions in tests.
D. It groups test steps into reusable methods to keep tests clean and maintainable.

Solution

  1. Step 1: Understand the purpose of App Actions pattern

    The pattern groups common test steps into reusable methods to avoid repetition.
  2. Step 2: Identify the benefit in test code

    This grouping makes tests cleaner and easier to maintain by reusing code.
  3. Final Answer:

    It groups test steps into reusable methods to keep tests clean and maintainable. -> Option D
  4. Quick Check:

    Reusable methods = cleaner tests [OK]
Hint: Remember: App Actions = reusable test steps [OK]
Common Mistakes:
  • Thinking App Actions generate test data automatically
  • Confusing App Actions with test assertions
  • Assuming App Actions speed up test execution
2. Which of the following is the correct way to define an App Action method for logging in a user in Cypress?
easy
A. const login = () => { cy.get('#user').type('admin'); cy.get('#pass').type('1234'); cy.get('#submit').click(); }
B. cy.login = () => { cy.get('#user').type('admin'); cy.get('#pass').type('1234'); cy.get('#submit').click(); }
C. function login() { cy.get('#user').type('admin'); cy.get('#pass').type('1234'); cy.get('#submit').click(); }
D. login() { cy.get('#user').type('admin'); cy.get('#pass').type('1234'); cy.get('#submit').click(); }

Solution

  1. Step 1: Identify valid JavaScript function syntax

    const login = () => { cy.get('#user').type('admin'); cy.get('#pass').type('1234'); cy.get('#submit').click(); } uses a valid arrow function assigned to a constant, which is common in Cypress helper files.
  2. Step 2: Check other options for syntax errors

    function login() { cy.get('#user').type('admin'); cy.get('#pass').type('1234'); cy.get('#submit').click(); } is a function declaration but not exported or assigned; cy.login = () => { cy.get('#user').type('admin'); cy.get('#pass').type('1234'); cy.get('#submit').click(); } incorrectly assigns to cy object; login() { cy.get('#user').type('admin'); cy.get('#pass').type('1234'); cy.get('#submit').click(); } is invalid syntax.
  3. Final Answer:

    const login = () => { cy.get('#user').type('admin'); cy.get('#pass').type('1234'); cy.get('#submit').click(); } -> Option A
  4. Quick Check:

    Arrow function assigned to const = correct syntax [OK]
Hint: Use arrow functions assigned to const for App Actions [OK]
Common Mistakes:
  • Using invalid function syntax without const or arrow
  • Attaching methods directly to cy object incorrectly
  • Omitting function keyword or arrow in definitions
3. Given this App Action method:
const addItem = (name) => { cy.get('#item-input').type(name); cy.get('#add-button').click(); }

What will be the result of this test code?
addItem('Book'); cy.get('#item-list').should('contain', 'Book');
medium
A. The test will fail because addItem does not return a value.
B. The test will pass if 'Book' appears in the item list after adding.
C. The test will throw a syntax error due to missing return statement.
D. The test will pass only if the input field has a placeholder 'Book'.

Solution

  1. Step 1: Understand what addItem does

    It types the given name into the input and clicks the add button, triggering UI update.
  2. Step 2: Analyze the assertion

    The test checks if '#item-list' contains the text 'Book', which should be true after adding.
  3. Final Answer:

    The test will pass if 'Book' appears in the item list after adding. -> Option B
  4. Quick Check:

    UI updates with added item = test passes [OK]
Hint: Add item then check list contains it [OK]
Common Mistakes:
  • Assuming missing return causes failure
  • Confusing input placeholder with typed value
  • Expecting addItem to return a value
4. This App Action method is intended to log in a user:
const login = (user, pass) => { cy.get('#username').type(user); cy.get('#password').type(pass); cy.get('#login-btn').click }

What is the error and how to fix it?
medium
A. Missing parentheses after click; fix by changing to cy.get('#login-btn').click().
B. Wrong selector for username; fix by using #user instead of #username.
C. Missing return statement; fix by adding return before cy commands.
D. Using arrow function incorrectly; fix by using function keyword.

Solution

  1. Step 1: Check method chaining syntax

    The click command is missing parentheses, so it is not called.
  2. Step 2: Fix the click command

    Add parentheses to call the function: click() to perform the click action.
  3. Final Answer:

    Missing parentheses after click; fix by changing to cy.get('#login-btn').click() -> Option A
  4. Quick Check:

    Method calls need parentheses [OK]
Hint: Always add () to call Cypress commands like click [OK]
Common Mistakes:
  • Forgetting parentheses on Cypress commands
  • Changing selectors without verifying correctness
  • Thinking return is needed for Cypress commands
5. You want to create an App Action to add multiple items from an array and verify all appear in the list. Which is the best approach?
hard
A. Use a single cy.get() call to type all items at once separated by commas.
B. Write separate tests for each item instead of looping in one method.
C. Create an addItems method that loops over the array, calls addItem for each, then asserts all items appear.
D. Add all items by typing them in one input, then click add once.

Solution

  1. Step 1: Understand the need for reusability and verification

    Looping over the array and calling addItem reuses existing code and ensures each item is added properly.
  2. Step 2: Verify all items appear after adding

    After adding, asserting all items appear confirms the UI updated correctly for each item.
  3. Final Answer:

    Create an addItems method that loops over the array, calls addItem for each, then asserts all items appear. -> Option C
  4. Quick Check:

    Loop + reuse + verify = best practice [OK]
Hint: Loop array, reuse addItem, then assert all present [OK]
Common Mistakes:
  • Typing all items at once without separate adds
  • Writing many separate tests instead of one reusable method
  • Assuming one click adds multiple items automatically
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard