You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 02c8d0a
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: tutorial/stage-0-baseline/playwright-e2e-from-cowboy-to-confidence.mdx
+9-10Lines changed: 9 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
---
2
2
title: Playwright e2e testing - from cowboy to confidence
3
-
description: Outline of the Endform saas tutorial, where we will take an untested saas application and build a Playwright test suite for it.
3
+
description: Outline of the Endform SaaS tutorial, where we will take an untested SaaS application and build a Playwright test suite for it.
4
4
sidebar:
5
5
order: 1
6
6
---
@@ -15,18 +15,18 @@ _Maybe you're a bit of a cowboy._
15
15
16
16
Maybe you already have unit and integration tests, but you still keep running through user flows manually in your browser.
17
17
18
-
Or you're a more seasoned Playwright tester, but you're looking to brush up on the latest and greatest, and improve your setup.
18
+
Or you're a more seasoned Playwright tester, but you're looking to brush up on the latest and greatest, and improve your setup.
19
19
20
-
In this tutorial, we will end-to-end test a realistic software as a service application from scratch.
21
-
We will cover all of the Playwright features that you need to be productive in your day to day.
20
+
In this tutorial, we will end-to-end test a realistic software-as-a-service application from scratch.
21
+
We will cover all of the Playwright features that you need to be productive in your day-to-day work.
22
22
23
23
So come along, and let's get you from cowboy to confidence.
24
24
25
25
## Source code
26
26
27
-
The full repository for this tutorial can be found [here](https://github.com/endformdev/playwright-tutorial).
27
+
The full repository for this tutorial can be found [here](https://github.com/endformdev/playwright-tutorial).
28
28
29
-
The repository contains a software as a service application that has login, logout, user modification, team management and checkout functionality.
29
+
The repository contains a software-as-a-service application that has login, logout, user modification, team management, and checkout functionality.
30
30
The application is built with Next.js and can either be run locally from your command line or you can test against our [pre-deployed version of it](https://endform-playwright-tutorial.vercel.app).
31
31
32
32
## Getting started with the tutorial repository
@@ -36,7 +36,7 @@ To get started, you will need to:
36
36
-[Clone the repository](https://github.com/endformdev/playwright-tutorial): `git clone https://github.com/endformdev/playwright-tutorial && cd playwright-tutorial`
37
37
- Make sure you have [`pnpm` installed on your system](https://pnpm.io/installation#using-corepack)
38
38
- Install the dependencies: `pnpm install`
39
-
-Checkout the branch for the stage you want to start from, for example: `git checkout stage-0-baseline`
39
+
-Check out the branch for the stage you want to start from, for example: `git checkout stage-0-baseline`
40
40
41
41
We will be testing against a realistic dummy application.
42
42
You can either:
@@ -53,12 +53,12 @@ You can either:
53
53
## Choose where to start
54
54
55
55
Each step of the tutorial has a [branch associated with it](https://github.com/endformdev/playwright-tutorial/branches), with all of the work included from the previous tutorial steps.
56
-
You can choose to start from the beginning, or you can start from a specific step, depending on what you're interested in and what your previous experience with Playwright is.
56
+
You can choose to start from the beginning, or you can start from a specific step, depending on what you're interested in and what your previous experience with Playwright is.
57
57
58
58
Here's what we'll cover in each step:
59
59
60
60
<LinkCard
61
-
title="Practical playwright setup"
61
+
title="Practical Playwright setup"
62
62
description="Setting up a Playwright project to make your future testing life easier."
63
63
href="/docs/tutorial/practical-playwright-setup"
64
64
/>
@@ -81,4 +81,3 @@ Here's what we'll cover in each step:
In this part of the tutorial, we will both set up a Playwright project from scratch, but we will also learn to use the most important features to be more productive with Playwright when using a real-world application.
12
+
In this part of the tutorial, we will set up a Playwright project from scratch and learn to use the most important features for being more productive with Playwright in a real-world application.
13
13
14
14
Some Playwright features we will cover include:
15
15
@@ -20,7 +20,7 @@ Some Playwright features we will cover include:
20
20
Let's get started!
21
21
22
22
<Aside>
23
-
To start from this step, checkout the [`stage-0-baseline` branch](https://github.com/endformdev/playwright-tutorial/tree/stage-0-baseline) of the [tutorial repository](https://github.com/endformdev/playwright-tutorial).
23
+
To start from this step, check out the [`stage-0-baseline` branch](https://github.com/endformdev/playwright-tutorial/tree/stage-0-baseline) of the [tutorial repository](https://github.com/endformdev/playwright-tutorial).
24
24
For more information about getting started with the tutorial repository, go [here](/docs/tutorial/playwright-e2e-from-cowboy-to-confidence#getting-started-with-the-tutorial-repository).
25
25
</Aside>
26
26
@@ -62,7 +62,7 @@ projects: [
62
62
name: "chromium",
63
63
use: { ...devices["Desktop Chrome"] },
64
64
}
65
-
// Remove the other firefox and webkit projects
65
+
// Remove the other Firefox and WebKit projects
66
66
]
67
67
```
68
68
@@ -71,7 +71,7 @@ projects: [
71
71
Let's check that this works by modifying the `example.spec.ts` test file in the `tests` directory.
72
72
73
73
- Remove the second test "get started link"
74
-
- Modify the first test to go to the default url`await page.goto("/")`
74
+
- Modify the first test to go to the default URL`await page.goto("/")`
75
75
- Modify the expectation to check for our page title `/Playwright Tutorial/`
76
76
- Watch your test run `pnpm playwright test --debug`
77
77
@@ -80,7 +80,7 @@ When you run Playwright in debug mode for the first time, the browser will open
80
80
</Aside>
81
81
82
82
You can watch your test step by step by using the "step over" button.
83
-
<Imagesrc={StepOverDebug}alt="Step over button in Playwrights inspector"width={600} />
83
+
<Imagesrc={StepOverDebug}alt="Step over button in Playwright's inspector"width={600} />
84
84
85
85
## Alternatives for creating temporary test data (like users)
86
86
@@ -89,20 +89,20 @@ Almost all of the tests that you will end up making will require some amount of
89
89
There are two schools of thought about how to create this test data.
90
90
Either you can create it by using the browser and clicking through your application to create that data, or you can use either your public API or create internal APIs in order to create this data more efficiently.
91
91
92
-
Playwright has two methods of globally setting up test data before your suite runs. Project dependencies, which runs a browser, or global setup, which is more like a simple script more suited to API calls.
92
+
Playwright has two methods of globally setting up test data before your suite runs: project dependencies, which run a browser, or global setup, which is more like a simple script better suited to API calls.
93
93
94
-
If we look at [Playwrights documentation](https://playwright.dev/docs/test-global-setup-teardown), we can see that it slightly prefers using project dependencies to globally set up and tear down test data.
95
-
The table in the documentation there outlines how using project dependencies provides more visibility into how the set up and tear down steps work.
94
+
If we look at [Playwright's documentation](https://playwright.dev/docs/test-global-setup-teardown), we can see that it slightly prefers using project dependencies to globally set up and tear down test data.
95
+
The table in the documentation there outlines how using project dependencies provides more visibility into how the setup and teardown steps work.
96
96
97
97
In our experience, having an API endpoint available to create data (like test users), instead of requiring a whole browser, makes your Playwright project more flexible long term.
98
98
Initially you will feel like one user is enough, in which case the browser-based setup method is the simplest.
99
99
However, further down the line, you will likely need to make several users, some for cases where users collide such as your "delete user" flow.
100
100
When this happens, you will find that your API endpoints will make it much easier to create these tests.
101
101
102
-
If you learn to create and use API endpoints like this, it will be much easier for you to extend them to create more kinds of useful test data, such as organisations or organisation memberships.
103
-
This will really take your ability to test end to end test your application to a whole new level.
102
+
If you learn to create and use API endpoints like this, it will be much easier for you to extend them to create more kinds of useful test data, such as organizations or organization memberships.
103
+
This will really take your ability to test your application end-to-end to a whole new level.
104
104
105
-
Today we will learn to use both kinds of set up approaches.
105
+
Today we will learn to use both kinds of setup approaches.
106
106
107
107
### Setup & teardown with Playwright project dependencies
108
108
@@ -171,7 +171,7 @@ export default defineConfig({
171
171
</TabItem>
172
172
</Tabs>
173
173
174
-
We'll talk more about generating tests in the next step, so here's the completed setup / teardonwn and modified example tests to copy for now.
174
+
We'll talk more about generating tests in the next step, so here's the completed setup / teardown and modified example tests to copy for now.
175
175
176
176
177
177
<Tabs>
@@ -299,7 +299,7 @@ export default defineConfig({
299
299
300
300
### Creating / deleting users through an API
301
301
302
-
Let's explore the alternative to creating users through the browser, which is to create and use API endpoints for our test data.
302
+
Let's explore the alternative to creating users through the browser, which is to create and use API endpoints for our test data.
303
303
304
304
Let's make ourselves an internal API endpoint for our tests to use.
305
305
@@ -338,7 +338,7 @@ export async function DELETE(request: Request) {
338
338
}
339
339
```
340
340
341
-
Let's set up a global setup and global teardown script to use these API endpoints.
341
+
Let's set up a global setup and global teardown script to use these API endpoints.
342
342
First we need to modify the `playwright.config.ts` file.
At this point in time, we don't just have a basic playwright project set up, but we have a very practical playwright set up for our future testing needs.
527
+
At this point, we don't just have a basic Playwright project set up, but we have a very practical Playwright setup for our future testing needs.
528
528
529
529
We have:
530
530
531
-
- A file structure and config file for running a Playwright suite in typescript
531
+
- A file structure and config file for running a Playwright suite in TypeScript
532
532
- A set of projects that depend on each other where we can create shared test data
533
-
- API endpoints for easily creating more test data when needed
533
+
- API endpoints for easily creating more test data when needed
Copy file name to clipboardExpand all lines: tutorial/stage-2-generated-tests/generate-tests-playwright-mcp.mdx
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ import CursorActivityTodo from "../../../assets/cursor-activity-todo.png";
12
12
In this guide, we will use the Playwright MCP to generate tests for your application.
13
13
14
14
<Aside>
15
-
To start from this step, checkout the [`stage-1-setup` branch](https://github.com/endformdev/playwright-tutorial/tree/stage-1-setup) of the [tutorial repository](https://github.com/endformdev/playwright-tutorial).
15
+
To start from this step, check out the [`stage-1-setup` branch](https://github.com/endformdev/playwright-tutorial/tree/stage-1-setup) of the [tutorial repository](https://github.com/endformdev/playwright-tutorial).
16
16
For more information about getting started with the tutorial repository, go [here](/docs/tutorial/playwright-e2e-from-cowboy-to-confidence#getting-started-with-the-tutorial-repository).
17
17
</Aside>
18
18
@@ -41,7 +41,7 @@ For example for Cursor, your `mcp.json` file could look like this:
41
41
42
42
## Authenticating with the Playwright MCP Server
43
43
44
-
At the time of writing, the Playwright MCP server doesn't have support for the projects or storage states that we set up in our Playwright config in the previous step.
44
+
At the time of writing, the Playwright MCP server doesn't have support for the projects or storage states that we set up in our Playwright config in the previous step.
45
45
46
46
You can achieve something similar by using the following flags to the MCP server:
47
47
@@ -431,14 +431,14 @@ Other classic problems with the tests that the AI generated:
431
431
432
432
- Strict mode violations / more than one element on the page that matches a locator
433
433
- Adding manual timeouts to tests instead of crafting good assertions
434
-
- Hardcoding urls instead of using relative paths
435
-
- Not using Playwright `test.step` to label steps in the test & excessive comments
434
+
- Hardcoding URLs instead of using relative paths
435
+
- Not using Playwright `test.step` to label steps in the test and using excessive comments
436
436
437
437
## Areas for improvement for our test setup at the moment
438
438
439
439
It's been fantastic to generate a few tests using this method.
440
-
When creating this tutorial, I was able to go from one test to ten tests in the space of just an hour or two, but that also should give us a little space to reflect over what we've done.
440
+
When creating this tutorial, I was able to go from one test to ten tests in the space of just an hour or two, but that should also give us a little space to reflect on what we've done.
441
441
442
442
At the moment:
443
443
444
-
-Have lots of duplicated selectors in tests where better practice would be to have [page object models](https://playwright.dev/docs/pom) so that we can reduce the amount of places we need to update selectors when changes are needed.
444
+
-We have lots of duplicated selectors in tests where better practice would be to have [page object models](https://playwright.dev/docs/pom), so that we can reduce the number of places we need to update selectors when changes are needed.
In this guide, we will use endform to speed up your test suite.
12
+
In this guide, we will use Endform to speed up your test suite.
13
13
14
14
<Aside>
15
-
To start from this step, checkout the [`stage-2-generated-tests` branch](https://github.com/endformdev/playwright-tutorial/tree/stage-2-generated-tests) of the [tutorial repository](https://github.com/endformdev/playwright-tutorial).
15
+
To start from this step, check out the [`stage-2-generated-tests` branch](https://github.com/endformdev/playwright-tutorial/tree/stage-2-generated-tests) of the [tutorial repository](https://github.com/endformdev/playwright-tutorial).
16
16
For more information about getting started with the tutorial repository, go [here](/docs/tutorial/playwright-e2e-from-cowboy-to-confidence#getting-started-with-the-tutorial-repository).
17
17
</Aside>
18
18
19
-
At this point in time, we have a pretty decent Playwriht end to end testing suite that can test most of the dummy features in this application.
20
-
We can test complex multiuser flows like inviting, and we have the ability to create new users on demand when the user data conflicts with other tests.
19
+
At this point, we have a pretty decent Playwright end-to-end testing suite that can test most of the dummy features in this application.
20
+
We can test complex multi-user flows like inviting, and we have the ability to create new users on demand when the user data conflicts with other tests.
21
21
22
-
Since this a very simple application, our tests are thankfully very fast to run. Let's explore their performance.
22
+
Since this is a very simple application, our tests are thankfully very fast to run. Let's explore their performance.
23
23
24
24
## Running the tests
25
25
@@ -35,9 +35,9 @@ Let's try running the tests with Endform also to get a benchmark:
35
35
pnpm endform test
36
36
```
37
37
38
-
On my machine (M2 Macbook Pro), the tests ran in 20 seconds with Playwright, and 25 seconds with Endform.
38
+
On my machine (M2 MacBook Pro), the tests ran in 20 seconds with Playwright and 25 seconds with Endform.
39
39
40
-
With these very fast, very small, and few tests - uploading and running the tests on Endform's remote runners aren't giving us much of a speedup.
40
+
With these few, very fast tests, uploading and running the tests on Endform's remote runners isn't giving us much of a speedup.
41
41
42
42
## Cranking up the heat
43
43
@@ -72,13 +72,12 @@ while Endform will keep the speed constant.
72
72
73
73
### Other influential factors
74
74
75
-
This is one case of the speed of this particular suite, but lots of things have an impact on the speed of a suite.
76
-
Like:
75
+
This is one case of the speed of this particular suite, but lots of things have an impact on suite speed, including:
77
76
78
77
- How reliable or flaky the tests are
79
78
- How long the tests take to run
80
79
- How slow the slowest test is
81
-
- How performant the app the tests are run against is
80
+
- How performant the app under test is
82
81
83
82
We think that we have the fastest Playwright test runner on the market, but we're really curious to hear what your experience in running Endform versus Playwright in your test suite is like.
84
83
@@ -126,8 +125,8 @@ jobs:
126
125
127
126
Here we used the [`repository_dispatch` event](https://vercel.com/docs/git/vercel-for-github#repository-dispatch-events) to trigger the workflow when the Vercel deployment is successful.
128
127
129
-
Some other thigns you could try are:
128
+
Some other things you could try are:
130
129
131
130
- Just trigger on commits to the main branch
132
131
- Triggering on pull requests
133
-
- Sending a message to a Slack channel when the tests are successful or fail
132
+
- Sending a message to a Slack channel when the tests are successful or fail
0 commit comments