Skip to content

Commit

Permalink
Set Up Automated Testing with Playwright (#688)
Browse files Browse the repository at this point in the history
## Description
This PR introduces the foundation for our automated end-to-end (E2E)
testing suite using `playwright`. We've implemented initial test
scenarios covering critical user flows across three key areas of our
application.

### Test Scenarios Implemented:

1. **Legal Pages**
   - Verify page titles
   - Confirm page existence

2. **Login Page**
   - Ensure login page loads correctly
   - Validate successful login functionality

3. **Create Organization Page**
   - Test creation with mandatory information only
   - Test creation with mandatory information and description
   - Validate handling of missing inputs
   - Verify responses to incorrect inputs

### Technical Details:
- Framework: Playwright
- Browsers Tested: Chromium, Firefox

## Type of Change
- [x] New feature (non-breaking change which adds functionality)
- [x] This change requires a documentation update

## Impact
This change lays the groundwork for comprehensive automated testing,
which will:
- Improve code quality and reliability
- Accelerate the development process by catching issues early
- Enhance confidence in deployments

## Additional Context
Documentation on the testing framework, including how to start the
tester locally, add new tests and best practices, will be added to the
StreamETH Notion. This will serve as a guide for current and future
developers to understand and expand our testing suite.
  • Loading branch information
xannyxs authored Aug 12, 2024
1 parent 11c0363 commit 904c7bd
Show file tree
Hide file tree
Showing 15 changed files with 903 additions and 52 deletions.
23 changes: 0 additions & 23 deletions .github/workflows/main.yml

This file was deleted.

145 changes: 145 additions & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
name: Playwright Tests with Dependency and Artifact Caching

on:
push:
branches: [main]
pull_request:
branches: [develop, main]

jobs:
install:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Node 20
uses: actions/setup-node@v4
with:
node-version: "20"

- name: Install yarn and dependencies
run: |
npm install -g yarn
yarn install
- name: Install Playwright browsers
run: yarn playwright install --with-deps

- name: Build application
run: yarn build
env:
NEXT_PUBLIC_SPACE_STORAGE_URL: ${{ secrets.NEXT_PUBLIC_SPACE_STORAGE_URL }}
NEXT_PUBLIC_STUDIO_API_KEY: ${{ secrets.NEXT_PUBLIC_STUDIO_API_KEY }}
NEXT_PUBLIC_API_URL: ${{ secrets.NEXT_PUBLIC_API_URL }}
NEXT_PUBLIC_PRIVY_ID: ${{ secrets.NEXT_PUBLIC_PRIVY_ID }}
SPACES_KEY: ${{ secrets.SPACES_KEY }}
SPACES_SECRET: ${{ secrets.SPACES_SECRET }}
SPACE_STORAGE_PATH: ${{ secrets.SPACE_STORAGE_PATH }}

- name: Save .next directory
uses: actions/upload-artifact@v4
with:
name: next-artifact
if-no-files-found: error
path: packages/app/.next

chrome-tests:
needs: install
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node 20
uses: actions/setup-node@v4
with:
node-version: "20"

- name: Install dependencies
run: |
npm install -g yarn
yarn install
- name: Install Playwright browsers
run: yarn playwright install --with-deps chromium

- name: Download the build folders
uses: actions/download-artifact@v4
with:
name: next-artifact
path: packages/app/.next

- name: Run Playwright tests on Chrome
run: |
cd packages/app
yarn playwright test --project=chromium
env:
NEXT_PUBLIC_SPACE_STORAGE_URL: ${{ secrets.NEXT_PUBLIC_SPACE_STORAGE_URL }}
NEXT_PUBLIC_STUDIO_API_KEY: ${{ secrets.NEXT_PUBLIC_STUDIO_API_KEY }}
NEXT_PUBLIC_API_URL: ${{ secrets.NEXT_PUBLIC_API_URL }}
NEXT_PUBLIC_PRIVY_ID: ${{ secrets.NEXT_PUBLIC_PRIVY_ID }}
SPACES_KEY: ${{ secrets.SPACES_KEY }}
SPACES_SECRET: ${{ secrets.SPACES_SECRET }}
SPACE_STORAGE_PATH: ${{ secrets.SPACE_STORAGE_PATH }}
PRIVY_EMAIL: ${{ secrets.PRIVY_EMAIL }}
PRIVY_OTP: ${{ secrets.PRIVY_OTP }}
ORG_NAME: test_org

- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: playwright-report-chrome
path: packages/app/playwright-report
retention-days: 30

firefox-tests:
needs: install
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node 20
uses: actions/setup-node@v4
with:
node-version: "20"

- name: Install dependencies
run: |
npm install -g yarn
yarn install
- name: Install Playwright browsers
run: yarn playwright install --with-deps

- name: Download the build folders
uses: actions/download-artifact@v4
with:
name: next-artifact
path: packages/app/.next

- name: Run Playwright tests on Firefox
run: |
cd packages/app
yarn playwright test --project=firefox
env:
NEXT_PUBLIC_SPACE_STORAGE_URL: ${{ secrets.NEXT_PUBLIC_SPACE_STORAGE_URL }}
NEXT_PUBLIC_STUDIO_API_KEY: ${{ secrets.NEXT_PUBLIC_STUDIO_API_KEY }}
NEXT_PUBLIC_API_URL: ${{ secrets.NEXT_PUBLIC_API_URL }}
NEXT_PUBLIC_PRIVY_ID: ${{ secrets.NEXT_PUBLIC_PRIVY_ID }}
SPACES_KEY: ${{ secrets.SPACES_KEY }}
SPACES_SECRET: ${{ secrets.SPACES_SECRET }}
SPACE_STORAGE_PATH: ${{ secrets.SPACE_STORAGE_PATH }}
PRIVY_EMAIL: ${{ secrets.PRIVY_EMAIL }}
PRIVY_OTP: ${{ secrets.PRIVY_OTP }}
ORG_NAME: test_org

- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: playwright-report-firefox
path: packages/app/playwright-report
retention-days: 30
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ node_modules

.yarn/*
.yarn

# testing
/coverage
/playwright

# next.js
/.next/
Expand Down
6 changes: 6 additions & 0 deletions packages/app/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ node_modules

# testing
/coverage
/playwright

# next.js
/.next/
Expand All @@ -26,6 +27,7 @@ yarn-error.log*

# local env files
.env*.local
*.env

# vercel
.vercel
Expand All @@ -45,3 +47,7 @@ google_sa_secret.json

# Sentry Config File
.sentryclirc
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
Original file line number Diff line number Diff line change
Expand Up @@ -206,19 +206,3 @@ export default function CreateOrganizationForm({
</Form>
);
}

{
/* <FormField
control={form.control}
name="url"
render={({ field }) => (
<FormItem>
<FormLabel className="">Company website</FormLabel>
<FormControl>
<Input placeholder="Company website" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/> */
}
2 changes: 1 addition & 1 deletion packages/app/components/misc/ConnectWalletButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const ConnectWalletButton = ({
return (
<Button variant={'primary'} onClick={show} className={className}>
<span className="px-2 md:px-0">
{isConnected ? ensName ?? truncatedAddress : btnText}
{isConnected ? (ensName ?? truncatedAddress) : btnText}
</span>
</Button>
);
Expand Down
9 changes: 7 additions & 2 deletions packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
"start": "next start -H 0.0.0.0 -p 3000",
"lint": "next lint",
"check-types": "tsc --noEmit --incremental",
"prettier:fix": "prettier --write './app' './components' './lib'",
"prettier:check": "prettier --check './app' './components' './lib'"
"test:ui": "dotenvx run -f test.env -- playwright test --ui",
"test": "dotenvx run -f test.env -- playwright test",
"prettier:fix": "prettier --write './app' './components' './lib' ./tests",
"prettier:check": "prettier --check './app' './components' './lib' ./tests/"
},
"dependencies": {
"@aws-sdk/client-s3": "^3.509.0",
Expand Down Expand Up @@ -97,6 +99,8 @@
"zod": "^3.22.4"
},
"devDependencies": {
"@dotenvx/dotenvx": "^1.0.1",
"@playwright/test": "^1.37.0",
"@tailwindcss/typography": "^0.5.13",
"@types/fuzzy-search": "^2.1.5",
"@types/lodash": "^4.17.7",
Expand All @@ -105,6 +109,7 @@
"@types/react-color": "^3.0.11",
"@types/react-dom": "18.2.15",
"@types/react-scroll": "^1.8.7",
"dotenv": "^16.4.5",
"eslint": "8.50.0",
"eslint-config-next": "^14.2.5",
"next-bundle-analyzer": "^0.6.8",
Expand Down
79 changes: 79 additions & 0 deletions packages/app/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { defineConfig, devices } from '@playwright/test'
import path from 'path';

require('dotenv').config({path: path.resolve(__dirname, 'test.env')})

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './tests',
/* Run tests in files in parallel */
fullyParallel: false,
/* 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 : 1,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : 2,
/* 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: {
baseURL: 'http://localhost:3000',
trace: 'on-first-retry',
},

/* Configure projects for major browsers */
projects: [
{ name: 'setup', testMatch: /.*\.setup\.ts/ },
{
name: 'chromium',
use: {
...devices['Desktop Chrome'], storageState: 'packages/app/playwright/.auth/user.json',
},
dependencies: ['setup'],

},

{
name: 'firefox',
use: {
...devices['Desktop Firefox'], storageState: 'packages/app/playwright/.auth/user.json',
},
dependencies: ['setup'],
},

//{
// 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: 'yarn start',
url: 'http://127.0.0.1:3000',
reuseExistingServer: !process.env.CI,
},
})
7 changes: 7 additions & 0 deletions packages/app/tests/core.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('http://localhost:3000/studio');

await expect(page).toHaveTitle(/StreamETH/);
});
Loading

0 comments on commit 904c7bd

Please sign in to comment.