|
1 | 1 | # React Playwright Demo
|
2 |
| -This is the project to demo the playwright with the React App |
3 | 2 |
|
4 |
| - |
5 |
| -[](https://github.com/jerseysu/react-playwright-demo/actions/workflows/pages/pages-build-deployment) |
| 3 | +> This is the project to demo the playwright with the React App |
| 4 | +
|
| 5 | +[](https://github.com/jerseysu/react-playwright-demo/actions/workflows/playwright.yml) |
| 6 | +[](https://github.com/jerseysu/react-playwright-demo/actions/workflows/pages/pages-build-deployment) |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | +The React Playwright Demo App is based on following instruction: |
| 12 | + |
| 13 | +React Developer Guide: [React Developer Guide](https://react.dev/) |
| 14 | + |
| 15 | +Playwright Developer Guide: [Playwright Developer Guide](https://playwright.dev/) |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | +Sample Login/Register App Example: [Sample Login/Register App Example](https://medium.com/@prabhashi.mm/create-a-simple-react-app-typescript-with-login-register-pages-using-create-react-app-e5c12dd6db53) |
| 20 | + |
| 21 | +Demo Github Page: [Demo](https://jerseysu.github.io/react-playwright-demo/) |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | +## Prerequisites |
| 27 | + |
| 28 | +- node 20.15.1 |
| 29 | +- npm 10.7.0 |
| 30 | +- typescript 4.9.5 |
| 31 | +- react 18.3.1 |
| 32 | +- @playwright/test 1.45.1 |
| 33 | + |
| 34 | +## How to run the Demo Page |
| 35 | + |
| 36 | +```sh |
| 37 | +# install the dependencies |
| 38 | +$ npm ci |
| 39 | + |
| 40 | +# run the web server |
| 41 | +$ npm run start |
| 42 | +``` |
| 43 | + |
| 44 | +## Execution Test: |
| 45 | + |
| 46 | +### Execute the Unit test |
| 47 | + |
| 48 | +```sh |
| 49 | +# run unit test |
| 50 | +$ npm run test |
| 51 | +``` |
| 52 | + |
| 53 | + |
| 54 | +### Execute the Playwright test |
| 55 | + |
| 56 | +```sh |
| 57 | +# run playwright test |
| 58 | +$ npm run test:e2e |
| 59 | +``` |
| 60 | + |
| 61 | +### Open the html test report |
| 62 | + |
| 63 | +```sh |
| 64 | +# run playwright report |
| 65 | +$ npx playwright show-report |
| 66 | +``` |
| 67 | + |
| 68 | +## Useful Sample: |
| 69 | + |
| 70 | +- Page Object Patterns |
| 71 | + |
| 72 | +```typescript |
| 73 | +import { expect, type Locator, type Page } from '@playwright/test'; |
| 74 | + |
| 75 | +export class IndexPage { |
| 76 | + readonly page: Page; |
| 77 | + readonly loginButton: Locator; |
| 78 | + readonly email: Locator; |
| 79 | + |
| 80 | + constructor(page: Page) { |
| 81 | + this.page = page; |
| 82 | + this.email = page.locator('div[data-testid="email"] input'); |
| 83 | + this.loginButton = page.locator('a[data-testid="loginButton"]'); |
| 84 | + } |
| 85 | + |
| 86 | + async fillEmail() { |
| 87 | + await this. email. fill( '[email protected]'); |
| 88 | + await expect(this.email).toBeVisible(); |
| 89 | + } |
| 90 | + |
| 91 | + async action() { |
| 92 | + await this.fillEmail(); |
| 93 | + await this.loginButton.click(); |
| 94 | + } |
| 95 | +} |
| 96 | +``` |
| 97 | + |
| 98 | +## Documentation: |
| 99 | + |
| 100 | +Blog: - [Shift Left Testing feat. react, playwright and github actions](https://medium.com/@loverjersey/%E7%95%B6%E6%B8%AC%E8%A9%A6%E9%96%8B%E5%A7%8B%E5%B7%A6%E7%A7%BB-feat-react-playwright-and-github-action-f5e87d999cd6) |
| 101 | + |
| 102 | +## Author |
| 103 | + |
| 104 | +Jersey Su – [@jerseysu](https://twitter.com/jersey_su) |
0 commit comments