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

fix: make failing e2e tests to create screenshot #22536

Merged
merged 2 commits into from
Sep 21, 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
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

cd tests/e2e && npm run lint && npm run prettier
cd tests/e2e && npm run lint && npm run tsc && npm run prettier
1 change: 1 addition & 0 deletions tests/e2e/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export * from './constants/API_TEST_CONSTANTS';
export * from './constants/BASE_TEST_CONSTANTS';
export * from './constants/CHROME_DRIVER_CONSTANTS';
export * from './constants/FACTORY_TEST_CONSTANTS';
export * from './constants/MOCHA_CONSTANTS';
export * from './constants/MONACO_CONSTANTS';
export * from './constants/OAUTH_CONSTANTS';
export * from './constants/PLUGIN_TEST_CONSTANTS';
Expand Down
25 changes: 9 additions & 16 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 @@
"eslint-plugin-header": "^3.1.1",
"eslint-plugin-jsdoc": "^46.5.0",
"eslint-plugin-prettier": "^5.0.0",
"inversify-inject-decorators": "^3.1.0",
"husky": "^8.0.3",
"mocha": "^9.1.3",
"monaco-page-objects": "3.9.1",
Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/specs/MochaHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ exports.mochaHooks = {
afterAll: [
async function stopTheDriver(): Promise<void> {
if (!BASE_TEST_CONSTANTS.TS_DEBUG_MODE && CHROME_DRIVER_CONSTANTS.TS_USE_WEB_DRIVER_FOR_TEST) {
// ensure that fired events done
await driverHelper.wait(5000);
await driverHelper.getDriver().quit();
Logger.info('Chrome driver session stopped.');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { FACTORY_TEST_CONSTANTS } from '../../constants/FACTORY_TEST_CONSTANTS';
const stackName: string = BASE_TEST_CONSTANTS.TS_SELENIUM_DASHBOARD_SAMPLE_NAME || 'Python';
const projectName: string = FACTORY_TEST_CONSTANTS.TS_SELENIUM_PROJECT_NAME || 'python-hello-world';

suite(`"Start workspace with existed workspace name" test`, function (): void {
suite('"Start workspace with existed workspace name" test', function (): void {
const workspaceHandlingTests: WorkspaceHandlingTests = e2eContainer.get(CLASSES.WorkspaceHandlingTests);
const projectAndFileTests: ProjectAndFileTests = e2eContainer.get(CLASSES.ProjectAndFileTests);
const loginTests: LoginTests = e2eContainer.get(CLASSES.LoginTests);
Expand All @@ -47,11 +47,11 @@ suite(`"Start workspace with existed workspace name" test`, function (): void {
expect(isFileImported).not.eqls(undefined);
});

test(`Stop created workspace`, async function (): Promise<void> {
test('Stop created workspace', async function (): Promise<void> {
existedWorkspaceName = WorkspaceHandlingTests.getWorkspaceName();
await workspaceHandlingTests.stopWorkspace(existedWorkspaceName);
await browserTabsUtil.closeAllTabsExceptCurrent();
});
});

test(`Create new workspace from the same ${stackName} stack`, async function (): Promise<void> {
existedWorkspaceName = WorkspaceHandlingTests.getWorkspaceName();
Expand Down
38 changes: 16 additions & 22 deletions tests/e2e/utils/CheReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,22 @@ import { CHROME_DRIVER_CONSTANTS } from '../constants/CHROME_DRIVER_CONSTANTS';
import { OAUTH_CONSTANTS } from '../constants/OAUTH_CONSTANTS';
import { REPORTER_CONSTANTS } from '../constants/REPORTER_CONSTANTS';
import { PLUGIN_TEST_CONSTANTS } from '../constants/PLUGIN_TEST_CONSTANTS';
import { inject, injectable } from 'inversify';
import { injectable } from 'inversify';
import getDecorators from 'inversify-inject-decorators';
import { e2eContainer } from '../configs/inversify.config';

const { lazyInject } = getDecorators(e2eContainer);

@injectable()
class CheReporter extends mocha.reporters.Spec {
private static methodIndex: number = 0;
private static deleteScreencast: boolean = true;
@lazyInject(CLASSES.DriverHelper)
private readonly driverHelper!: DriverHelper;
@lazyInject(CLASSES.ScreenCatcher)
private readonly screenCatcher!: ScreenCatcher;

constructor(
runner: mocha.Runner,
options: mocha.MochaOptions,
@inject(CLASSES.DriverHelper)
private readonly driverHelper: DriverHelper,
@inject(CLASSES.ScreenCatcher)
private readonly screenCatcher: ScreenCatcher
) {
constructor(runner: mocha.Runner, options: mocha.MochaOptions) {
super(runner, options);

runner.on('start', (): void => {
Expand Down Expand Up @@ -111,13 +112,7 @@ class CheReporter extends mocha.reporters.Spec {
}
});

runner.on('end', async (): Promise<void> => {
// ensure that fired events done
await this.driverHelper.wait(5000);

// close driver
await this.driverHelper.getDriver().quit();

runner.on('end', (): void => {
// delete screencast folder if conditions matched
if (CheReporter.deleteScreencast && REPORTER_CONSTANTS.DELETE_SCREENCAST_IF_TEST_PASS) {
rm.sync(REPORTER_CONSTANTS.TS_SELENIUM_REPORT_FOLDER);
Expand Down Expand Up @@ -158,14 +153,12 @@ class CheReporter extends mocha.reporters.Spec {
// take screenshot and write to file
const screenshot: string = await this.driverHelper.getDriver().takeScreenshot();
const screenshotStream: WriteStream = fs.createWriteStream(screenshotFileName);
screenshotStream.write(Buffer.from(screenshot, 'base64'));
screenshotStream.end();
screenshotStream.write(Buffer.from(screenshot, 'base64'), (): void => screenshotStream.end());

// take page source and write to file
const pageSource: string = await this.driverHelper.getDriver().getPageSource();
const pageSourceStream: WriteStream = fs.createWriteStream(pageSourceFileName);
pageSourceStream.write(Buffer.from(pageSource));
pageSourceStream.end();
pageSourceStream.write(Buffer.from(pageSource), (): void => pageSourceStream.end());

// take browser console logs and write to file
const browserLogsEntries: logging.Entry[] = await this.driverHelper.getDriver().manage().logs().get('browser');
Expand All @@ -176,8 +169,9 @@ class CheReporter extends mocha.reporters.Spec {
});

const browserLogsStream: WriteStream = fs.createWriteStream(browserLogsFileName);
browserLogsStream.write(Buffer.from(browserLogs));
browserLogsStream.end();
browserLogsStream.write(Buffer.from(browserLogs), (): void => {
browserLogsStream.end();
});
});
}
}
Expand Down
Loading