Skip to content

Commit d9e583b

Browse files
committed
01/01: add exercise
1 parent a4e06f2 commit d9e583b

31 files changed

+1227
-253
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ data.db
1313
__screenshots__
1414
*.sqlite
1515
test-profiles
16+
test-results
1617
coverage
1718
.vitest-reports
1819
*.DS_Store

epicshop/generate-tests.js

Lines changed: 0 additions & 72 deletions
This file was deleted.

epicshop/setup.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,6 @@ if (major < 8 || (major === 8 && minor < 16)) {
3434
throw new Error('npm version is out of date')
3535
}
3636

37-
// Generate test suites for exercises.
38-
{
39-
const result = spawnSync('node ./generate-tests.js', {
40-
cwd: new URL('.', import.meta.url),
41-
stdio: 'inherit',
42-
shell: true,
43-
})
44-
45-
if (result.status !== 0) {
46-
process.exit(result.status)
47-
}
48-
}
49-
5037
{
5138
const command =
5239
'npx --yes "https://gist.github.com/kentcdodds/bb452ffe53a5caa3600197e1d8005733" -q'
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Install & configure
2+
3+
## Your task
4+
5+
In this first exercise, your task is to install and configure Playwright from scratch and write a simple end-to-end test. Follow 🐨 Kody who will guide you through the steps you need to complete.
6+
7+
🐨 First, install [`@playwright/test`](https://npmjs.com/package/@playwright/test) as a dependency in your project:
8+
9+
```sh
10+
npm i @playwright/test --save-dev
11+
```
12+
13+
🐨 Then, install the binaries of the browsers you want to use for automated tests. In this workshop, we will be using Chromium for browser automation. Install it using this command:
14+
15+
```sh
16+
npx playwright install --with-deps chromium
17+
```
18+
19+
🐨 Next, create `playwright.config.ts` file at the root of your project. This is Playwright's configuration file. You will use it to set up Playwright in the way that makes sense for your project.
20+
21+
🐨 In `package.json`, create a new script called `test:e2e`. You will use this script to run your end-to-end tests at the end of this exercise. Use the `playwright test` command as the value for that script.
22+
23+
🐨 Create a directory called `tests`. In that directory, create a new test file called `epicweb.test.ts`.
24+
25+
🐨 In the `epicweb.test.ts` file, write a single test case called "displays the page heading".
26+
27+
```ts
28+
import { test, expect } from '@playwright/test'
29+
30+
test('test title', async ({ page }) => {
31+
// ...test steps here.
32+
})
33+
```
34+
35+
The purpose of this test will be to verify that a this heading is displayed at the Epic Web's homepage.
36+
37+
![](/assets/01-01-epicweb-heading.png)
38+
39+
To do that, your test would have to perform a series of steps:
40+
41+
1. Navigate to `https://epicweb.dev/` using the `page.goto()` function (pay attention that it returns a promise!).
42+
1. Find the heading on the page by its _role_ and _accessible name_ using the `page.getByRole(role, { name })` function.
43+
44+
> If you are unsure where to find element's role and accessible name, open your DevTools, head to the "Elements" tab, and select the "Accessibility" nested tab to the right (in the same tab list as "Styles" and "Computed"). Select the element on the page and see its accessible attributes, including its role and accessible name.
45+
46+
3. Assert that the heading element is visible on the page via `await expect(element).toBeVisible()`.
47+
48+
🐨 Finally, run this test via `npm run test:e2e` in the terminal. You should see it passing.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"name": "exercises_01.basics_01.problem.install-and-configure"
3+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"include": ["**/*.ts"],
3+
"exclude": ["node_modules"],
4+
"compilerOptions": {
5+
"strict": true,
6+
"skipLibCheck": true,
7+
"target": "esnext",
8+
"module": "esnext",
9+
"moduleResolution": "node"
10+
}
11+
}

exercises/01.basics/01.solution.getting-started/README.mdx

Lines changed: 0 additions & 16 deletions
This file was deleted.

exercises/01.basics/01.solution.getting-started/package.json

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Install & configure
2+
3+
Good job! 👏
4+
5+
Please wait for the others to finish so we could go through the solution to this exercise together.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "exercises_01.basics_01.solution.install-and-configure",
3+
"scripts": {
4+
"test:e2e": "playwright test"
5+
},
6+
"devDependencies": {
7+
"@playwright/test": "^1.53.2"
8+
}
9+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { defineConfig, devices } from '@playwright/test'
2+
3+
export default defineConfig({
4+
projects: [
5+
{
6+
name: 'chromium',
7+
use: {
8+
...devices['Desktop Chrome'],
9+
},
10+
},
11+
],
12+
fullyParallel: true,
13+
forbidOnly: !!process.env.CI,
14+
})
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { test, expect } from '@playwright/test'
2+
3+
test('displays the page heading', async ({ page }) => {
4+
await page.goto('https://epicweb.dev/')
5+
6+
await expect(
7+
page.getByRole('heading', {
8+
name: 'Full Stack Workshop Training for Professional Web Developers',
9+
}),
10+
).toBeVisible()
11+
})
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"include": ["**/*.ts"],
3+
"exclude": ["node_modules"],
4+
"compilerOptions": {
5+
"strict": true,
6+
"skipLibCheck": true,
7+
"target": "esnext",
8+
"module": "esnext",
9+
"moduleResolution": "node"
10+
}
11+
}

0 commit comments

Comments
 (0)