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

Test/avr 549 playwright tests #695

Merged
merged 3 commits into from
Nov 18, 2024
Merged
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
10 changes: 5 additions & 5 deletions .github/workflows/deploy-staging.yml
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ name: Deploy Staging

on:
release:
types: [ published ]
types: [published]
push:
branches:
- dev
@@ -12,7 +12,7 @@ on:
permissions:
contents: read
id-token: write

jobs:
build:
runs-on: ubuntu-latest
@@ -22,8 +22,8 @@ jobs:
- name: Use Node.js 14
uses: actions/setup-node@v4
with:
node-version: '14'
cache: 'npm'
node-version: "14"
cache: "npm"

- name: Install deps
run: |
@@ -38,7 +38,7 @@ jobs:
- name: Run E2E Tests
run: |
npm run e2e
npm run e2e:stg
- name: Build SSR
run: |
10 changes: 5 additions & 5 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -2,13 +2,13 @@ name: Deploy to ECS

on:
release:
types: [ published ]
types: [published]
workflow_dispatch:

permissions:
contents: read
id-token: write

jobs:
build:
runs-on: ubuntu-latest
@@ -18,8 +18,8 @@ jobs:
- name: Use Node.js 14
uses: actions/setup-node@v4
with:
node-version: '14'
cache: 'npm'
node-version: "14"
cache: "npm"

- name: Install deps
run: |
@@ -35,7 +35,7 @@ jobs:
- name: Run E2E Tests
continue-on-error: true
run: |
npm run e2e
npm run e2e:live
- name: Build SSR
run: |
10 changes: 5 additions & 5 deletions .github/workflows/deploy_dev.yml
Original file line number Diff line number Diff line change
@@ -2,12 +2,12 @@ name: Deploy to GH Pages (dev)

on:
push:
branches: [ dev ]
branches: [dev]

permissions:
contents: read
id-token: write

jobs:
build:
runs-on: ubuntu-latest
@@ -17,8 +17,8 @@ jobs:
- name: Use Node.js 14
uses: actions/setup-node@v4
with:
node-version: '14'
cache: 'npm'
node-version: "14"
cache: "npm"

- name: Install deps
run: |
@@ -33,7 +33,7 @@ jobs:
- name: Run E2E Tests
run: |
npm run e2e
npm run e2e:dev
- name: Build Beta
run: |
30 changes: 30 additions & 0 deletions .github/workflows/test-e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: E2E Tests
on:
workflow_dispatch:
inputs:
env:
description: "Environment to run tests against"
required: true
default: "live"
jobs:
test:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "14"
cache: "npm"
- name: Install dependencies
run: npm ci
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Run Playwright tests
run: npm run e2e:${{ github.event.inputs.env }}
- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: playwright-report
path: playwright-report/
retention-days: 14
37 changes: 0 additions & 37 deletions .github/workflows/test.yml

This file was deleted.

5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -41,3 +41,8 @@ testem.log
# System Files
.DS_Store
Thumbs.db
node_modules/
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -3,14 +3,15 @@
![Avrae.io](docs/avrae.png)

## Important Links

- [avrae.io](https://avrae.io)
- [Support Discord Server](http://support.avrae.io)
- [D&D Beyond Discord Server](https://dndbeyond.com/discord)
- [Build](https://travis-ci.org/avrae/avrae.io)

## Overview

This is the source code for the Angular website located at https://avrae.io. It serves as a web portal for users of the D&D Beyond Avrae Discord Bot to manage their data.
This is the source code for the Angular website located at https://avrae.io. It serves as a web portal for users of the D&D Beyond Avrae Discord Bot to manage their data.

## Local Config

@@ -34,7 +35,7 @@ Run `npm run dev:ssr`

To run end to end tests:

Run `ng e2e` or `npm run e2e`
Run `npm run e2e:<env>` where env is either `live`, `stg`, `dev` or `docker`

## Lint

12 changes: 12 additions & 0 deletions e2e/app.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { test, expect } from "@playwright/test";

test.describe("avrae frontpage", () => {
test.beforeEach(async ({ page }) => {
await page.goto("/");
});

test("should display welcome message", async ({ page }) => {
const paragraphText = await page.textContent("css=.about-avrae");
expect(paragraphText).toContain("I am Avrae");
});
});
35 changes: 35 additions & 0 deletions e2e/commands.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { test, expect } from "@playwright/test";
import { CommandsPage } from "./pages/commands";

test.describe("avrae commands page", () => {
let commandsPage: CommandsPage;

test.beforeEach(async ({ page }) => {
commandsPage = new CommandsPage(page);
await commandsPage.navigate();
});

test("should display a header", async () => {
const headerText = await commandsPage.getHeaderText();
expect(headerText).toEqual("Avrae Commands");
});

test("should show some modules", async () => {
const renderedModules = await commandsPage.getRenderedModules();
for (const moduleElement of await renderedModules.all()) {
expect(moduleElement);
}
});

test("should show some commands in each module", async () => {
const renderedModules = await commandsPage.getRenderedModules();
for (const moduleElement of await renderedModules.all()) {
const moduleCommands = await commandsPage.getModuleCommands(
moduleElement
);
for (const commandElement of await moduleCommands.all()) {
expect(commandElement).toBeVisible();
}
}
});
});
25 changes: 25 additions & 0 deletions e2e/pages/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Page } from "@playwright/test";

export class CommandsPage {
readonly page: Page;

constructor(page: Page) {
this.page = page;
}

async navigate() {
await this.page.goto("/commands");
}

async getHeaderText() {
return this.page.textContent("h1");
}

async getRenderedModules() {
return this.page.locator("css=.module-container");
}

async getModuleCommands(moduleElement) {
return moduleElement.locator("css=avr-command-display");
}
}
10 changes: 0 additions & 10 deletions e2e/protractor-ci.conf.js

This file was deleted.

28 changes: 0 additions & 28 deletions e2e/protractor.conf.js

This file was deleted.

14 changes: 0 additions & 14 deletions e2e/src/app.e2e-spec.ts

This file was deleted.

11 changes: 0 additions & 11 deletions e2e/src/app.po.ts

This file was deleted.

25 changes: 0 additions & 25 deletions e2e/src/commands.e2e-spec.ts

This file was deleted.

13 changes: 0 additions & 13 deletions e2e/tsconfig.e2e.json

This file was deleted.

6 changes: 6 additions & 0 deletions e2e/urls.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const URLS = {
live: "https://avrae.io",
stg: "",
dev: "http://localhost:4200",
docker: "http://localhost:8000",
};
15,319 changes: 65 additions & 15,254 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -10,7 +10,10 @@
"lint": "ng lint",
"build-themes:dev": "python ./tools/build-themes.py",
"build-themes": "bash ./tools/build-themes.sh",
"e2e": "ng e2e --protractor-config=e2e/protractor-ci.conf.js --configuration production",
"e2e:docker": "TESTING_ENV=docker npx playwright test",
"e2e:dev": "TESTING_ENV=dev npx playwright test",
"e2e:stg": "TESTING_ENV=dev npx playwright test",
"e2e:live": "TESTING_ENV=live npx playwright test",
"dev:ssr": "npm run build-themes && ng run frontend:serve-ssr",
"serve:ssr": "node dist/frontend/server/main.js",
"build:ssr": "ng build && ng run frontend:server",
@@ -57,6 +60,7 @@
"@angular/compiler-cli": "^13.3.9",
"@angular/language-service": "^13.3.9",
"@nguniversal/builders": "^13.1.1",
"@playwright/test": "^1.48.2",
"@types/express": "^4.17.11",
"@types/express-serve-static-core": "^4.17.21",
"@types/jasmine": "~3.7.7",
81 changes: 81 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { defineConfig, devices } from "@playwright/test";
import { URLS } from "./e2e/urls";

/**
* 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: "./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: URLS[process.env.TESTING_ENV || "live"],

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: "on-first-retry",
screenshot: "only-on-failure",
},

/* 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 start',
// url: 'http://127.0.0.1:3000',
// reuseExistingServer: !process.env.CI,
// },
});
5 changes: 1 addition & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -15,9 +15,6 @@
},
{
"path": "./src/tsconfig.server.json"
},
{
"path": "./e2e/tsconfig.e2e.json"
}
]
}
}