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

Sets project up to run Playwright tests in CI against local app changes #21

Merged
merged 7 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// Features to add to the dev container. More info: https://containers.dev/features.
"features": {
"ghcr.io/devcontainers/features/python:1": {},
"ghcr.io/devcontainers/features/node:1": {},
"ghcr.io/devcontainers/features/docker-in-docker:2": {}
},

Expand Down
7 changes: 1 addition & 6 deletions .devcontainer/on-setup.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,5 @@ wget -q https://raw.githubusercontent.com/dapr/cli/master/install/install.sh -O

# Initialize dapr
dapr uninstall --all # clean if needed
dapr init

# Install python dependencies
pip install -r ./src/backend/requirements.txt

# dotnet restore
dotnet restore ./src/frontend/PetSpotR/PetSpotR.csproj
scripts/setup
20 changes: 19 additions & 1 deletion .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
name: Playwright Tests

on:
push:
branches:
Expand All @@ -8,6 +7,14 @@ on:
branches:
- main
workflow_dispatch:
inputs:
url:
description: URL to test
required: false
default: http://localhost:5114/

env:
TEST_URL: ${{ github.event.inputs.url || 'http://localhost:5114/' }}

jobs:
test:
Expand All @@ -19,6 +26,17 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version: 16
- name: Cache Playwright Browsers
uses: actions/cache@v2
with:
path: ~/.cache/ms-playwright
key: ${{ runner.os }}-node-${{ hashFiles('tests/playwright/package.json') }}-${{ hashFiles('tests/playwright/playwright.config.ts') }}
- name: Dapr tool installer
if: ${{ env.TEST_URL == 'http://localhost:5114/' }}
uses: dapr/setup-dapr@v1
- name: Setup app locally
if: ${{ env.TEST_URL == 'http://localhost:5114/'}}
run: scripts/setup
- name: Install dependencies
run: |
cd tests/playwright
Expand Down
6 changes: 3 additions & 3 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
{
"label": "dapr-up-frontend",
"type": "shell",
"command": [ "dapr run --app-id frontend --app-port 5114 --components-path ./iac/dapr/local --dapr-http-port 3501 --dapr-grpc-port 50001"],
"command": ["scripts/dev-frontend"],
"isBackground": true,
"dependsOn": "build",
"problemMatcher": [
Expand Down Expand Up @@ -72,7 +72,7 @@
{
"label": "dapr-up-backend",
"type": "shell",
"command": [ "dapr run --app-id backend --app-port 5000 --components-path ./iac/dapr/local --dapr-http-port 3502 --dapr-grpc-port 50002"],
"command": ["scripts/dev-backend"],
"isBackground": true,
"dependsOn": "build",
"problemMatcher": [
Expand Down Expand Up @@ -102,4 +102,4 @@
}
}
]
}
}
11 changes: 11 additions & 0 deletions scripts/dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

set -e

lsof -ti :5114,5000 | xargs kill || true

dotnet watch --project "$(dirname "$0")/../src/frontend/PetSpotR/PetSpotR.csproj" run &
$(dirname "$0")/dev-backend &
$(dirname "$0")/dev-frontend &

wait
5 changes: 5 additions & 0 deletions scripts/dev-backend
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

set -e

dapr run --app-id backend --app-port 5000 --components-path ./iac/dapr/local --dapr-http-port 3502 --dapr-grpc-port 50002
5 changes: 5 additions & 0 deletions scripts/dev-frontend
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

set -e

dapr run --app-id frontend --app-port 5114 --components-path ./iac/dapr/local --dapr-http-port 3501 --dapr-grpc-port 50001
16 changes: 16 additions & 0 deletions scripts/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

set -e

dapr init

# Install python dependencies
pip install -r ./src/backend/requirements.txt

# dotnet restore
dotnet restore ./src/frontend/PetSpotR/PetSpotR.csproj

# install playwright browsers
cd tests/playwright
npm install
npx playwright install --with-deps
99 changes: 69 additions & 30 deletions tests/playwright/package-lock.json

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

2 changes: 1 addition & 1 deletion tests/playwright/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"author": "",
"license": "ISC",
"devDependencies": {
"@playwright/test": "^1.30.0"
"@playwright/test": "^1.46.1"
}
}
21 changes: 15 additions & 6 deletions tests/playwright/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import { devices } from '@playwright/test';
*/
// require('dotenv').config();

const test_url = process.env.TEST_URL?.trim() || undefined;

if (test_url) {
console.log(`Testing against ${test_url}`);
}

/**
* See https://playwright.dev/docs/test-configuration.
*/
Expand Down Expand Up @@ -35,8 +41,9 @@ const config: PlaywrightTestConfig = {
use: {
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
actionTimeout: 0,

/* Base URL to use in actions like `await page.goto('/')`. */
// baseURL: 'http://localhost:3000',
baseURL: test_url ?? `http://localhost:5114/`,

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
Expand Down Expand Up @@ -96,12 +103,14 @@ const config: PlaywrightTestConfig = {

/* Folder for test artifacts such as screenshots, videos, traces, etc. */
// outputDir: 'test-results/',
};

if (test_url?.includes('localhost')) {
/* Run your local dev server before starting the tests */
// webServer: {
// command: 'npm run start',
// port: 3000,
// },
};
config.webServer = {
command: '../../scripts/dev',
url: 'http://localhost:5114/'
};
}

export default config;
4 changes: 2 additions & 2 deletions tests/playwright/tests/homepage.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { test, expect } from '@playwright/test';

test('has title', async ({ page }) => {
await page.goto('http://app.9e5524d3a2474ae58276.westus3.aksapp.io/');
await page.goto('/');

// Expect a title "to contain" a substring.
await expect(page).toHaveTitle(/PetSpotR/);
});

test('get started link', async ({ page }) => {
await page.goto('http://app.9e5524d3a2474ae58276.westus3.aksapp.io/');
await page.goto('/');

// Click the get started link.
await page.getByRole('button', { name: 'I lost my pet' }).click();
Expand Down
Loading