Pratique du Shadowing: Playwright API Testing with TypeScript (from scratch in 10 minutes) - Apprendre l'anglais à l'oral avec la vidéo

Choisissez un mode d'entraînement

Chaque mode ouvre une salle d'entraînement en plein écran.

135 phrases
Si les phrases sont trop courtes ou trop longues, cliquez sur Edit pour les ajuster.
1
You want to automate APIs with Playwright but don't know where to start?
2
So let me show you how to do that.
3
It's actually very simple.
4
So first of all, navigate to nodejs .org, you will need to install Node .js.
5
So click on install
6
Node .js, download it and install on your computer.
7
After that, create a new empty folder anywhere on your computer and open this folder in new terminal.
8
Then run this command in this terminal npm init playwright at latest.
9
After execution of this command just answer everything by default yes
10
so playwright will ask you do you want typescript yes do you want to use test folder yes
11
and so on and so forth just click enter enter enter
12
and after you've done this you will have a sample project generated by the playwright
13
that would look like this open it in visual studio code
14
and you pretty much ready to go
15
so under the test folder you will see example .spec .ts that's the sample test file
16
that you can start with test number one test number two
17
this is the body number one body number two
18
you can see this test is configured to run ui test playwright is using a thing called fixture page fixture
19
so this page fixture is responsible for opening a new browser page
20
and do whatever operations you need on this browser page
21
but for api automation we don't need page so for
22
that we have a different fixture which is called request fixture
23
and with the request fixture you can make api request
24
so using this example let's make a simple simple get request
25
and i will show you how to use this fixture so we don't need page fixture.
26
I just remove it and I remove all this stuff.
27
We don't need it.
28
I'm going to keep this test as our placeholder.
29
So where would you start?
30
Await request dot and then you have methods inside of the request.
31
So if you want to make get request, you call get method.
32
If you want to make post request, you make post method.
33
Patch, put, delete and so on.
34
So let's start with the get request
35
which example we will use for this demonstration here conduit bonder
36
academy let's look into the networking tab for this app
37
and take the very first api request for example for the tags endpoints this is a get request tags endpoint
38
so let's use it as our demo i take the tags
39
and inside of get request i just paste this url that i want to call and that's it
40
Look, if I run it, it's already working.
41
128 milliseconds took to run this single line.
42
So Playwright already sending requests.
43
Now we need to process the response.
44
Then you assign the result to some constant or variable, for example, response equals to.
45
And then from this response, I need to extract the JSON object.
46
So I type const response object equals to await response dot method json.
47
So with the method json, you can get the json object that is coming back.
48
And let's print it out to the console.
49
Console dot log.
50
And I print out the response object and running this test.
51
Running this test.
52
Here we go we have a response object that is printed out and after
53
that we can make the assertions to make assertions in the playwright you can use a built -in assertion library
54
which is expect and we can call our response object
55
that has property tags inside tags and this is the array
56
so i take the first value of array we see it should be a test
57
and i type to equal test and i run this test again
58
and test pass successfully and let's write one more validation for example expect
59
that our response object tags and the amount of text we have 10 values
60
so let's to have for example length of 10.
61
Like this and then running this test again and this test passed successfully.
62
If I mess with this test around and let's say I change to 9
63
and run this test and the test failed expectedly.
64
Look received length 10 but expected length 9.
65
So assertion working successfully and test working successfully.
66
So that's well that's the approach.
67
You basically have three steps in any API test.
68
First you make a request, second you make the extraction of the JSON object with the JSON method
69
and the third step is making the validations of your response.
70
That's basically
71
whole thing about api testing you send request validate response send request validate response that's it
72
and let me show you just one more example
73
this was the very simple get request let me show you how to make a post
74
or put request i copy this thing and for example sample post request
75
so the same thing here we need to change get to post
76
because it will be a post request
77
and let's find in our application example for the post request
78
so I will create a new article let me type any random values right click inspect network publish the article
79
and this is the request
80
for the post request so post request this is the url
81
and now i just simply copying the values inside of our request
82
so this is the post request for the post request we need a payload as well
83
and authorization header because this is authorized request
84
so i need to paste the headers into authorization
85
so where would you put
86
that stuff put the comma over here after the url then start a new object
87
and within this new object you can put different parameters
88
so such as headers this is another object
89
and we will use authorization no let's do this authorization
90
and the value for authorization will be going back this is the token paste the token
91
and then wow that's a huge token okay
92
and then we need to add uh request object
93
and in playwright it's called as data so i paste this object
94
and let me find this payload over here
95
so this is my payload i'm copying it here going back
96
and pasting it right here so i guess that's it so url authorization header,
97
payload that I'm sending to the API and we can send the request.
98
Let me send like test, test will be title for the article, response object.
99
I will remove the assertions because response will be different and we will see the response object that should,
100
at least we should see the response object sending the request and the request was successful.
101
You can see the new article was created.
102
If I go back to the test application, click over here.
103
Here we go.
104
Test test article using API was created.
105
Well guys and that's pretty much it.
106
This is how easy you create your API test in Playwright.
107
You call get, post, put or delete methods depending on operation that you want to do.
108
For the get request it's very very simple.
109
Just send request, validate response, make the assertions for the post request you need maybe headers
110
and data that you send as your payload in the same way.
111
You extract the JSON and then validate the response.
112
You can also chain the commands. For example, we send the post request and then after
113
that we can send get request to validate that the article that was created before is there.
114
But that's more about the scenarios, right?
115
That's not about the scripting anymore.
116
It's more about scenarios.
117
So yeah, it's very, very simple.
118
So if have just a handful of tests to automate, just go with this route, automate those scenarios and you are done.
119
If you need to automate more than that and your application is more sophisticated, you need to generate some test data,
120
make a schema validation and all that fun stuff, you can build some other test frameworks around the Playwright using this approach.
121
And for example, I built my own approach to API testing using Playwright using this approach.
122
For example, you provide path, you provide parameters that way, you make a get request with a custom getter and all that stuff.
123
And then your test would look nicely organized.
124
I have a custom should match schema method to validate the schema
125
and the test looks nicely and more compact and for example random data generator and all that stuff.
126
And here are my custom utils such as schema validator, request handler, custom expect assertion data generator and so on.
127
But again if you need to run just something very simple.
128
Just use built -in tools that isn't playwright.
129
If you need to automate something more complex, you may need to build something more sophisticated like this.
130
If you want to learn how to build the framework like this, check the link in the description below.
131
I have a course where I teach how exactly step -by -step to build this stuff like this.
132
It is a very good training to get an advanced programming skills.
133
All right, so I hope it was helpful.
134
If you have any questions write them down below put the likes
135
and subscribe and I'll see you in the next one

Télécharger l'application

Tout pour parler couramment

Prononciation IAChaque phrase notée
Phonétique (IPA)Maîtrisez chaque son
VocabulaireEnrichissez votre lexique
Jeu de vocabulaireApprenez en jouant
FOR YOU

Vidéo recommandée

Vocabulaire et conseils d’expression pour cette leçon

Cette leçon d’expression orale s’appuie sur la vidéo « Playwright API Testing with TypeScript ». Les mots qui reviennent le plus souvent : request, test, response, object, example. Cette vidéo contient 135 phrases et 1552 mots à répéter en shadowing. La partie parlée dure 9:54. Le locuteur parle à un rythme naturel d’environ 157 mots par minute, proche d’une conversation courante. 83 % des mots font partie des 3 000 mots les plus courants en anglais ; le reste mérite d’être vu avant de commencer.

Vocabulaire clé de cette vidéo

15 mots de la vidéo à retenir, avec leur prononciation et leur sens :

MotPrononciationSens
fixture nom/ˈfɪks.t͡ʃə/habitué
assertion nom/əˈsɜɹʃən/assertion, confirmation
tag nom/tæɡ/étiquette
authorization nom/ˌɔːθəɹaɪˈzeɪʃən/autorisation
header nom/ˈhɛdɚ/en-tête
successfully adverbe/səkˈsɛs.fə.li/avec succès
custom nom/ˈkʌstəm/coutume
pasta nom/ˈpɑ.stə/pâtes, pâtes alimentaires
folder nom/ˈfoʊldɚ/dossier, chemise
scenario nom/sɪˈnɛəɹioʊ/scénario
install verbe/ɪnˈstɔl/installer
token nom/ˈtoʊkən/symbole
validation nom/ˌvæl.əˈdeɪ.ʃən/validation
terminal nom/ˈtɚmɪnəl/terminal, aérogare
delete verbe/dɪˈliːt/supprimer

Les verbes à particule que vous entendrez

MotSens
go back verberentrer, retourner
come back verberevenir

Prononciation à surveiller

Le locuteur utilise 10 contractions et formes réduites, comme don't, I'm, I'll. Prononcez-les sous leur forme courte, telles que vous les entendez.

  • Les sons « th »: authorization /ˌɔːθəɹaɪˈzeɪʃən/, authorize /ˈɔθəɹaɪz/
  • Les sons « sh » et « zh »: assertion /əˈsɜɹʃən/, authorization /ˌɔːθəɹaɪˈzeɪʃən/, validation /ˌvæl.əˈdeɪ.ʃən/, execution /ˌɛk.sɪˈkjuː.ʃən/, publish /ˈpʌblɪʃ/
  • Mots longs — placez bien l’accent: authorization /ˌɔːθəɹaɪˈzeɪʃən/, successfully /səkˈsɛs.fə.li/, validation /ˌvæl.əˈdeɪ.ʃən/, generator /ˈdʒɛnəɹeɪtə(ɹ)/, parameter /pəˈɹæm.ə.tɚ/

Les sons difficiles pour les francophones :

  • /h/ — il se souffle, il n’est pas muet: header /ˈhɛdɚ/, helpful /ˈhɛlp.fl̩/, handful /ˈhæn(d)fʊl/, handler /ˈhænd.lə/, placeholder /ˈpleɪsˌhoʊldɚ/
  • /tʃ/ et /dʒ/ — à ne pas adoucir en « ch » et « j »: fixture /ˈfɪks.t͡ʃə/, generate /ˈd͡ʒɛn.ə.ɹeɪt/, generator /ˈdʒɛnəɹeɪtə(ɹ)/, patch /pæt͡ʃ/
  • /r/ anglais — langue recourbée, sans frotter la gorge: assertion /əˈsɜɹʃən/, authorization /ˌɔːθəɹaɪˈzeɪʃən/, scenario /sɪˈnɛəɹioʊ/, framework /ˈfɹeɪm.wɜːk/, generate /ˈd͡ʒɛn.ə.ɹeɪt/

Comment s’entraîner avec cette vidéo

  1. Écoutez la vidéo en entier une fois sans parler et notez les mots que vous ne connaissez pas.
  2. Commencez à la vitesse 0,75×, répétez phrase par phrase, puis revenez à la vitesse normale quand cela devient facile.
  3. Enregistrez-vous et comparez avec l’original, en faisant attention à des mots comme fixture, assertion, tag.

Qu'est-ce que la technique du Shadowing ?

Le Shadowing est une technique d'apprentissage des langues fondée sur la science, développée à l'origine pour la formation des interprètes professionnels. Le principe est simple mais puissant : vous écoutez de l'anglais natif et le répétez immédiatement à voix haute — comme une ombre suivant le locuteur avec un décalage de 1 à 2 secondes. Les recherches montrent une amélioration significative de la précision de la prononciation, de l'intonation, du rythme, des liaisons, de la compréhension orale et de la fluidité.

Technique du shadowing : lire le guide complet étape par étape →