Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/github-actions-after-push.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: GitHub Actions After Push Into Develop Branch
name: GitHub Actions After PR > Master
on:
pull_request:
branches: master
Expand Down
27 changes: 0 additions & 27 deletions .github/workflows/github-actions-manually.yml

This file was deleted.

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ node_modules/
/test-results/
/playwright-report/
/playwright/.cache/
/package-lock.json
/package-lock.json
/cache
1 change: 1 addition & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const config: PlaywrightTestConfig = {
trace: 'on-first-retry'
},

globalSetup: require.resolve('./src/setup/cacheWarmer.ts'),
/* Configure projects for major browsers */
projects: [
{
Expand Down
2 changes: 1 addition & 1 deletion src/FixtureConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type MyFixtures = {
export const test = base.extend<MyFixtures>({
loginPage: async ({ page }, use) => {
const loginPage = new LoginPage(page);
await page.routeFromHAR('cache/cache.har', { notFound: 'fallback', update: false });
await use(loginPage);
},
inventoryPage: async ({ page }, use) => {
Expand All @@ -22,6 +23,5 @@ export const test = base.extend<MyFixtures>({
const apiService = new ApiService(page);
await use(apiService);
},

});
export { expect } from '@playwright/test';
43 changes: 43 additions & 0 deletions src/setup/cacheWarmer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { chromium } from '@playwright/test';
import fs from 'fs';
import LoginPage from '../pages/LoginPage';

const dir = 'cache';

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export default async function globalSetup() {
console.log('[Checking a cache folder...]');

try {
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
console.log('[Creating a cache folder...]');
}
} catch (err) {
console.error(err);
}

console.log('[CACHE WARMER] Warming up static files cache...');
console.time('[CACHE WARMER] Done warming up static files cache.');

const browser = await chromium.launch();
const context = await browser.newContext({
recordHar: {
path: `${dir}/cache.har`,
urlFilter: /^.*\.(js|css|png|jpg|jpeg|gif|svg|ico|woff|woff2|ttf|eot)$/,
},
});

const page = await context.newPage();
const loginPage = new LoginPage(page);
const pagePath = await loginPage.getPageUrl();

// TODO: Remove hardcoded URL
await page.goto(pagePath, {
waitUntil: 'networkidle',
});
await page.close();
await context.close();
await browser.close();
console.timeEnd('[CACHE WARMER] Done warming up static files cache.');
}
Loading