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

feat: collect har file on test fail #22526

Merged
merged 2 commits into from
Oct 2, 2023
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
1 change: 1 addition & 0 deletions tests/e2e/driver/ChromeDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class ChromeDriver implements IDriver {

constructor() {
const options: Options = this.getDriverOptions();
options.setLoggingPrefs({ performance: 'ALL' });
if (CHROME_DRIVER_CONSTANTS.TS_USE_WEB_DRIVER_FOR_TEST) {
this.driver = this.getDriverBuilder(options).build();
}
Expand Down
77 changes: 77 additions & 0 deletions tests/e2e/package-lock.json

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

1 change: 1 addition & 0 deletions tests/e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"@typescript-eslint/parser": "^6.1.0",
"axios": "^0.25.0",
"chai": "^4.3.4",
"chrome-har": "^0.13.2",
"chromedriver": "^117.0.3",
"clone-deep": "^4.0.1",
"eslint": "^8.45.0",
Expand Down
12 changes: 12 additions & 0 deletions tests/e2e/utils/CheReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import { PLUGIN_TEST_CONSTANTS } from '../constants/PLUGIN_TEST_CONSTANTS';
import { injectable } from 'inversify';
import getDecorators from 'inversify-inject-decorators';
import { e2eContainer } from '../configs/inversify.config';
// @ts-ignore: No module declaration file
import * as chromeHar from 'chrome-har';

const { lazyInject } = getDecorators(e2eContainer);

Expand Down Expand Up @@ -135,6 +137,7 @@ class CheReporter extends mocha.reporters.Spec {
const screenshotFileName: string = `${testReportDirPath}/screenshot-${testTitle}.png`;
const pageSourceFileName: string = `${testReportDirPath}/pagesource-${testTitle}.html`;
const browserLogsFileName: string = `${testReportDirPath}/browserlogs-${testTitle}.txt`;
const harFileName: string = `${testReportDirPath}/har-${testTitle}.har`;

// create reporter dir if not exist
const reportDirExists: boolean = fs.existsSync(REPORTER_CONSTANTS.TS_SELENIUM_REPORT_FOLDER);
Expand Down Expand Up @@ -172,6 +175,15 @@ class CheReporter extends mocha.reporters.Spec {
browserLogsStream.write(Buffer.from(browserLogs), (): void => {
browserLogsStream.end();
});

// take networking logs and write to file
const networkLogsEntries: logging.Entry[] = await this.driverHelper.getDriver().manage().logs().get('performance');
dkwon17 marked this conversation as resolved.
Show resolved Hide resolved
const events = networkLogsEntries.map((entry) => JSON.parse(entry.message).message);
const har = chromeHar.harFromMessages(events, { includeTextFromResponseBody: true });
const networkLogsStream: WriteStream = fs.createWriteStream(harFileName);
networkLogsStream.write(Buffer.from(JSON.stringify(har)), (): void => {
networkLogsStream.end();
});
});
}
}
Expand Down
Loading