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(tests): add Playwright for e2e testing #3297

Merged
merged 3 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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') });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing this will be uncommented for something later on?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will remove them for now


/**
* 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' },
// },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, guessing these will be uncommented when sorting out mobile tests?

],

/* 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"]
}
Loading