Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Playwright automation setup with README, GitHub Actions, and initial tests #1

Merged
merged 1 commit into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -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
41 changes: 41 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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/
87 changes: 85 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,85 @@
# playwright-automation
Automated UI & API testing suite using Playwright for end-to-end testing.
<p align="center">
<img src="https://playwright.dev/img/playwright-logo.svg" alt="Playwright Logo" width="200"/>
</p>


# 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.
97 changes: 97 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "playwright-automation",
"version": "1.0.0",
"description": "Automated UI &amp; 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"
}
}
37 changes: 37 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -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,
// },
});
18 changes: 18 additions & 0 deletions tests/example.spec.ts
Original file line number Diff line number Diff line change
@@ -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();
});