├── env.ts ├── .gitignore ├── tsconfig.json ├── tests └── scenarios │ └── example │ └── example.spec.ts ├── README.md ├── LICENSE ├── package.json └── playwright.config.ts /env.ts: -------------------------------------------------------------------------------- 1 | import "dotenv/config"; 2 | 3 | export const host = process.env.HOST || "https://example.com"; -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | credentials/**/*.json 3 | /test-results/ 4 | /playwright-report/ 5 | /playwright/.cache/ 6 | .env 7 | .idea 8 | storageState.json -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "esnext", 4 | "module": "commonjs", 5 | "lib": ["es6", "dom"], 6 | "strict": true, 7 | "moduleResolution": "node", 8 | "resolveJsonModule": true, 9 | "esModuleInterop": true, 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /tests/scenarios/example/example.spec.ts: -------------------------------------------------------------------------------- 1 | import { test, expect } from '@playwright/test'; 2 | 3 | test('test', async ({ page }) => { 4 | await page.goto('https://example.com/login'); 5 | await page.waitForTimeout(5000); 6 | const heading = await page.getByRole('heading', { name: 'Example Domain' }); 7 | expect(heading).toBeTruthy(); 8 | }); -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # This repo is a playwright project scaffolding 2 | ## Preconfigured with 3 | - typescript 4.8.3 4 | - playwright 1.32.3 5 | - eslint 6 | - husky 7 | - dotenv 8 | 9 | ## Setup 10 | - clone the repo 11 | - `npm install` 12 | 13 | ## Usage 14 | - `npm run test:ui` 15 | 16 | See `package.json` scripts for more info. 17 | 18 | ### Docs 19 | - https://playwright.dev/docs/intro -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Julio César 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "e2e", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "", 6 | "engines": { 7 | "node": ">= 18" 8 | }, 9 | "scripts": { 10 | "test": "playwright test", 11 | "test:ui": "playwright test --ui", 12 | "test:head": "playwright test --headed", 13 | "test:chromium": "playwright test --headed --project=chromium", 14 | "test:firefox": "playwright test --headed --project=firefox", 15 | "test:webkit": "playwright test --headed --project=webkit", 16 | "test:ci": "playwright test --headless", 17 | "record": "playwright codegen $(grep HOST .env | cut -d '=' -f2)/login", 18 | "eslint": "tsc --noEmit && eslint tests ", 19 | "eslint:fix": "tsc --noEmit && eslint tests --fix", 20 | "prepare": "husky install", 21 | "ts-node": "ts-node" 22 | }, 23 | "keywords": [], 24 | "author": "", 25 | "license": "ISC", 26 | "devDependencies": { 27 | "@playwright/test": "^1.32.3", 28 | "@types/node": "^17.0.36", 29 | "@typescript-eslint/eslint-plugin": "^5.31.0", 30 | "@typescript-eslint/parser": "^5.31.0", 31 | "husky": "^8.0.1", 32 | "ts-node": "^10.9.1", 33 | "typescript": "^4.8.3" 34 | }, 35 | "dependencies": { 36 | "dotenv": "^16.0.1" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /playwright.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig, devices } from '@playwright/test'; 2 | import path from 'path'; 3 | import { host } from './env'; 4 | 5 | export const STORAGE_STATE_PATH = path.join(__dirname, './storageState.json'); 6 | export default defineConfig({ 7 | forbidOnly: !!process.env.CI, 8 | retries: process.env.CI ? 2 : 0, 9 | expect: { timeout: 1000000 }, // important firefox with 5s too slow and fails 10 | timeout: 60000, 11 | use: { 12 | baseURL: host, 13 | trace: 'on-first-retry', 14 | actionTimeout: 20000, 15 | navigationTimeout: 40000, 16 | screenshot: { 17 | mode: 'only-on-failure', 18 | fullPage: true, 19 | }, 20 | }, 21 | workers: 1, 22 | globalTimeout: 60 * 60 * 1000, 23 | projects: [ 24 | { 25 | name: 'setup', 26 | testMatch: '**/*.setup.ts', 27 | }, 28 | { 29 | name: 'chromium', 30 | dependencies: ['setup'], 31 | use: { 32 | ...devices['Desktop Chrome'], 33 | storageState: STORAGE_STATE_PATH, 34 | }, 35 | }, 36 | { 37 | name: 'firefox', 38 | dependencies: ['setup'], 39 | use: { 40 | ...devices['Desktop Firefox'], 41 | storageState: STORAGE_STATE_PATH, 42 | }, 43 | }, 44 | { 45 | name: 'webkit', 46 | dependencies: ['setup'], 47 | use: { 48 | ...devices['Desktop Safari'], 49 | storageState: STORAGE_STATE_PATH, 50 | }, 51 | }, 52 | ], 53 | }); 54 | --------------------------------------------------------------------------------