Skip to content

Commit 32aabf7

Browse files
committed
Update code blocks and minor fixes
1 parent ad270ed commit 32aabf7

File tree

2 files changed

+38
-24
lines changed

2 files changed

+38
-24
lines changed

src/content/5/en/part5d.md

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ Before we move on, let's break the tests one more time. We notice that the execu
242242
When developing tests, it may be wiser to reduce the waiting time to a few seconds. According to the [documentation](https://playwright.dev/docs/test-timeouts), this can be done by changing the file _playwright.config.js_ as follows:
243243

244244
```js
245-
module.exports = defineConfig({
245+
export default defineConfig({
246246
// ...
247247
timeout: 3000, // highlight-line
248248
fullyParallel: false, // highlight-line
@@ -826,26 +826,32 @@ const loginWith = async (page, username, password) => {
826826
export { loginWith }
827827
```
828828
829-
The test becomes simpler and clearer:
829+
The tests becomes simpler and clearer:
830830
831831
```js
832-
const { loginWith } = require('./helper')
832+
const { test, describe, expect, beforeEach } = require('@playwright/test')
833+
const { loginWith } = require('./helper') // highlight-line
833834

834835
describe('Note app', () => {
836+
// ...
837+
835838
test('user can log in', async ({ page }) => {
836839
await loginWith(page, 'mluukkai', 'salainen') // highlight-line
837840
await expect(page.getByText('Matti Luukkainen logged in')).toBeVisible()
838841
})
839842

843+
test('login fails with wrong password', async ({ page }) => {
844+
await loginWith(page, 'mluukkai', 'wrong') // highlight-line
845+
846+
const errorDiv = page.locator('.error')
847+
// ...
848+
})
849+
840850
describe('when logged in', () => {
841851
beforeEach(async ({ page }) => {
842852
await loginWith(page, 'mluukkai', 'salainen') // highlight-line
843853
})
844854

845-
test('a new note can be created', () => {
846-
// ...
847-
})
848-
849855
// ...
850856
})
851857
```
@@ -899,7 +905,7 @@ const createNote = async (page, content) => {
899905
}
900906
// highlight-end
901907

902-
export { loginWith, createNote }
908+
export { loginWith, createNote } // highlight-line
903909
```
904910
905911
The tests are simplified as follows:
@@ -953,13 +959,14 @@ So we can replace all the addresses in the tests from _http://localhost:3001/api
953959
We can now define the _baseUrl_ for the application in the tests configuration file <i>playwright.config.js</i>:
954960
955961
```js
956-
module.exports = defineConfig({
962+
export default defineConfig({
957963
// ...
958964
use: {
959965
baseURL: 'http://localhost:5173',
966+
// ...
960967
},
961968
// ...
962-
}
969+
})
963970
```
964971
965972
All the commands in the tests that use the application url, e.g.
@@ -969,7 +976,7 @@ await page.goto('http://localhost:5173')
969976
await page.post('http://localhost:5173/api/testing/reset')
970977
```
971978
972-
can be transformed into:
979+
can now be transformed into:
973980
974981
```js
975982
await page.goto('/')

src/content/5/fi/osa5d.md

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ Ennen kuin mennään eteenpäin, rikotaan testit vielä kertaalleen. Huomaamme,
206206
Testejä kehitettäessä voi olla viisaampaa pienentää odotettavaa aikaa muutamaan sekuntiin. [Dokumentaation](https://playwright.dev/docs/test-timeouts) mukaan tämä onnistuu muuttamalla tiedostoa _playwright.config.js_ seuraavasti:
207207

208208
```js
209-
module.exports = defineConfig({
209+
export default defineConfig({
210210
// ...
211211
timeout: 3000, // highlight-line
212212
fullyParallel: false, // highlight-line
@@ -784,26 +784,32 @@ const loginWith = async (page, username, password) => {
784784
export { loginWith }
785785
```
786786
787-
Testi yksinkertaistuu ja selkeytyy:
787+
Testit yksinkertaistuvat ja selkeytyvät:
788788
789789
```js
790-
const { loginWith } = require('./helper')
790+
const { test, describe, expect, beforeEach } = require('@playwright/test')
791+
const { loginWith } = require('./helper') // highlight-line
791792

792793
describe('Note app', () => {
794+
// ...
795+
793796
test('user can log in', async ({ page }) => {
794-
await loginWith(page, 'mluukkai', 'salainen')
797+
await loginWith(page, 'mluukkai', 'salainen') // highlight-line
795798
await expect(page.getByText('Matti Luukkainen logged in')).toBeVisible()
796799
})
797800

798-
describe('when logged in', () => {
799-
beforeEach(async ({ page }) => {
800-
await loginWith(page, 'mluukkai', 'salainen')
801-
})
801+
test('login fails with wrong password', async ({ page }) => {
802+
await loginWith(page, 'mluukkai', 'wrong') // highlight-line
802803

803-
test('a new note can be created', () => {
804+
const errorDiv = page.locator('.error')
804805
// ...
805806
})
806807

808+
describe('when logged in', () => {
809+
beforeEach(async ({ page }) => {
810+
await loginWith(page, 'mluukkai', 'salainen') // highlight-line
811+
})
812+
807813
// ...
808814
})
809815
```
@@ -857,7 +863,7 @@ const createNote = async (page, content) => {
857863
}
858864
// highlight-end
859865

860-
export { loginWith, createNote }
866+
export { loginWith, createNote } // highlight-line
861867
```
862868
863869
Testi yksinkertaistuu seuraavasti:
@@ -911,13 +917,14 @@ Voimme siis korvata testeissä kaikki osoitteet _http://localhost:3001/api/..._
911917
Voimme nyt määrittellä sovellukselle _baseUrl_:in testien konfiguraatiotiedostoon <i>playwright.config.js</i>:
912918
913919
```js
914-
module.exports = defineConfig({
920+
export default defineConfig({
915921
// ...
916922
use: {
917923
baseURL: 'http://localhost:5173',
924+
// ...
918925
},
919926
// ...
920-
}
927+
})
921928
```
922929
923930
Kaikki testeissä olevat sovelluksen urlia käyttävät komennot esim.
@@ -927,7 +934,7 @@ await page.goto('http://localhost:5173')
927934
await page.post('http://localhost:5173/api/tests/reset')
928935
```
929936
930-
voidaan muuttaa muotoon
937+
voidaan nyt muuttaa muotoon
931938
932939
```js
933940
await page.goto('/')

0 commit comments

Comments
 (0)