Skip to content

Commit

Permalink
starting playwright tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Zwiterrion committed Dec 13, 2024
1 parent afca8ac commit 5a04fc3
Show file tree
Hide file tree
Showing 9 changed files with 838 additions and 2,774 deletions.
3 changes: 2 additions & 1 deletion otoroshi/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ companion.txt
/route-d.json
/service.json
/zips
outsideplugins.scala
outsideplugins.scala
playwright-report
4 changes: 4 additions & 0 deletions otoroshi/javascript/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
node_modules
.DS_Store
stats.json
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
11 changes: 5 additions & 6 deletions otoroshi/javascript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
},
"dependencies": {
"@fortawesome/fontawesome-free": "^6.2.0",
"@maif/react-forms": "1.0.60",
"ace-builds": "^1.11.2",
"antd": "^4.21.4",
"apollo-link-ws": "1.0.8",
Expand All @@ -51,9 +50,9 @@
"moment": "2.29.4",
"prop-types": "15.7.2",
"query-string": "9.1.1",
"react": "16.13.1",
"react": "16.14.0",
"react-ace": "12.0.0",
"react-dom": "16.13.1",
"react-dom": "16.14.0",
"react-query": "^3.39.3",
"react-redux": "^7.2.1",
"react-router-dom": "5.2.0",
Expand All @@ -78,14 +77,16 @@
"@babel/plugin-syntax-dynamic-import": "7.8.3",
"@babel/preset-env": "7.11.5",
"@babel/preset-react": "7.10.4",
"@playwright/test": "^1.49.1",
"@types/node": "^22.10.2",
"babel-eslint": "10.1.0",
"babel-loader": "^8.2.5",
"babel-minify-webpack-plugin": "0.3.1",
"classnames": "2.2.6",
"compression-webpack-plugin": "^10.0.0",
"cross-env": "7.0.2",
"crypto-browserify": "^3.12.0",
"css-loader": "^6.7.1",
"css-minimizer-webpack-plugin": "7.0.0",
"eslint": "7.9.0",
"eslint-plugin-react": "7.20.6",
"file-loader": "6.1.0",
Expand All @@ -100,11 +101,9 @@
"rimraf": "3.0.2",
"sass": "1.26.11",
"sass-loader": "^13.0.2",
"speed-measure-webpack-plugin": "1.3.3",
"stream-browserify": "^3.0.0",
"style-loader": "^3.3.1",
"terser-webpack-plugin": "^5.3.3",
"uglifyjs-webpack-plugin": "2.2.0",
"url-loader": "^4.1.1",
"webpack": "5.76.0",
"webpack-bundle-analyzer": "^4.5.0",
Expand Down
42 changes: 42 additions & 0 deletions otoroshi/javascript/playwright.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { defineConfig, devices } from '@playwright/test';

export default defineConfig({
testDir: './tests',
fullyParallel: true,
timeout: 12000,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
workers: process.env.CI ? 1 : undefined,
reporter: 'html',
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
baseURL: 'http://otoroshi.oto.tools:9999',
trace: 'on-first-retry',
},
projects: [
{
name: 'setup',
testMatch: /.*\.setup\.js/
},
{
name: 'chromium',
use: {
...devices['Desktop Chrome'],
// Use prepared auth state.
storageState: 'playwright/.auth/user.json',
},
dependencies: ['setup']
},

{
name: 'firefox',
use: {
...devices['Desktop Firefox'],
// Use prepared auth state.
storageState: 'playwright/.auth/user.json',
},
dependencies: ['setup']
}
]
});

15 changes: 15 additions & 0 deletions otoroshi/javascript/playwright/.auth/user.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"cookies": [
{
"name": "otoroshi-session",
"value": "eyJhbGciOiJIUzI1NiJ9.eyJkYXRhIjp7ImJvdXNyIjoiTnRuN3U0ZzVkT0lMQ3V0T0dZN0xiQmVZZnhZMG1MeDQ5dUNMUGFjS3ZKdFRpVmF3OXpEdDU1cUxMU2g0Y255MiJ9LCJleHAiOjE3MzQzNjA2MjAsIm5iZiI6MTczNDEwMTQyMCwiaWF0IjoxNzM0MTAxNDIwfQ.zNLQdWjxCpAconS36kmiOKdJ9pP4E3X8fQawctv5Nog",
"domain": ".oto.tools",
"path": "/",
"expires": 1734360620.163286,
"httpOnly": true,
"secure": false,
"sameSite": "Lax"
}
],
"origins": []
}
15 changes: 15 additions & 0 deletions otoroshi/javascript/tests/playwright/.auth/user.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"cookies": [
{
"name": "otoroshi-session",
"value": "eyJhbGciOiJIUzI1NiJ9.eyJkYXRhIjp7ImJvdXNyIjoiZ0ZrTHVTNFhFVG1ldndZVk1PVThxZHFleUtqTTF1WGpGUkdDVDJUQ3BpeVpVS0EwRkE0YWlDVUNzN0FZV3A2cyJ9LCJleHAiOjE3MzQzNjM3NjgsIm5iZiI6MTczNDEwNDU2OCwiaWF0IjoxNzM0MTA0NTY4fQ.jQiIwMJwvcBKR5M6bK1UZV-DSPktvvk0ibPgYTOg2So",
"domain": ".oto.tools",
"path": "/",
"expires": 1734363768.209069,
"httpOnly": true,
"secure": false,
"sameSite": "Lax"
}
],
"origins": []
}
21 changes: 21 additions & 0 deletions otoroshi/javascript/tests/setup/auth.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { test as setup, expect } from '@playwright/test';
import path from 'path';

const authFile = path.join(__dirname, '../playwright/.auth/user.json');

setup('authenticate', async ({ page }) => {
// Perform authentication steps. Replace these actions with your own.
await page.goto('/');
await page.getByRole('button', { name: 'Login', exact: true }).click();
await page.locator('input[name="email"]').click();
await page.locator('input[name="email"]').fill('[email protected]');
await page.locator('input[name="email"]').press('Tab');
await page.locator('input[name="password"]').fill('password');
await page.getByRole('button', { name: 'Login' }).click();

await page.waitForURL('/bo/dashboard');

await expect(page.locator('#content-scroll-container img')).toBeVisible();

await page.context().storageState({ path: authFile });
});
50 changes: 50 additions & 0 deletions otoroshi/javascript/tests/spec/otoroshi.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const { test, expect } = require('@playwright/test');

const SECTIONS = {
MANAGE_RESOURCES: 'Manage resources',
CONFIGURATION: 'Configuration',
ANALYTICS: 'Analytics',
NETWORKING: 'Networking',
SESSIONS: 'Sessions',
TOOLING: 'Tooling',
}

async function showTableOfEntity(page, section, tab, expected) {
await page.goto('/');

await page.getByText(section).click();
await page
.locator(`div[title^="${tab}"]`).click();

await expect(page.locator('#content-scroll-container')).toContainText(expected ? expected : tab);
}

test('Show Routes', async ({ page }) => showTableOfEntity(page, SECTIONS.MANAGE_RESOURCES, 'Routes'));
test('Show Services', async ({ page }) => showTableOfEntity(page, SECTIONS.MANAGE_RESOURCES, 'Services'));
test('Show Admins', async ({ page }) => showTableOfEntity(page, SECTIONS.MANAGE_RESOURCES, 'Administrator', 'All administrators'));
test('Show Data Exporters', async ({ page }) => showTableOfEntity(page, SECTIONS.MANAGE_RESOURCES, 'Data exporters'));
test('Show Apikeys', async ({ page }) => showTableOfEntity(page, SECTIONS.MANAGE_RESOURCES, 'Apikeys'));
test('Show Auth. modules', async ({ page }) => showTableOfEntity(page, SECTIONS.MANAGE_RESOURCES, 'Auth. modules', 'Authentication modules'));
test('Show Backends', async ({ page }) => showTableOfEntity(page, SECTIONS.MANAGE_RESOURCES, 'Backends'));
test('Show Drafts', async ({ page }) => showTableOfEntity(page, SECTIONS.MANAGE_RESOURCES, 'Drafts'));
test('Show Error Templates', async ({ page }) => showTableOfEntity(page, SECTIONS.MANAGE_RESOURCES, 'Error Templates', 'Error templates'));
test('Show JWT verifiers', async ({ page }) => showTableOfEntity(page, SECTIONS.MANAGE_RESOURCES, 'JWT verifiers', 'Jwt verifiers'));
test('Show Service Groups', async ({ page }) => showTableOfEntity(page, SECTIONS.MANAGE_RESOURCES, 'Service groups', 'Groups'));
test('Show TCP Services', async ({ page }) => showTableOfEntity(page, SECTIONS.MANAGE_RESOURCES, 'TCP services', 'Tcp services'));
test('Show Teams', async ({ page }) => showTableOfEntity(page, SECTIONS.MANAGE_RESOURCES, 'Teams'));
test('Show Wasm Plugins', async ({ page }) => showTableOfEntity(page, SECTIONS.MANAGE_RESOURCES, 'Wasm Plugins', 'Wasm plugins'));

test('Show Cluster members', async ({ page }) => showTableOfEntity(page, SECTIONS.NETWORKING, 'Cluster members'));
test('Show Connected tunnels', async ({ page }) => showTableOfEntity(page, SECTIONS.NETWORKING, 'Connected tunnels'));
test('Show Eureka servers', async ({ page }) => showTableOfEntity(page, SECTIONS.NETWORKING, 'Eureka servers'));

test('Show Resources loader', async ({ page }) => showTableOfEntity(page, SECTIONS.TOOLING, 'Resources loader'));

test('Show Danger zone', async ({ page }) => showTableOfEntity(page, SECTIONS.CONFIGURATION, 'Danger zone'));

test('Show Alerts log', async ({ page }) => showTableOfEntity(page, SECTIONS.ANALYTICS, 'Alerts log'));
test('Show Analytics', async ({ page }) => showTableOfEntity(page, SECTIONS.ANALYTICS, 'Analytics'));
test('Show Audit log', async ({ page }) => showTableOfEntity(page, SECTIONS.ANALYTICS, 'Audit log'));
test('Show Events log', async ({ page }) => showTableOfEntity(page, SECTIONS.ANALYTICS, 'Events log'));
test('Show Global Status', async ({ page }) => showTableOfEntity(page, SECTIONS.ANALYTICS, 'Global Status', 'Global status'));

Loading

0 comments on commit 5a04fc3

Please sign in to comment.