Bird
Raised Fist0
NextJSframework~20 mins

E2E testing with Playwright in NextJS - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Playwright E2E Master
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 Playwright snippet?

Consider this Playwright test code for a Next.js app. What will be the test result?

NextJS
import { test, expect } from '@playwright/test';

test('homepage has correct title', async ({ page }) => {
  await page.goto('http://localhost:3000');
  const title = await page.title();
  expect(title).toBe('My Next.js App');
});
ATest passes if the page title is exactly 'My Next.js App'
BTest fails because page.title() is not a function
CTest passes regardless of the page title content
DTest throws a runtime error due to missing await on page.goto
Attempts:
2 left
💡 Hint

Check the Playwright API for getting the page title and the use of await.

❓ locator
intermediate
1:30remaining
Which locator correctly selects the submit button by role and accessible name?

You want to select a submit button with the accessible name 'Send' in a Playwright test. Which locator is correct?

Apage.getByRole('button', { name: 'Send' })
Bpage.locator('button:has-text("Send")')
Cpage.locator('button[name="Send"]')
Dpage.getByText('Send')
Attempts:
2 left
💡 Hint

Use semantic roles and accessible names for best locator practice.

❓ assertion
advanced
2:00remaining
Which assertion correctly waits for a success message to appear?

You want to assert that a success message with text 'Saved successfully' appears after submitting a form. Which assertion is correct?

NextJS
await page.click('button[type=submit]');
Aexpect(await page.locator('text=Saved successfully').isVisible()).toBe(true);
Bawait expect(page.locator('text=Saved successfully')).toBeVisible();
Cawait expect(page.locator('text=Saved successfully')).toHaveText('Saved successfully');
Dexpect(page.locator('text=Saved successfully')).toBeVisible();
Attempts:
2 left
💡 Hint

Use Playwright's built-in waiting assertions to handle dynamic content.

🔧 Debug
advanced
2:30remaining
Why does this Playwright test intermittently fail with a timeout?

Review this test snippet and identify the cause of intermittent timeout failures.

NextJS
test('login test', async ({ page }) => {
  await page.goto('http://localhost:3000/login');
  await page.fill('#username', 'user1');
  await page.fill('#password', 'pass1');
  await page.click('button[type=submit]');
  await expect(page.locator('#welcome')).toBeVisible({ timeout: 2000 });
});
AThe test does not wait for navigation after clicking submit
BThe selector '#welcome' is invalid and causes the timeout
CMissing await before page.click causes the test to fail
DThe timeout of 2000ms is too short for the welcome element to appear after login
Attempts:
2 left
💡 Hint

Consider network delays and UI rendering time after login.

❓ framework
expert
3:00remaining
How to configure Playwright test to run only on Chromium with headless mode disabled?

You want to run Playwright tests only on Chromium browser and see the browser UI (headless mode off). Which configuration snippet in playwright.config.ts achieves this?

A
import { defineConfig } from '@playwright/test';

export default defineConfig({
  use: { browserName: 'chromium', headless: false }
});
B
export default {
  browsers: ['chromium'],
  headless: false
};
C
import { defineConfig, devices } from '@playwright/test';

export default defineConfig({
  projects: [
    {
      name: 'chromium',
      use: { ...devices['Desktop Chrome'], headless: false }
    }
  ]
});
D
import { defineConfig, devices } from '@playwright/test';

export default defineConfig({
  projects: [
    {
      name: 'chromium',
      use: { browserName: 'chromium', headless: true }
    }
  ]
});
Attempts:
2 left
💡 Hint

Check Playwright's project configuration and device presets.

Practice

(1/5)
1. What is the main purpose of E2E testing in a Next.js application using Playwright?
easy
A. To check only the backend API responses
B. To verify CSS styles and layout only
C. To test individual React components in isolation
D. To test the entire user experience from start to finish

Solution

  1. Step 1: Understand E2E testing scope

    E2E (end-to-end) testing simulates real user actions across the whole app, not just parts.
  2. Step 2: Identify Playwright's role

    Playwright automates browser actions to test full user flows, like clicking and filling forms.
  3. Final Answer:

    To test the entire user experience from start to finish -> Option D
  4. Quick Check:

    E2E testing = full user experience [OK]
Hint: E2E tests cover full user flows, not just parts [OK]
Common Mistakes:
  • Confusing E2E with unit or integration tests
  • Thinking E2E tests only check backend APIs
  • Assuming E2E tests verify only UI styles
2. Which of the following is the correct syntax to launch a browser and open a new page in Playwright for Next.js E2E testing?
easy
A. const browser = await chromium.launch(); const page = await browser.newPage();
B. const browser = await chromium.launch(); const page = browser.newPage();
C. const browser = playwright.launchChromium(); const page = browser.newPage();
D. const browser = await playwright.chromium.launch(); const page = await browser.newPage();

Solution

  1. Step 1: Recall Playwright import and usage

    Playwright's browser types like chromium are imported directly, so you use chromium.launch().
  2. Step 2: Check async usage and method names

    launch() and newPage() are async and must be awaited; syntax must match Playwright docs.
  3. Final Answer:

    const browser = await chromium.launch(); const page = await browser.newPage(); -> Option A
  4. Quick Check:

    Use 'await chromium.launch()' and 'await browser.newPage()' [OK]
Hint: Use 'await chromium.launch()' and 'await browser.newPage()' [OK]
Common Mistakes:
  • Using 'playwright.chromium.launch()' instead of 'chromium.launch()'
  • Missing 'await' keyword for async calls
  • Calling 'newPage()' directly on Playwright instead of browser
3. Given this Playwright test snippet for a Next.js app:
await page.goto('http://localhost:3000');
await page.click('button#submit');
const text = await page.textContent('div.result');
console.log(text);

What will be logged if the button triggers showing 'Success' inside div.result?
medium
A. Error: selector not found
B. undefined
C. 'Success'
D. '' (empty string)

Solution

  1. Step 1: Understand the test flow

    The test navigates to the page, clicks the submit button, then reads text from 'div.result'.
  2. Step 2: Analyze expected page behavior

    Clicking the button triggers showing 'Success' inside 'div.result', so textContent returns 'Success'.
  3. Final Answer:

    'Success' -> Option C
  4. Quick Check:

    textContent('div.result') = 'Success' after click [OK]
Hint: Click triggers text update; textContent reads updated text [OK]
Common Mistakes:
  • Assuming textContent returns undefined if element exists
  • Expecting error without checking if selector exists
  • Thinking textContent returns empty string if no text
4. You wrote this Playwright test for a Next.js app:
await page.goto('http://localhost:3000');
await page.click('button.submit');
await expect(page.locator('div.result')).toHaveText('Success');

But the test fails with timeout error. What is the most likely cause?
medium
A. The page.goto URL is incorrect
B. The selector 'button.submit' does not match any element
C. The assertion syntax is invalid
D. The test forgot to import 'expect' from Playwright

Solution

  1. Step 1: Analyze failure reason

    Timeout usually means the expected text never appeared in 'div.result'.
  2. Step 2: Check selector correctness

    If 'button.submit' selector is wrong (e.g., class is 'submit-btn'), click never happens, so text never changes.
  3. Final Answer:

    The selector 'button.submit' does not match any element -> Option B
  4. Quick Check:

    Wrong selector = no click = assertion timeout [OK]
Hint: Check selectors carefully; wrong selector blocks actions [OK]
Common Mistakes:
  • Assuming assertion syntax is wrong without checking selectors
  • Ignoring that click may fail silently if selector is wrong
  • Not verifying page URL correctness
5. You want to write a Playwright test for a Next.js app that fills a login form and verifies the welcome message. Which sequence of steps is correct?
hard
A. Go to login page, fill username and password, click submit, wait for welcome message, assert text
B. Click submit button, fill username and password, go to login page, assert welcome message
C. Fill username and password, assert welcome message, click submit, go to login page
D. Assert welcome message, go to login page, fill username and password, click submit

Solution

  1. Step 1: Understand logical user flow

    User must first visit login page, then fill form fields, then submit.
  2. Step 2: Verify post-submit behavior

    After submitting, wait for welcome message to appear, then assert its text.
  3. Final Answer:

    Go to login page, fill username and password, click submit, wait for welcome message, assert text -> Option A
  4. Quick Check:

    Follow user steps in order: visit, fill, submit, check [OK]
Hint: Follow real user steps: open page, fill, submit, then check [OK]
Common Mistakes:
  • Trying to assert before submitting the form
  • Clicking submit before filling fields
  • Checking messages before navigating to page
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