E2E testing checks if your whole app works well from a user's view. Playwright helps you do this by controlling a browser to test your app automatically.
You want to make sure clicking buttons and filling forms works as expected.
You need to test your app on different browsers like Chrome and Firefox.
You want to catch bugs before users find them by simulating real user actions.
You want to test navigation between pages in your Svelte app.
You want to check that your app looks and behaves correctly after changes.
This test opens the Svelte app, clicks a button that increases a counter, and checks if the counter shows '1'.
Svelte
import { test, expect } from'@playwright/test';
test('E2E test for Svelte app button click', async ({ page }) => {
// Open the appawait page.goto('http://localhost:3000');
// Click the button with id 'increment'await page.click('button#increment');
// Check if the counter text updated to '1'await expect(page.locator('span#count')).toHaveText('1');
});
OutputSuccess
Important Notes
Use clear and stable selectors like IDs or data-test attributes for locating elements.
Run your app locally before running Playwright tests to avoid connection errors.
Playwright can test on multiple browsers; specify them in the config for wider coverage.
Summary
E2E testing checks your app from the user's point of view.
Playwright automates browsers to run these tests easily.
Write tests that open pages, interact with elements, and check results.
Practice
(1/5)
1. What is the main purpose of E2E testing with Playwright in a Svelte app?
easy
A. To test the app from the user's point of view by automating browser actions
B. To check only the backend API responses without UI interaction
C. To write unit tests for individual Svelte components
D. To manually test the app by clicking buttons in the browser
Solution
Step 1: Understand E2E testing purpose
E2E testing simulates real user actions to verify the whole app works correctly.
Step 2: Role of Playwright in E2E testing
Playwright automates browsers to perform user-like actions and check results automatically.
Final Answer:
To test the app from the user's point of view by automating browser actions -> Option A
Quick Check:
E2E testing = user perspective automation [OK]
Hint: E2E tests mimic user actions in a real browser [OK]
Common Mistakes:
Confusing E2E with unit or API testing
Thinking E2E tests run only backend checks
Assuming manual testing is E2E automation
2. Which of the following is the correct way to launch a browser and open a page in Playwright for a Svelte app test?
Why might this test fail even if the button click works?
medium
A. The selector 'button.submit' is incorrect if the button has id 'submit', not class 'submit'
B. The expect assertion syntax is invalid and will cause a syntax error
C. page.goto is missing await causing navigation failure
D. toHaveText cannot be used with page.locator
Solution
Step 1: Check selector correctness
'button.submit' selects a button with class 'submit', but if button has id 'submit', selector should be 'button#submit'.
Step 2: Verify assertion and syntax
expect with toHaveText on page.locator is valid syntax in Playwright.
Final Answer:
The selector 'button.submit' is incorrect if the button has id 'submit', not class 'submit' -> Option A
Quick Check:
Selector must match element attribute type [OK]
Hint: Match selector type: # for id, . for class [OK]
Common Mistakes:
Using class selector when element has id
Missing await on async calls
Misunderstanding Playwright assertion syntax
5. You want to write a Playwright test for a Svelte app that fills a form with name and email, submits it, and checks for a success message. Which sequence of actions is correct?