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

[FR-344] feat: auto screenshot with Playwrite #3011

Merged
merged 1 commit into from
Jan 10, 2025
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
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Logs
logs
*.log
Expand Down Expand Up @@ -63,6 +62,10 @@ typings/
# dotenv environment variables file
.env

# dotenv environment variables file for playwright test
/e2e/envs/*
!/e2e/envs/.env.playwright.sample

# next.js build output
.next

Expand Down Expand Up @@ -139,3 +142,5 @@ yarn.lock
/playwright-report/
/blob-report/
/playwright/.cache/

/e2e/screenshots/*
1 change: 1 addition & 0 deletions e2e/envs/.env.playwright.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SCREENSHOT_PATH=./screenshots
106 changes: 106 additions & 0 deletions e2e/screenshot.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import { loginAsAdmin, webuiEndpoint } from './test-util';
import { test } from '@playwright/test';
import * as path from 'path';

const routes = [
'/summary',
'/session',
'/session/start',
'/serving',
'/service',
'/service/start',
'/import',
'/data',
'/my-environment',
'/agent-summary',
'/statistics',
'/environment',
'/agent',
'/settings',
'/maintenance',
'/information',
'/usersettings',
'/credential',
'/logs',
'/error',
'/unauthorized',
];

test.describe.configure({ mode: 'parallel' });
test.describe.skip('Screenshot all routes', () => {
let screenshotPath: string;
test.beforeEach(async ({ page }) => {
await loginAsAdmin(page);
screenshotPath = process.env.SCREENSHOT_PATH
? path.resolve(process.env.SCREENSHOT_PATH)
: path.resolve(__dirname + '/screenshots');
});

routes.forEach((route) => {
test(`screenshot ${route}`, async ({ page }) => {
await page.goto(`${webuiEndpoint}${route}`, {
waitUntil: 'networkidle',
});
await page.screenshot({
path: path.resolve(
`${screenshotPath}/${route.replace(/\//g, '_')}.png`,
),
fullPage: true,
});
});

test(`screenshot ${route} (dark mode)`, async ({ page }) => {
await page.goto(`${webuiEndpoint}${route}`, {
waitUntil: 'networkidle',
});
await page.getByRole('button', { name: 'moon' }).click();
// Wait for the dark mode to be applied
await page.waitForTimeout(500);
await page.screenshot({
path: path.resolve(
`${screenshotPath}/${route.replace(/\//g, '_')}_dark.png`,
),
fullPage: true,
});
});

test(`screenshot ${route} without sidebar`, async ({ page }) => {
await page.goto(`${webuiEndpoint}${route}`, {
waitUntil: 'networkidle',
});
await page.screenshot({
path: path.resolve(
`${screenshotPath}/${route.replace(/\//g, '_')}_no_sidebar.png`,
),
clip: {
x: 240,
y: 0,
width: (page.viewportSize()?.width || 0) - 240,
height: page.viewportSize()?.height || 0,
},
});
});

test(`screenshot ${route} without sidebar (dark mode)`, async ({
page,
}) => {
await page.goto(`${webuiEndpoint}${route}`, {
waitUntil: 'networkidle',
});
await page.getByRole('button', { name: 'moon' }).click();
// Wait for the dark mode to be applied
await page.waitForTimeout(500);
await page.screenshot({
path: path.resolve(
`${screenshotPath}/${route.replace(/\//g, '_')}_no_sidebar_dark.png`,
),
clip: {
x: 240,
y: 0,
width: (page.viewportSize()?.width || 0) - 240,
height: page.viewportSize()?.height || 0,
},
});
});
});
});
2 changes: 0 additions & 2 deletions e2e/test-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import {
expect,
request,
} from '@playwright/test';
import fs from 'fs/promises';
import path from 'path';

export const webuiEndpoint = 'http://127.0.0.1:9081';
export const webServerEndpoint = 'http://127.0.0.1:8090';
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
"@babel/preset-typescript": "^7.24.7",
"@babel/types": "^7.25.2",
"@electron/packager": "^18.3.3",
"@playwright/test": "^1.46.1",
"@playwright/test": "^1.49.1",
"@rollup/plugin-commonjs": "^25.0.8",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-replace": "^5.0.7",
Expand Down
2 changes: 2 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { defineConfig, devices } from '@playwright/test';
import * as dotenv from 'dotenv';
dotenv.config({ path: './e2e/envs/.env.playwright' });

/**
* Read environment variables from file.
Expand Down
47 changes: 37 additions & 10 deletions pnpm-lock.yaml

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

Loading