Skip to content

Commit 6438736

Browse files
committed
2 parents 6557e87 + 700b4b0 commit 6438736

File tree

3 files changed

+294
-3
lines changed

3 files changed

+294
-3
lines changed

README.md

Lines changed: 289 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,289 @@
1+
### Playwright Tutorial Full Course - https://bit.ly/playwright-tutorial-automation-testing
2+
### Playwright API Testing Tutorial - https://bit.ly/playwright-api-testing-tutorial
3+
### Playwright with Dynamics 365 CRM - https://youtu.be/WwovRRp0f4o?si=oqPE2ux7UcDeJMm6
4+
### Playwright with Azure DevOps Pipeline - https://bit.ly/playwright-azure-devops-tutorial
5+
6+
#### Install Playwright & Select Configurations
7+
- npm init playwright@latest
8+
9+
Playwright will download the browsers needed as well as create the following files.
10+
11+
- node_modules
12+
- playwright.config.js
13+
- package.json
14+
- package-lock.json
15+
- tests/
16+
example.spec.js
17+
- tests-examples/
18+
demo-todo-app.spec.js
19+
20+
21+
#### dotenv Package Installation Command
22+
- npm install dotenv --save
23+
24+
#### csv-parse Package Installation Command
25+
- npm install csv-parse
26+
27+
#### faker-js plugin for test data generation
28+
- npm install @faker-js/faker --save-dev
29+
30+
#### luxon plugin for custom dates
31+
- npm install --save luxon
32+
33+
## Playwright Important Commands
34+
35+
npx playwright install
36+
- Install Browsers manually.
37+
38+
npx playwright test
39+
- Runs the end-to-end tests.
40+
41+
npx playwright test --ui
42+
- Starts the interactive UI mode.
43+
44+
npx playwright test --project=chromium
45+
- Runs the tests only on Desktop Chrome.
46+
47+
npx playwright test example
48+
- Runs the tests in a specific file.
49+
50+
npx playwright test --debug
51+
- Runs the tests in debug mode.
52+
53+
npx playwright codegen
54+
- Auto generate tests with Codegen.
55+
56+
We suggest that you begin by typing:
57+
58+
npx playwright test
59+
60+
### And check out the following files:
61+
- .\tests\example.spec.js - Example end-to-end test
62+
- .\tests-examples\demo-todo-app.spec.js - Demo Todo App end-to-end tests
63+
- .\playwright.config.js - Playwright Test configuration
64+
65+
## Allure Report with Playwright [Screenshots, Videos & Traces]
66+
- Step1: Install Allure Report command-line tool
67+
### npm install --save-dev allure-commandline
68+
69+
- Step2: Install the Allure Playwright adapter.
70+
### npm install --save-dev allure-playwright
71+
72+
- Step3: Add below config in playwright.config.js file.
73+
### reporter:[
74+
### ['html'],
75+
### ['allure-playwright']
76+
### ],
77+
78+
- Step4: Run Playwright tests.
79+
### npx playwright test
80+
81+
- Step5: Generate Allure Report
82+
### npx allure serve allure-results
83+
![image](https://github.com/BakkappaN/PlaywrightTutorialFullCourse/assets/22426896/0dc08076-a4ba-4f9f-9b89-ecd8fc81f5ba)
84+
85+
![image](https://github.com/BakkappaN/PlaywrightTutorialFullCourse/assets/22426896/5fc751fa-81ca-4dc6-9c49-54834258d0aa)
86+
87+
![image](https://github.com/BakkappaN/PlaywrightTutorialFullCourse/assets/22426896/36161f37-2cf2-4373-a30d-f888adb405de)
88+
89+
![image](https://github.com/BakkappaN/PlaywrightTutorialFullCourse/assets/22426896/b7ef2588-adbd-40fc-9801-ed1554fd38ef)
90+
91+
92+
93+
## Playwright Test Report
94+
![image](https://github.com/BakkappaN/PlaywrightTutorialFullCourse/assets/22426896/dd9e360b-bd9e-425a-9191-848a13791d29)
95+
96+
![image](https://github.com/BakkappaN/PlaywrightTutorialFullCourse/assets/22426896/9ea0128b-5906-476f-9fc7-615b240d7623)
97+
98+
![image](https://github.com/BakkappaN/PlaywrightTutorialFullCourse/assets/22426896/379bb630-b84d-4a47-a70e-8afca0d33240)
99+
100+
101+
## Integrate Playwright with Azure Devops Pipeline
102+
There are 2 options, option1 is using yaml file & option2 is without using yaml file. let's see one by one
103+
104+
1. Option1 - Using YAML File
105+
- Step1: Create a new project in ADO then Click on Project
106+
![image](https://github.com/BakkappaN/PlaywrightTutorialFullCourse/assets/22426896/0ec3b6b7-748f-4d0a-80bf-762e24728afb)
107+
108+
- Step2: Click on Repos & Let's create new repository, Click on New reposiotry
109+
![image](https://github.com/BakkappaN/PlaywrightTutorialFullCourse/assets/22426896/fe0485c8-2708-456b-9030-a046b1170c70)
110+
111+
- Step3: Enter Repository name & Click on Create
112+
![image](https://github.com/BakkappaN/PlaywrightTutorialFullCourse/assets/22426896/ea15010a-4308-41c2-883e-f0ddee48908f)
113+
![image](https://github.com/BakkappaN/PlaywrightTutorialFullCourse/assets/22426896/0ee53f40-2d9e-4dbb-8301-5cc2c615d647)
114+
115+
- Step4: Click on Clone button and get the URL. Go to your system then clone repository.
116+
- Step5: Add all the playwright framework folders inside cloned repository
117+
![image](https://github.com/BakkappaN/PlaywrightTutorialFullCourse/assets/22426896/b8039254-cba5-46ff-9696-0aad20dd9876)
118+
119+
- Step6: Push all the folders into Azure devops
120+
![image](https://github.com/BakkappaN/PlaywrightTutorialFullCourse/assets/22426896/add3e34a-5ba8-4792-9d2c-dbae06bc6a64)
121+
122+
- Step7: Repository is ready now, let's create pipeline. Click on Pipelines->Create Pipeline
123+
- ![image](https://github.com/BakkappaN/PlaywrightTutorialFullCourse/assets/22426896/7bb2f8dc-8253-46ab-879a-743446211bdf)
124+
125+
- Step8: Click on Azure Repos Git
126+
![image](https://github.com/BakkappaN/PlaywrightTutorialFullCourse/assets/22426896/885628e1-8e4c-43fc-ba6a-6125ec34e6fb)
127+
128+
- Step9: Select previously created repository
129+
![image](https://github.com/BakkappaN/PlaywrightTutorialFullCourse/assets/22426896/09b1489d-f699-4885-84a4-c06554adc3e6)
130+
131+
- Step10: Select Starter Pipeline
132+
![image](https://github.com/BakkappaN/PlaywrightTutorialFullCourse/assets/22426896/3db45ed6-c0c9-4033-b786-b8ca7e263ce4)
133+
134+
- Step11: Copy below yaml content and paste it inside azure-pipelines.yml file.
135+
```
136+
trigger:
137+
- main
138+
139+
pool:
140+
vmImage: ubuntu-latest
141+
142+
steps:
143+
- task: NodeTool@0
144+
inputs:
145+
versionSpec: '18'
146+
displayName: 'Install Node.js'
147+
- script: npm ci
148+
displayName: 'npm ci'
149+
- script: npx playwright install --with-deps
150+
displayName: 'Install Playwright browsers'
151+
- script: npx playwright test
152+
displayName: 'Run Playwright tests'
153+
env:
154+
CI: 'true'
155+
```
156+
If you are running in self hosted agent replace pool commands
157+
```
158+
pool:
159+
name: AgentPoolName
160+
demands:
161+
- agent.name -equals AgentName
162+
```
163+
- Step12: Click on Save and run
164+
![image](https://github.com/BakkappaN/PlaywrightTutorialFullCourse/assets/22426896/208f9b43-735a-45e1-b5c3-699df9e6d8f2)
165+
![image](https://github.com/BakkappaN/PlaywrightTutorialFullCourse/assets/22426896/41262f5d-6e80-4274-a4fc-75d0536e73a7)
166+
167+
- Step13: You will see job queued like this.
168+
- ![image](https://github.com/BakkappaN/PlaywrightTutorialFullCourse/assets/22426896/1fff0860-2ac5-45b0-aa45-757afb76777e)
169+
170+
- Step14: Click on Job & Verify build status.
171+
![image](https://github.com/BakkappaN/PlaywrightTutorialFullCourse/assets/22426896/66326c8f-d789-4856-b90c-8909bef95930)
172+
173+
- Step15: Now let's Upload playwright-report folder with Azure Pipelines & Report generation
174+
Firstly update azure-pipelines.yml file
175+
```
176+
trigger:
177+
- main
178+
179+
pool:
180+
vmImage: ubuntu-latest
181+
182+
steps:
183+
- task: NodeTool@0
184+
inputs:
185+
versionSpec: '18'
186+
displayName: 'Install Node.js'
187+
- script: npm ci
188+
displayName: 'npm ci'
189+
- script: npx playwright install --with-deps
190+
displayName: 'Install Playwright browsers'
191+
- script: npx playwright test
192+
displayName: 'Run Playwright tests'
193+
env:
194+
CI: 'true'
195+
196+
- task: PublishTestResults@2
197+
displayName: 'Publish test results'
198+
inputs:
199+
searchFolder: 'test-results'
200+
testResultsFormat: 'JUnit'
201+
testResultsFiles: 'e2e-junit-results.xml'
202+
mergeTestResults: true
203+
failTaskOnFailedTests: true
204+
testRunTitle: 'My End-To-End Tests'
205+
condition: succeededOrFailed()
206+
- task: PublishPipelineArtifact@1
207+
inputs:
208+
targetPath: playwright-report
209+
artifact: playwright-report
210+
publishLocation: 'pipeline'
211+
condition: succeededOrFailed()
212+
```
213+
214+
- Step16: Verify playwright-report folder attachment & report.
215+
From job we can navigate into artifacts folder. Download playwright report and verify results.
216+
![image](https://github.com/BakkappaN/PlaywrightTutorialFullCourse/assets/22426896/54aaf4b4-7715-435d-b96a-7a19c23fa384)
217+
![image](https://github.com/BakkappaN/PlaywrightTutorialFullCourse/assets/22426896/5ed6c543-4162-43a9-9f21-9643d7f52438)
218+
219+
220+
2. Option2 - Without using YAML File
221+
- Step1: Repeat step 1 to 6 above from Option1
222+
- Step2: Click on Pipelines then click on New Pipeline
223+
![image](https://github.com/BakkappaN/PlaywrightTutorialFullCourse/assets/22426896/1f753af4-881e-495d-a7dd-8c9163de97ff)
224+
225+
- Step3: Click on Use the classic editor & Click on Continue
226+
![image](https://github.com/BakkappaN/PlaywrightTutorialFullCourse/assets/22426896/499f6cf4-0458-4aba-813a-ad131cea4b02)
227+
![image](https://github.com/BakkappaN/PlaywrightTutorialFullCourse/assets/22426896/332011f7-0ae4-46ce-a9c2-3c2a9d66f599)
228+
229+
- Step4: Click on Emtpy job
230+
![image](https://github.com/BakkappaN/PlaywrightTutorialFullCourse/assets/22426896/d84dda85-cbc0-4c9f-9147-bc1de36823c4)
231+
232+
- Step5: Click on + icon, Search for Node and add Node.js tool installer
233+
![image](https://github.com/BakkappaN/PlaywrightTutorialFullCourse/assets/22426896/73d32c4d-2cd1-4f78-beb7-ec1bf5f5138a)
234+
![image](https://github.com/BakkappaN/PlaywrightTutorialFullCourse/assets/22426896/64fcf35f-1200-4ccf-b34c-d53072728ced)
235+
236+
237+
- Step6: Select just now added task and add Node v16 becuase playwright supports for Node v14 and above
238+
- ![image](https://github.com/BakkappaN/PlaywrightTutorialFullCourse/assets/22426896/aa804427-464c-434f-b4e4-27547b245bd9)
239+
240+
- Step7: Click on + icon, Similary add Command line task,
241+
Display name: Install Playwright & Dependencies
242+
Script: npm install && npx playwright install
243+
![image](https://github.com/BakkappaN/PlaywrightTutorialFullCourse/assets/22426896/df63a628-ccb4-4709-8c2a-166358dc5264)
244+
![image](https://github.com/BakkappaN/PlaywrightTutorialFullCourse/assets/22426896/70991c9e-ad21-4ab8-978e-ba02d0f5971f)
245+
246+
Click on Advanced-> Click on little icon(i) & select the Link. This will enable working directory for the task.
247+
![image](https://github.com/BakkappaN/PlaywrightTutorialFullCourse/assets/22426896/1d6dc42d-e720-4446-b1f7-4589f105ff04)
248+
249+
- Step8: Add another task by clicking on + icon, search for npm & Add npm
250+
![image](https://github.com/BakkappaN/PlaywrightTutorialFullCourse/assets/22426896/49eadf73-d640-4c7d-8ea6-730f2291d503)
251+
252+
Enter Display name, Select Command as custom & Enter Command and Arguments as run tests
253+
![image](https://github.com/BakkappaN/PlaywrightTutorialFullCourse/assets/22426896/f055ace0-8cdb-46e7-9f24-33c808eef4ee)
254+
255+
In this task we are referring to the package.json file.
256+
![image](https://github.com/BakkappaN/PlaywrightTutorialFullCourse/assets/22426896/6074a566-6efb-46a7-ad37-2108eed90bf8)
257+
258+
- Step9: Once everthing is completed now it is a time run script. Click on Save & queue.
259+
![image](https://github.com/BakkappaN/PlaywrightTutorialFullCourse/assets/22426896/112334f9-6adb-43a5-b2d4-41f364c7527d)
260+
261+
Add commit message then click save & run.
262+
263+
- Step10: It looks like this
264+
![image](https://github.com/BakkappaN/PlaywrightTutorialFullCourse/assets/22426896/ae48637e-d0bf-4a32-8d93-2ea251301068)
265+
266+
Click on Job and you will see a screen like this
267+
![image](https://github.com/BakkappaN/PlaywrightTutorialFullCourse/assets/22426896/b135a6c0-039c-4b90-934c-849b35e47cbc)
268+
269+
- Step11: We can also upload playwright-report using Publish Pipeline Artifacts task
270+
![image](https://github.com/BakkappaN/PlaywrightTutorialFullCourse/assets/22426896/138a4af7-addd-4498-8296-64468c957610)
271+
272+
- Step12: Let's Publish Test Results using Publish Test Results task
273+
![image](https://github.com/BakkappaN/PlaywrightTutorialFullCourse/assets/22426896/f0ea2efe-3509-4e48-baa5-01a2ec9f283d)
274+
275+
276+
- Let's run the pipeline
277+
![image](https://github.com/BakkappaN/PlaywrightTutorialFullCourse/assets/22426896/575518de-feed-4267-b7f1-290e4ad76903)
278+
279+
- Artifacts are published & also we have published test results
280+
![image](https://github.com/BakkappaN/PlaywrightTutorialFullCourse/assets/22426896/d575766a-2f20-42f2-a1e3-aa5f71259823)
281+
282+
![image](https://github.com/BakkappaN/PlaywrightTutorialFullCourse/assets/22426896/45821475-feb2-4b16-a9ae-126c55cf20a1)
283+
284+
285+
286+
287+
288+
289+

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
"version": "1.0.0",
44
"description": "",
55
"main": "index.js",
6-
"scripts": {},
6+
"scripts": {
7+
"tests": "npx playwright test --config=playwright.config.js --project=chromium"
8+
},
79
"keywords": [],
810
"author": "",
911
"license": "ISC",

playwright.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ module.exports = defineConfig({
4040
// video, screenshot, headless mode
4141
video:'on',
4242
screenshot: 'on',
43-
headless : false,
43+
headless : true,
4444

4545
// custom attribute
4646
testIdAttribute: 'autocomplete',
@@ -94,4 +94,4 @@ module.exports = defineConfig({
9494
// url: 'http://127.0.0.1:3000',
9595
// reuseExistingServer: !process.env.CI,
9696
// },
97-
});
97+
});

0 commit comments

Comments
 (0)