Add E2E UI tests in CI
Diff
.github/workflows/integration-tests.yml | 40 ++++++++++++++++++++++++++++++++++++++++
chartered-frontend/tests/test.ts | 35 +++++++++++++++++++++++++++++++++++
2 files changed, 73 insertions(+), 2 deletions(-)
@@ -1,0 +1,40 @@
on: [push, pull_request]
name: CI - Integration Tests
jobs:
e2e-ui-test:
name: End-to-end UI tests
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- uses: actions/setup-node@v2
with:
node-version: '18'
- uses: actions-rs/cargo@v1
with:
command: build
args: -p chartered-web -p chartered-db --features sqlite
- name: Install dependencies
working-directory: ./chartered-frontend
run: npm ci
- name: Install Playwright
working-directory: ./chartered-frontend
run: npx playwright install --with-deps
- name: Run tests
working-directory: ./chartered-frontend
run: |
../target/debug/chartered-web -c ../chartered-web/config-example.toml &
sleep 5
npm test
- name: Upload test results
if: always()
uses: actions/upload-artifact@v2
with:
name: playwright-report
path: playwright-report
@@ -1,6 +1,37 @@
import { expect, test } from '@playwright/test';
test('index page has expected h1', async ({ page }) => {
test('redirect to login when unauthenticated', async ({ page }) => {
await page.goto('/');
expect(await page.textContent('h1')).toBe('Welcome to SvelteKit');
expect(await page.textContent('h1')).toBe('chartered ✈️');
expect(await page.textContent('button')).toBe('Login');
});
test('register button takes user to register page', async ({ page }) => {
await page.goto('/');
await page.locator('text=Register').click();
await expect(page).toHaveURL(/.*register/);
expect(await page.textContent('h1')).toBe('chartered ✈️');
expect(await page.textContent('button')).toBe('Register');
});
test('can successfully register and login', async ({ page }) => {
const username = Math.random().toString(36).substring(2,7);
const password = 'aaaaaaaa';
await page.goto('/');
await page.locator('text=Register').click();
await page.locator('input[id="username"]').fill(username);
await page.locator('input[id="password"]').fill(password);
await page.locator('text=Register').click();
await expect(page.locator('[role="alert"]')).toHaveCount(0);
await expect(page).toHaveURL(/.*login/);
await page.locator('input[id="username"]').fill(username);
await page.locator('input[id="password"]').fill(password);
await page.locator('text=Username Password Login >> button').click();
await expect(page).not.toHaveURL(/.*login/);
expect(await page.textContent('h1')).toBe('Welcome to Chartered.');
});