0
0
Svelteframework~20 mins

E2E testing with Playwright in Svelte - 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 code snippet?
Consider this Playwright test for a Svelte app login page. What will be the test execution result?
Svelte
import { test, expect } from '@playwright/test';

test('login button is enabled after input', async ({ page }) => {
  await page.goto('http://localhost:5173/login');
  await page.fill('input[name="username"]', 'user1');
  await page.fill('input[name="password"]', 'pass123');
  const isEnabled = await page.isEnabled('button#login-btn');
  expect(isEnabled).toBe(true);
});
ATest fails due to a timeout error on page.goto.
BTest fails because the selector 'button#login-btn' is invalid in Playwright.
CTest fails because page.fill does not work with input[name="username"].
DTest passes because the login button becomes enabled after filling inputs.
Attempts:
2 left
💡 Hint
Think about how Playwright interacts with form inputs and button states.
locator
intermediate
1:30remaining
Which locator correctly selects the submit button in a Svelte form?
You want to select the submit button in a Svelte form for Playwright testing. The button has class 'submit-btn' and text 'Submit'. Which locator is best?
Apage.locator('button.submit-btn:has-text("Submit")')
Bpage.locator('button.submit-btn')
Cpage.locator('button:has-text("Submit")')
Dpage.locator('button[role="submit"]')
Attempts:
2 left
💡 Hint
Combine class and visible text for precise selection.
assertion
advanced
1:30remaining
What assertion verifies a success message is visible after form submission?
After submitting a form, a success message with id 'success-msg' should appear. Which assertion correctly verifies this in Playwright?
Aawait expect(page.locator('#success-msg')).toBeVisible();
Bawait expect(page.locator('#success-msg')).toHaveText('Success');
Cawait expect(page.locator('#success-msg')).toContainText('Success');
Dawait expect(page.locator('#success-msg')).not.toBeHidden();
Attempts:
2 left
💡 Hint
Check for visibility explicitly.
🔧 Debug
advanced
2:00remaining
Why does this Playwright test fail with a timeout error?
This test fails with a timeout error. What is the most likely cause? Code: import { test, expect } from '@playwright/test'; test('check welcome text', async ({ page }) => { await page.goto('http://localhost:5173/home'); await expect(page.locator('text=Welcome')).toBeVisible({ timeout: 1000 }); });
AThe locator 'text=Welcome' is invalid syntax in Playwright.
BThe page does not contain the text 'Welcome' within 1 second timeout.
CThe page.goto URL is incorrect causing navigation failure.
DThe expect statement is missing await keyword.
Attempts:
2 left
💡 Hint
Consider the timeout duration and page content loading.
framework
expert
3:00remaining
How to implement a reusable Playwright test fixture for authenticated Svelte app sessions?
You want to create a Playwright fixture that logs in once and reuses the authenticated session for multiple tests in a Svelte app. Which approach is correct?
AUse beforeEach hook to login before every test without sharing session data.
BCall login steps inside each test to ensure fresh authentication every time.
CUse test.extend to create a fixture that performs login once and shares storageState across tests.
DStore username and password in environment variables and pass them directly to page.goto.
Attempts:
2 left
💡 Hint
Think about session reuse and test speed optimization.