Skip to content

Commit

Permalink
feat(tests): add Playwright for e2e testing
Browse files Browse the repository at this point in the history
  • Loading branch information
olgapod committed Oct 11, 2024
1 parent 92d9d15 commit 9cf08ce
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ ganache-accounts.json
.dappPids.json
cypress/videos
cypress/screenshots
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/

.vscode
.DS_Store
Expand Down
60 changes: 60 additions & 0 deletions package-lock.json

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

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@
"prepare": "if [ -z \"$SKIP_HOOKS\" ]; then import-meta-env-prepare -x .env.example -p .env.local .env.local.secrets && import-meta-env-typescript -x .env.example -o src/typedefs; fi",
"postinstall": "if [ -z \"$SKIP_HOOKS\" ]; then ./scripts/lambda-functions-dependencies.sh && scripts/generate-amplify-local-config.sh; fi",
"watch-amplify": "node scripts/watchAmplifyFiles",
"forward-time": "node scripts/forward-time"
"forward-time": "node scripts/forward-time",
"playwright:install": "npx playwright install --with-deps",
"playwright:run": "playwright test",
"playwright:watch": "playwright test --ui"
},
"repository": {
"type": "git",
Expand All @@ -61,6 +64,7 @@
"@jackfranklin/test-data-bot": "^1.4.0",
"@jest/globals": "^29.0.2",
"@limegrass/eslint-plugin-import-alias": "^1.4.1",
"@playwright/test": "^1.48.0",
"@storybook/addon-essentials": "^8.0.0",
"@storybook/addon-interactions": "^8.0.0",
"@storybook/addon-links": "^8.0.0",
Expand Down
79 changes: 79 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { defineConfig, devices } from '@playwright/test';

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// import dotenv from 'dotenv';
// import path from 'path';
// dotenv.config({ path: path.resolve(__dirname, '.env') });

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './playwright/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://localhost:9091',

/* 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',
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: 'npm run frontend',
url: 'http://localhost:9091',
reuseExistingServer: !process.env.CI,
},
});
32 changes: 32 additions & 0 deletions playwright/README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Playwright Testing

This folder contains Playwright tests for the application.
For more details on Playwright, you can visit the [Playwright documentation](https://playwright.dev/).

## Installation (only before the first test run)

To install the necessary dependencies for Playwright, run the following command:

```bash
npm run playwright:install
```

## Running the Tests

To execute the Playwright tests, use one of the following commands:

Run all tests:

```bash
npm run playwright:run
```

This will run all Playwright tests in the headless mode.

Run tests in watch mode:

```bash
npm run playwright:watch
```

This will launch Playwright's UI for running tests interactively, allowing you to watch and debug them in real time.
7 changes: 7 additions & 0 deletions playwright/e2e/example.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { test, expect } from '@playwright/test';

test('has title', async ({ page }) => {
await page.goto('/');

await expect(page).toHaveTitle('Welcome to Colony');
});
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@
"target": "es2020",
"types": ["vite/client"]
},
"include": ["src"]
"include": ["src", "playwright.config.ts", "playwright"]
}

0 comments on commit 9cf08ce

Please sign in to comment.