Skip to content
This repository has been archived by the owner on Mar 31, 2024. It is now read-only.

Commit

Permalink
fix screenshot saving and error
Browse files Browse the repository at this point in the history
  • Loading branch information
dmlemeshko committed Jun 4, 2020
1 parent 5b16040 commit 6b3e7fa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
20 changes: 14 additions & 6 deletions packages/kbn-test/src/page_load_metrics/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@ import Url from 'url';
import _ from 'lodash';
import puppeteer from 'puppeteer';
import { resolve } from 'path';
import { ToolingLog, REPO_ROOT } from '@kbn/dev-utils';
import { ToolingLog } from '@kbn/dev-utils';
import { ResponseReceivedEvent, DataReceivedEvent } from './event';

const failureDir = resolve(REPO_ROOT, 'x-pack/test/page_load_metrics/screenshots/failure');

export interface NavigationOptions {
headless: boolean;
appConfig: { url: string; username: string; password: string };
screenshotsDir?: string;
}

export type NavigationResults = Map<string, Map<string, FrameResponse>>;
Expand Down Expand Up @@ -137,15 +136,24 @@ export async function navigateToApps(log: ToolingLog, options: NavigationOptions
continue;
}

await page.bringToFront();
const failureDir = options.screenshotsDir
? resolve(options.screenshotsDir, 'failure')
: resolve(__dirname, 'screenshots/failure');
const screenshotPath = resolve(
failureDir,
`${app.path.slice(1).split('/').join('_')}_navigation.png`
);
Fs.mkdirSync(failureDir, { recursive: true });

await page.bringToFront();
await page.screenshot({
path: resolve(failureDir, `${app.path.split('/').join('_')}_navigation.png`),
path: screenshotPath,
type: 'png',
fullPage: true,
});
log.debug(`Saving screenshot to ${screenshotPath}`);

throw error;
throw new Error(`Page load timeout: ${app.path} not loaded after 30 seconds`);
}
}

Expand Down
3 changes: 3 additions & 0 deletions x-pack/test/page_load_metrics/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export async function PuppeteerTestRunner({ getService }: FtrProviderContext) {
const config = getService('config');
const esArchiver = getService('esArchiver');

const screenshotsDir = config.get('screenshots.directory');

await esArchiver.load('default');
const metrics = await capturePageLoadMetrics(log, {
headless: true,
Expand All @@ -24,6 +26,7 @@ export async function PuppeteerTestRunner({ getService }: FtrProviderContext) {
username: config.get('servers.kibana.username'),
password: config.get('servers.kibana.password'),
},
screenshotsDir,
});
const reporter = CiStatsReporter.fromEnv(log);

Expand Down

0 comments on commit 6b3e7fa

Please sign in to comment.