0
0
NextJSframework~20 mins

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

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