-
-
Notifications
You must be signed in to change notification settings - Fork 33
Playwright end-to-end testing #896
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 9 commits
fd7217d
6d78d13
352e23e
236d9f0
488e3cb
b1f640d
994b54b
393a092
6c59b9d
36fcd4a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,35 @@ | ||||||
| # Playwright Basics | ||||||
|
|
||||||
| See the official documentation at http://playwright.dev/docs/intro | ||||||
|
|
||||||
| Playwright is another testing framework similar to Vitest in some respects but largely different in its end-to-end approach. Playwright has functions called [locators](http://playwright.dev/docs/locators) to locate page elements and more functions called [actions](https://playwright.dev/docs/input) to interact with them. | ||||||
|
|
||||||
| Although you can locate many items based on text in their content, classes, or css, it is often preferable to give them test ids to refer to. This is done by adding `data-testid="your-test-id"` in their Svelte HTML tag. Then use: | ||||||
|
|
||||||
| `const myItem = await page.getByTestId("your-test-id");` | ||||||
|
|
||||||
| You can install the Playwright plugin for VSCode and run individual tests using the "play" symbol appearing next to each test block (note the app itself must already be running locally). | ||||||
|
|
||||||
| - Make sure your test file ends with `.spec.ts` (or .js for JavaScript). | ||||||
| If you're testing `foo.ts`, you'd probably name the test file `foo.spec.ts`. | ||||||
| - Use the `test` function to write an end-to-end test | ||||||
| - Within each test, use `expect` to provide an assertion. | ||||||
|
|
||||||
| Here's what a test generally looks like: | ||||||
|
|
||||||
| ```js | ||||||
| test('Test Navigation', async ({ page }) => { | ||||||
| await page.goto('http://localhost:5173/'); | ||||||
|
|
||||||
| await page.getByTestId("about-icon").click(); | ||||||
| await expect(page.getByTestId("title")).toHaveText("About"); | ||||||
| }); | ||||||
| ``` | ||||||
|
Comment on lines
+20
to
+27
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Include the correct import line in the sample and remove the unnecessary await ```js
+import { test, expect } from '@playwright/test';
test('Test Navigation', async ({ page }) => {
await page.goto('http://localhost:5173/');
- await page.getByTestId("about-icon").click();
+ await page.getByTestId("about-icon").click();
await expect(page.getByTestId("title")).toHaveText("About");
});In docs/test/e2e-testing-basics.md around lines 20 to 27, the sample is missing |
||||||
|
|
||||||
| Gotchas: | ||||||
|
|
||||||
| - Make sure you import `test`, and `expect` from playwright, not from node.test or vitest. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct import guidance: import from @playwright/test (not “playwright”) -- Make sure you import `test`, and `expect` from playwright, not from node.test or vitest.
+- Make sure you import `test` and `expect` from `@playwright/test`, not from Node’s test module or Vitest.📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
|
|
||||||
| # Running Tests | ||||||
|
|
||||||
| Run `npx playwright test` in a terminal window to run all the tests in the project. Currently, Playwright does not start the local dev app before testing, so that must be done in another thread first (such as `npm run dev`). | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don’t await getByTestId; it returns a Locator, not a Promise
Using await here is incorrect and may confuse readers. Also, capitalize CSS.
📝 Committable suggestion
🤖 Prompt for AI Agents