diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml new file mode 100644 index 0000000..e73ddf0 --- /dev/null +++ b/.github/workflows/playwright.yml @@ -0,0 +1,27 @@ +name: Playwright Tests +on: + push: + branches: [ main, master ] + pull_request: + branches: [ main, master ] +jobs: + test: + timeout-minutes: 60 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: lts/* + - name: Install dependencies + run: npm ci + - name: Install Playwright Browsers + run: npx playwright install --with-deps + - name: Run Playwright tests + run: npx playwright test + - uses: actions/upload-artifact@v4 + if: ${{ !cancelled() }} + with: + name: playwright-report + path: playwright-report/ + retention-days: 10 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6eb6b06 --- /dev/null +++ b/.gitignore @@ -0,0 +1,41 @@ +# Node Modules +node_modules/ +.npm/ + +# Logs +*.log +logs/ +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* + +# OS Generated Files +.DS_Store +Thumbs.db + +# Environment Variables +.env +.env.local +.env.*.local + +# Playwright Specific +playwright-report/ +test-results/ +screenshots/ +trace/ +playwright/.cache/ + +# Cypress Specific +cypress/screenshots/ +cypress/videos/ + +# IDE and Editor Files +.idea/ +.vscode/ +*.sublime-project +*.sublime-workspace + +# Output and Coverage Files +dist/ +coverage/ diff --git a/README.md b/README.md index e5a73f1..612ad3c 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,85 @@ -# playwright-automation -Automated UI & API testing suite using Playwright for end-to-end testing. +

+ Playwright Logo +

+ + +# Playwright Automation +This project is an automated UI and API testing suite that utilizes [Playwright](https://playwright.dev/) for comprehensive end-to-end testing. Playwright is a robust framework that supports testing across multiple browsers, including Chromium, Firefox, and WebKit. With Playwright, you can ensure that your web applications perform consistently and reliably across different environments. + +### Key Benefits: + +- **Cross-Browser Testing**: Write tests that run on different browsers to ensure compatibility and performance. +- **End-to-End Testing**: Validate the entire workflow of your application, from the user interface to backend services. +- **UI Testing**: Automate interactions with your application's user interface to verify that it behaves as expected. +- **API Testing**: Test your backend APIs to ensure they return the correct responses and handle edge cases. +- **Headless Testing**: Execute tests in a headless browser mode for faster performance and integration into CI/CD pipelines. +- **Debugging Tools**: Utilize Playwright's powerful debugging tools to troubleshoot and resolve issues quickly. + +By integrating Playwright into your testing strategy, you can achieve higher test coverage, reduce manual testing efforts, and deliver a more reliable product to your users. + +## Table of Contents + +- [Features](#features) +- [Installation](#installation) +- [Usage](#usage) +- [License](#license) + +## Features + +- **End-to-End Testing**: Test your entire application from start to finish. +- **UI Testing**: Ensure your user interface works as expected. +- **API Testing**: Validate your backend services. +- **Headless Testing**: Run tests in a headless browser for faster execution. +- **Debugging**: Easily debug your tests with Playwright's built-in tools. + +## Installation + +To get started with this project, clone the repository and install the dependencies: + +```bash +git clone https://github.com/yourusername/playwright-automation.git +cd playwright-automation +``` +```bash +npm install +``` + +> **Note:** Make sure you have [Node.js](https://nodejs.org/) and `npm` installed on your machine before running the above command. + +## Usage + +You can run the tests using the following commands: + +Run All Tests + +```bash +npm test +``` + +Run Tests with UI + +```bash +npm run test:ui +``` + +Run Tests in Headed Mode + +```bash +npm run test:head +``` + +Debug Tests + +```bash +npm run test:debug +``` + +Generate Code + +```bash +npm run test:codegen +``` + +## License + +This project is licensed under the ISC License. See the [LICENSE](LICENSE) file for more details. \ No newline at end of file diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..b097922 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,97 @@ +{ + "name": "playwright-automation", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "playwright-automation", + "version": "1.0.0", + "license": "ISC", + "devDependencies": { + "@playwright/test": "^1.49.0", + "@types/node": "^22.10.1" + } + }, + "node_modules/@playwright/test": { + "version": "1.49.0", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.49.0.tgz", + "integrity": "sha512-DMulbwQURa8rNIQrf94+jPJQ4FmOVdpE5ZppRNvWVjvhC+6sOeo28r8MgIpQRYouXRtt/FCCXU7zn20jnHR4Qw==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "playwright": "1.49.0" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/@types/node": { + "version": "22.10.1", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.10.1.tgz", + "integrity": "sha512-qKgsUwfHZV2WCWLAnVP1JqnpE6Im6h3Y0+fYgMTasNQ7V++CBX5OT1as0g0f+OyubbFqhf6XVNIsmN4IIhEgGQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "undici-types": "~6.20.0" + } + }, + "node_modules/fsevents": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", + "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, + "node_modules/playwright": { + "version": "1.49.0", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.49.0.tgz", + "integrity": "sha512-eKpmys0UFDnfNb3vfsf8Vx2LEOtflgRebl0Im2eQQnYMA4Aqd+Zw8bEOB+7ZKvN76901mRnqdsiOGKxzVTbi7A==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "playwright-core": "1.49.0" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "fsevents": "2.3.2" + } + }, + "node_modules/playwright-core": { + "version": "1.49.0", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.49.0.tgz", + "integrity": "sha512-R+3KKTQF3npy5GTiKH/T+kdhoJfJojjHESR1YEWhYuEKRVfVaxH3+4+GvXE5xyCngCxhxnykk0Vlah9v8fs3jA==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "playwright-core": "cli.js" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/undici-types": { + "version": "6.20.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.20.0.tgz", + "integrity": "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg==", + "dev": true, + "license": "MIT" + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..7901c6c --- /dev/null +++ b/package.json @@ -0,0 +1,20 @@ +{ + "name": "playwright-automation", + "version": "1.0.0", + "description": "Automated UI & API testing suite using Playwright for end-to-end testing.", + "main": "index.js", + "scripts": { + "test": "npx playwright test", + "test:ui": "npx playwright test --ui", + "test:head": "npx playwright test --headed", + "test:debug": "npx playwright test --debug", + "test:codegen": "npx playwright codegen" + }, + "keywords": [], + "author": "", + "license": "ISC", + "devDependencies": { + "@playwright/test": "^1.49.0", + "@types/node": "^22.10.1" + } +} diff --git a/playwright.config.ts b/playwright.config.ts new file mode 100644 index 0000000..be0ff7b --- /dev/null +++ b/playwright.config.ts @@ -0,0 +1,37 @@ +import { defineConfig, devices } from '@playwright/test'; + +export default defineConfig({ + testDir: './tests', + fullyParallel: true, + forbidOnly: !!process.env.CI, + retries: process.env.CI ? 2 : 0, + workers: process.env.CI ? 1 : undefined, + reporter: 'html', + use: { + trace: 'on-first-retry', + }, + + projects: [ + { + name: 'chromium', + use: { ...devices['Desktop Chrome'] }, + }, + + { + name: 'firefox', + use: { ...devices['Desktop Firefox'] }, + }, + + { + name: 'webkit', + use: { ...devices['Desktop Safari'] }, + }, + ], + + /* Run your local dev server before starting the tests */ + // webServer: { + // command: 'npm run start', + // url: 'http://127.0.0.1:3000', + // reuseExistingServer: !process.env.CI, + // }, +}); diff --git a/tests/example.spec.ts b/tests/example.spec.ts new file mode 100644 index 0000000..54a906a --- /dev/null +++ b/tests/example.spec.ts @@ -0,0 +1,18 @@ +import { test, expect } from '@playwright/test'; + +test('has title', async ({ page }) => { + await page.goto('https://playwright.dev/'); + + // Expect a title "to contain" a substring. + await expect(page).toHaveTitle(/Playwright/); +}); + +test('get started link', async ({ page }) => { + await page.goto('https://playwright.dev/'); + + // Click the get started link. + await page.getByRole('link', { name: 'Get started' }).click(); + + // Expects page to have a heading with the name of Installation. + await expect(page.getByRole('heading', { name: 'Installation' })).toBeVisible(); +});