Skip to content

Commit

Permalink
Merge pull request #73 from satyam-seth/setup-playwright
Browse files Browse the repository at this point in the history
Setup playwright
  • Loading branch information
satyam-seth authored Dec 17, 2023
2 parents 669eb7a + 60e8fd5 commit 3f80e79
Show file tree
Hide file tree
Showing 7 changed files with 214 additions and 5 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Playwright E2E Tests

on:
push:
branches:
- main
pull_request:

jobs:
test:
name: 'Playwright 👩🏽‍🚒 E2E Test 🚀'
timeout-minutes: 60
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18

- 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@v3
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ node_modules/
# Skip ignoring this file because it is required for GitHub Pages to work.
# dist/
.nyc_output/
coverage/
coverage/
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,8 @@ A dialpad build using ts and scss

- [sinon npm package](https://www.npmjs.com/package/sinon)
- [sinon types npm package](https://www.npmjs.com/package/@types/sinon)

## [Playwright Setup](https://github.com/satyam-seth/dialpad/pull/73)

- [playwright installation doc link](https://playwright.dev/docs/intro#installing-playwright)
- [http-server npm package](https://www.npmjs.com/package/http-server)
9 changes: 9 additions & 0 deletions e2e/example.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* eslint-disable import/no-extraneous-dependencies */
import { expect, test } 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/);
});
77 changes: 73 additions & 4 deletions package-lock.json

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

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@
"lint:fix": "eslint src/**/*.ts --fix",
"lint-scss": "sass-lint src/**/*.scss",
"test:unit": "mocha",
"test:e2e": "npx playwright test",
"test:coverage": "nyc npm run test:unit"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@playwright/test": "^1.40.1",
"@types/chai": "^4.3.6",
"@types/mocha": "^10.0.2",
"@types/node": "^20.10.4",
"@types/sinon": "^10.0.18",
"@typescript-eslint/eslint-plugin": "^6.4.0",
"@typescript-eslint/parser": "^6.4.0",
Expand Down
84 changes: 84 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { defineConfig, devices } from '@playwright/test';

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// require('dotenv').config();

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './e2e',
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
// baseURL: 'http://127.0.0.1:3000',

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on',
video: 'on',
screenshot: 'on',
headless: true,
},

/* Configure projects for major browsers */
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},

{
name: 'firefox',
use: { ...devices['Desktop Firefox'] },
},

{
name: 'webkit',
use: { ...devices['Desktop Safari'] },
},

/* Test against mobile viewports. */
{
name: 'Mobile Chrome',
use: { ...devices['Pixel 5'] },
},

{
name: 'Mobile Safari',
use: { ...devices['iPhone 12'] },
},

/* Test against branded browsers. */
{
name: 'Microsoft Edge',
use: { ...devices['Desktop Edge'], channel: 'msedge' },
},

{
name: 'Google Chrome',
use: { ...devices['Desktop Chrome'], channel: 'chrome' },
},
],

/* Run your local dev server before starting the tests */
webServer: {
command: 'npx http-server',
port: 8080,
timeout: 120000, // Maximum time (in milliseconds) to wait for the server to start
reuseExistingServer: !process.env.CI,
},
});

0 comments on commit 3f80e79

Please sign in to comment.