Skip to content

Commit

Permalink
Add playwright init configuration
Browse files Browse the repository at this point in the history
Signed-off-by: Moulik Aggarwal <qwertymoulik@gmail.com>
  • Loading branch information
aggmoulik committed Oct 21, 2023
1 parent ae37b66 commit 0c6ab47
Show file tree
Hide file tree
Showing 6 changed files with 282 additions and 24 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 Tests
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
jobs:
test:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- name: ⬇️ Checkout repo
uses: actions/checkout@v3

- name: 🏄 Copy test env vars
run: cp .env.example .env

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

- name: Install dependencies
run: pnpm install

- name: Install Playwright Browsers
run: pnpm exec playwright install --with-deps

- name: Run Playwright tests
run: pnpm exec playwright test
- uses: actions/upload-artifact@v3
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,7 @@ dist
!.env.vault
!.env.example

oclif.manifest.json
oclif.manifest.json
/test-results/
/playwright-report/
/playwright/.cache/
18 changes: 18 additions & 0 deletions e2e/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();
});
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@
"test": "jest",
"prettify": "prettier --write \"platform/firecamp-platform/src/**/*.(ts|tsx)\" \"packages/firecamp-rest/src/**/*.(ts|tsx)\" \"packages/firecamp-graphql/src/**/*.(ts|tsx)\"",
"precommit": "lint-staged",
"preinstall": "npx only-allow pnpm"
"preinstall": "npx only-allow pnpm",
"test:e2e": "npm run test:e2e:dev --silent",
"test:e2e:dev": "playwright test --ui",
"pretest:e2e:run": "npm run build",
"test:e2e:run": "cross-env CI=true playwright test",
"test:e2e:install": "npx playwright install chromium --with-deps"
},
"lint-staged": {
"**/*.ts": [
Expand Down Expand Up @@ -49,6 +54,8 @@
"@babel/preset-react": "^7.16.7",
"@babel/preset-typescript": "^7.16.7",
"@babel/register": "^7.0.0",
"@playwright/test": "^1.39.0",
"@types/node": "^20.8.7",
"babel-eslint": "^10.1.0",
"babel-loader": "^9.1.0",
"babel-plugin-add-module-exports": "^1.0.4",
Expand Down
87 changes: 87 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { defineConfig, devices } from '@playwright/test';

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/

const PORT = 3000;

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './e2e',
/* Maximum time one test can run for. */
timeout: 30 * 1000,
expect: {
/**
* Maximum time expect() should wait for the condition to be met.
* For example in `await expect(locator).toHaveText();`
*/
timeout: 10 * 1000,
},
/* 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: {
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
actionTimeout: 0,
baseURL: `http://localhost:${PORT}/`,
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
},

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

// {
// name: 'firefox',

Check failure on line 51 in playwright.config.ts

View workflow job for this annotation

GitHub Actions / Check Spelling

`firefox` is not a recognized word. (unrecognized-spelling)
// use: { ...devices['Desktop Firefox'] },
// },

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

/* Test against mobile viewports. */

Check failure on line 60 in playwright.config.ts

View workflow job for this annotation

GitHub Actions / Check Spelling

`viewports` is not a recognized word. (unrecognized-spelling)
// {
// 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' },

Check failure on line 73 in playwright.config.ts

View workflow job for this annotation

GitHub Actions / Check Spelling

`msedge` is not a recognized word. (unrecognized-spelling)
// },
// {
// name: 'Google Chrome',
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
// },
],

/* Run your local dev server before starting the tests */
webServer: {
command: 'pnpm dev',
port: 3000,
reuseExistingServer: true,
},
});
Loading

0 comments on commit 0c6ab47

Please sign in to comment.