|
| 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 | + |
| 84 | + |
| 85 | + |
| 86 | + |
| 87 | + |
| 88 | + |
| 89 | + |
| 90 | + |
| 91 | + |
| 92 | + |
| 93 | +## Playwright Test Report |
| 94 | + |
| 95 | + |
| 96 | + |
| 97 | + |
| 98 | + |
| 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 | +  |
| 107 | + |
| 108 | + - Step2: Click on Repos & Let's create new repository, Click on New reposiotry |
| 109 | +  |
| 110 | + |
| 111 | + - Step3: Enter Repository name & Click on Create |
| 112 | +  |
| 113 | +  |
| 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 | +  |
| 118 | + |
| 119 | + - Step6: Push all the folders into Azure devops |
| 120 | +  |
| 121 | + |
| 122 | + - Step7: Repository is ready now, let's create pipeline. Click on Pipelines->Create Pipeline |
| 123 | + -  |
| 124 | + |
| 125 | + - Step8: Click on Azure Repos Git |
| 126 | +  |
| 127 | + |
| 128 | + - Step9: Select previously created repository |
| 129 | +  |
| 130 | + |
| 131 | + - Step10: Select Starter Pipeline |
| 132 | +  |
| 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 | +  |
| 165 | +  |
| 166 | + |
| 167 | + - Step13: You will see job queued like this. |
| 168 | + -  |
| 169 | + |
| 170 | + - Step14: Click on Job & Verify build status. |
| 171 | +  |
| 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 | +  |
| 217 | +  |
| 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 | +  |
| 224 | + |
| 225 | + - Step3: Click on Use the classic editor & Click on Continue |
| 226 | +  |
| 227 | +  |
| 228 | + |
| 229 | + - Step4: Click on Emtpy job |
| 230 | +  |
| 231 | + |
| 232 | + - Step5: Click on + icon, Search for Node and add Node.js tool installer |
| 233 | +  |
| 234 | +  |
| 235 | + |
| 236 | + |
| 237 | + - Step6: Select just now added task and add Node v16 becuase playwright supports for Node v14 and above |
| 238 | + -  |
| 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 | +  |
| 244 | +  |
| 245 | + |
| 246 | + Click on Advanced-> Click on little icon(i) & select the Link. This will enable working directory for the task. |
| 247 | +  |
| 248 | + |
| 249 | + - Step8: Add another task by clicking on + icon, search for npm & Add npm |
| 250 | +  |
| 251 | + |
| 252 | + Enter Display name, Select Command as custom & Enter Command and Arguments as run tests |
| 253 | +  |
| 254 | + |
| 255 | + In this task we are referring to the package.json file. |
| 256 | +  |
| 257 | + |
| 258 | + - Step9: Once everthing is completed now it is a time run script. Click on Save & queue. |
| 259 | +  |
| 260 | + |
| 261 | + Add commit message then click save & run. |
| 262 | + |
| 263 | + - Step10: It looks like this |
| 264 | +  |
| 265 | + |
| 266 | + Click on Job and you will see a screen like this |
| 267 | +  |
| 268 | + |
| 269 | + - Step11: We can also upload playwright-report using Publish Pipeline Artifacts task |
| 270 | +  |
| 271 | + |
| 272 | + - Step12: Let's Publish Test Results using Publish Test Results task |
| 273 | +  |
| 274 | + |
| 275 | + |
| 276 | + - Let's run the pipeline |
| 277 | +  |
| 278 | + |
| 279 | + - Artifacts are published & also we have published test results |
| 280 | +  |
| 281 | + |
| 282 | +  |
| 283 | + |
| 284 | + |
| 285 | + |
| 286 | + |
| 287 | + |
| 288 | + |
| 289 | + |
0 commit comments