Skip to content

Commit

Permalink
Generate E2E typescript test report for ReportPortal (#22590)
Browse files Browse the repository at this point in the history
feat: reportportal integration

Signed-off-by: mdolhalo <[email protected]>
  • Loading branch information
nallikaea authored Oct 27, 2023
1 parent a90153c commit 9fb1a12
Show file tree
Hide file tree
Showing 17 changed files with 462 additions and 72 deletions.
6 changes: 4 additions & 2 deletions tests/e2e/configs/mocharc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ module.exports = {
timeout: MOCHA_CONSTANTS.MOCHA_DEFAULT_TIMEOUT,
slow: 60000,
reporter: 'mocha-multi-reporters',
reporterOptions: 'configFile=configs/reporters-config.json',
reporterOptions: 'configFile=configs/reporters.config.js',
ui: 'tdd',
extension: ['js', 'cjs', 'mjs'],
require: ['dist/specs/MochaHooks.js', 'ts-node/register'],
bail: MOCHA_CONSTANTS.MOCHA_BAIL,
'full-trace': true,
Expand All @@ -39,5 +40,6 @@ module.exports = {
: MOCHA_CONSTANTS.MOCHA_USERSTORY
? [`dist/specs/**/${MOCHA_CONSTANTS.MOCHA_USERSTORY}.spec.js`, `dist/specs/${MOCHA_CONSTANTS.MOCHA_USERSTORY}.spec.js`]
: ['dist/specs/**/**.spec.js', 'dist/specs/**.spec.js'],
retries: MOCHA_CONSTANTS.MOCHA_RETRIES
retries: MOCHA_CONSTANTS.MOCHA_RETRIES,
grep: MOCHA_CONSTANTS.MOCHA_GREP
};
6 changes: 0 additions & 6 deletions tests/e2e/configs/reporters-config.json

This file was deleted.

51 changes: 51 additions & 0 deletions tests/e2e/configs/reporters.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/** *******************************************************************
* copyright (c) 2023 Red Hat, Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
const { REPORTER_CONSTANTS } = require('../constants/REPORTER_CONSTANTS');
const { BASE_TEST_CONSTANTS } = require('../constants/BASE_TEST_CONSTANTS');

module.exports = {
reporterEnabled: REPORTER_CONSTANTS.REPORTERS_ENABLED(),
allureMochaReporterOptions: {
resultsDir: '.allure-results'
},
reportportalAgentJsMochaReporterOptions: {
apiKey: REPORTER_CONSTANTS.RP_API_KEY,
endpoint: REPORTER_CONSTANTS.RP_ENDPOINT(),
project: REPORTER_CONSTANTS.RP_PROJECT(),
launch: `${REPORTER_CONSTANTS.RP_LAUNCH_NAME}`,
attributes: [
{
key: 'build',
value: `${BASE_TEST_CONSTANTS.TESTING_APPLICATION_VERSION}`
},
{
key: 'ocp version',
value: `${BASE_TEST_CONSTANTS.OCP_VERSION}`
},
{
key: 'ocp infra',
value: `${BASE_TEST_CONSTANTS.OCP_INFRA}`
},
{
key: 'application',
value: BASE_TEST_CONSTANTS.TESTING_APPLICATION_NAME()
},
{
key: 'url',
value: BASE_TEST_CONSTANTS.TS_SELENIUM_BASE_URL
}
],
rerun: REPORTER_CONSTANTS.RP_RERUN(),
rerunOf: REPORTER_CONSTANTS.RP_RERUN_UUID,
restClientConfig: {
timeout: 1200000
}
}
};
12 changes: 6 additions & 6 deletions tests/e2e/configs/sh-scripts/runFunctionalTests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

validateParameters(){
# Validate required parameters
if [ -z "$OCP_VERSION" ] || [ -z "$ARCH_VERSION" ] || [ -z "$TS_SELENIUM_BASE_URL" ]; then
echo "The ARCH_VERSION, OCP_VERSION or TS_SELENIUM_BASE_URL is not set!";
if [ -z "$OCP_VERSION" ] || [ -z "$OCP_INFRA" ] || [ -z "$TS_SELENIUM_BASE_URL" ]; then
echo "The OCP_INFRA, OCP_VERSION or TS_SELENIUM_BASE_URL is not set!";
echo "Please, set all required environment variable parameters"
exit 1
fi
Expand All @@ -17,22 +17,22 @@ validateParameters(){
launchAPITests() {
export MOCHA_SUITE="APITest"
echo "MOCHA_SUITE = ${MOCHA_SUITE}"
export RP_LAUNCH_NAME="API tests suite"
export RP_LAUNCH_NAME="API tests suite $TEST_ENVIRONMENT"
echo "suites/$MOCHA_DIRECTORY/$MOCHA_SUITE"
npm run driver-less-test
}

launchDynamicallyGeneratingAPITests() {
export MOCHA_SUITE="DynamicallyGeneratingAPITest"
export RP_LAUNCH_NAME="Application inbuilt DevWorkspaces API tests suite"
export RP_LAUNCH_NAME="Application inbuilt DevWorkspaces API tests suite $TEST_ENVIRONMENT"
echo "MOCHA_SUITE = ${MOCHA_SUITE}"
echo "suites/$MOCHA_DIRECTORY/$MOCHA_SUITE"
npm run delayed-test
}

launchUITests() {
export MOCHA_SUITE="UITest"
export RP_LAUNCH_NAME="UI tests suite"
export RP_LAUNCH_NAME="UI tests suite $TEST_ENVIRONMENT"
echo "MOCHA_SUITE = ${MOCHA_SUITE}"
echo "suites/$MOCHA_DIRECTORY/$MOCHA_SUITE"
npm run test
Expand All @@ -59,7 +59,7 @@ initTestValues() {
export MOCHA_DIRECTORY="online-ocp"
fi

export TEST_ENVIRONMENT="$ARCH_VERSION $MOCHA_DIRECTORY $OCP_VERSION"
export TEST_ENVIRONMENT="$OCP_INFRA $MOCHA_DIRECTORY $OCP_VERSION"
export DELETE_WORKSPACE_ON_FAILED_TEST=${DELETE_WORKSPACE_ON_FAILED_TEST:-'false'}
export DELETE_SCREENCAST_IF_TEST_PASS=${DELETE_SCREENCAST_IF_TEST_PASS:-'true'}
export NODE_TLS_REJECT_UNAUTHORIZED=${NODE_TLS_REJECT_UNAUTHORIZED:-'0'}
Expand Down
18 changes: 15 additions & 3 deletions tests/e2e/constants/BASE_TEST_CONSTANTS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export enum Platform {
}

export const BASE_TEST_CONSTANTS: {
ARCH_VERSION: string;
OCP_INFRA: string;
DELETE_WORKSPACE_ON_FAILED_TEST: boolean;
IS_CLUSTER_DISCONNECTED: () => boolean;
IS_PRODUCT_DOCUMENTATION_RELEASED: any;
Expand All @@ -30,16 +30,17 @@ export const BASE_TEST_CONSTANTS: {
TS_SELENIUM_PROJECT_ROOT_FILE_NAME: string;
TS_SELENIUM_REQUEST_INTERCEPTOR: boolean;
TS_SELENIUM_RESPONSE_INTERCEPTOR: boolean;
TESTING_APPLICATION_NAME: () => string;
} = {
/**
* base URL of the application which should be checked
*/
TS_SELENIUM_BASE_URL: !process.env.TS_SELENIUM_BASE_URL ? 'http://sample-url' : process.env.TS_SELENIUM_BASE_URL.replace(/\/$/, ''),

/**
* system arch type
* ocp infra type, possible values "PSI", "AWS", "IBM Z", "IBM Power"
*/
ARCH_VERSION: process.env.ARCH_VERSION || '',
OCP_INFRA: process.env.OCP_INFRA || '',

/**
* openShift version
Expand All @@ -51,6 +52,17 @@ export const BASE_TEST_CONSTANTS: {
*/
TEST_ENVIRONMENT: process.env.TEST_ENVIRONMENT || '',

/**
* application name (DevSpaces or Che)
*/
TESTING_APPLICATION_NAME: (): string => {
return BASE_TEST_CONSTANTS.TS_SELENIUM_BASE_URL.includes('devspaces')
? 'devspaces'
: BASE_TEST_CONSTANTS.TS_SELENIUM_BASE_URL.includes('che')
? 'che'
: 'default';
},

/**
* testing application version
*/
Expand Down
7 changes: 5 additions & 2 deletions tests/e2e/constants/MOCHA_CONSTANTS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const MOCHA_CONSTANTS: {
MOCHA_USERSTORY: undefined | string;
MOCHA_RETRIES: string | number;
MOCHA_BAIL: boolean;
MOCHA_GREP: string | undefined;
} = {
MOCHA_DIRECTORY: process.env.MOCHA_DIRECTORY || undefined,

Expand All @@ -26,9 +27,11 @@ export const MOCHA_CONSTANTS: {

MOCHA_DELAYED_SUITE: process.env.MOCHA_DELAYED_SUITE === 'true',

MOCHA_DEFAULT_TIMEOUT: process.env.MOCHA_DEFAULT_TIMEOUT || 420000,
MOCHA_DEFAULT_TIMEOUT: Number(process.env.MOCHA_DEFAULT_TIMEOUT) || 420000,

MOCHA_RETRIES: process.env.MOCHA_RETRIES || BASE_TEST_CONSTANTS.TEST_ENVIRONMENT === '' ? 0 : 2,

MOCHA_SUITE: process.env.MOCHA_SUITE || undefined
MOCHA_SUITE: process.env.MOCHA_SUITE || undefined,

MOCHA_GREP: process.env.MOCHA_GREP || undefined
};
103 changes: 98 additions & 5 deletions tests/e2e/constants/REPORTER_CONSTANTS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,29 @@
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
import { BASE_TEST_CONSTANTS } from './BASE_TEST_CONSTANTS';
import { MOCHA_CONSTANTS } from './MOCHA_CONSTANTS';

export const REPORTER_CONSTANTS: {
DELETE_SCREENCAST_IF_TEST_PASS: boolean;
RP_ENDPOINT(): string;
RP_IS_LOCAL_SERVER: boolean;
REPORTERS_ENABLED(): string;
RP_API_KEY: string;
RP_PROJECT(): string;
RP_RERUN(): boolean;
RP_RERUN_UUID: string | undefined;
RP_LAUNCH_NAME: string;
RP_USER: string;
RP_USE_PERSONAL: boolean;
SAVE_ALLURE_REPORT_DATA: boolean;
SAVE_RP_REPORT_DATA: boolean;
TS_SELENIUM_DELAY_BETWEEN_SCREENSHOTS: number;
TS_SELENIUM_REPORT_FOLDER: string;
TS_SELENIUM_EXECUTION_SCREENCAST: boolean;
TS_SELENIUM_PRINT_TIMEOUT_VARIABLES: string | boolean;
TS_SELENIUM_LOAD_TEST_REPORT_FOLDER: string;
TS_SELENIUM_LOG_LEVEL: string;
DELETE_SCREENCAST_IF_TEST_PASS: boolean;
TS_SELENIUM_PRINT_TIMEOUT_VARIABLES: string | boolean;
TS_SELENIUM_REPORT_FOLDER: string;
} = {
/**
* path to folder with load tests execution report.
Expand Down Expand Up @@ -44,10 +59,88 @@ export const REPORTER_CONSTANTS: {
/**
* log level settings, possible variants: 'INFO' (by default), 'DEBUG', 'TRACE'.
*/
TS_SELENIUM_LOG_LEVEL: process.env.TS_SELENIUM_LOG_LEVEL || 'INFO',
TS_SELENIUM_LOG_LEVEL: process.env.TS_SELENIUM_LOG_LEVEL || 'TRACE',

/**
* print all timeout variables when tests launch, default to false
*/
TS_SELENIUM_PRINT_TIMEOUT_VARIABLES: process.env.TS_SELENIUM_PRINT_TIMEOUT_VARIABLES || false
TS_SELENIUM_PRINT_TIMEOUT_VARIABLES: process.env.TS_SELENIUM_PRINT_TIMEOUT_VARIABLES === 'true',

/**
* use local Allure reporter, default to false
*/
SAVE_ALLURE_REPORT_DATA: process.env.SAVE_ALLURE_REPORT_DATA === 'true',

/**
* use ReportPortal reporter, default to false
*/
SAVE_RP_REPORT_DATA: process.env.SAVE_RP_REPORT_DATA === 'true',

/**
* list of enabler reporters
*/
REPORTERS_ENABLED: (): string => {
let reporters: string = 'dist/utils/CheReporter.js';
if (REPORTER_CONSTANTS.SAVE_ALLURE_REPORT_DATA) {
reporters += ',allure-mocha';
}
if (REPORTER_CONSTANTS.SAVE_RP_REPORT_DATA) {
reporters += ',@reportportal/agent-js-mocha';
}
return reporters;
},

/**
* reportPortal app key or user token
*/
RP_API_KEY: process.env.RP_API_KEY || '',

/**
* user name on ReportPortal
*/
RP_USER: process.env.RP_USER || process.env.USER || process.env.BUILD_USER_ID || '',

/**
* launch name to save report
*/
RP_LAUNCH_NAME: process.env.RP_LAUNCH_NAME || `Test run ${MOCHA_CONSTANTS.MOCHA_USERSTORY}`,

/**
* launch name to save report
*/
RP_RERUN_UUID: process.env.RP_RERUN_UUID || undefined,

/**
* is launch rerun
*/
RP_RERUN: (): boolean => !!REPORTER_CONSTANTS.RP_RERUN_UUID,

/**
* is local or online server to use
*/
RP_IS_LOCAL_SERVER: process.env.RP_IS_LOCAL_SERVER !== 'false',

/**
* url with endpoints where ReportPortal is
*/
RP_ENDPOINT: (): string => {
return process.env.RP_ENDPOINT || REPORTER_CONSTANTS.RP_IS_LOCAL_SERVER
? 'http://localhost:8080/api/v1'
: 'https://reportportal-crw.apps.ocp-c1.prod.psi.redhat.com/api/v1';
},

/**
* use personal project to save launch, if false launch will be send to devspaces or che project, true by default
*/
RP_USE_PERSONAL: process.env.RP_USE_PERSONAL !== 'false',

/**
* project name to save launch
*/
RP_PROJECT: (): string => {
const project: string = REPORTER_CONSTANTS.RP_USE_PERSONAL
? `${REPORTER_CONSTANTS.RP_USER}_personal`
: BASE_TEST_CONSTANTS.TESTING_APPLICATION_NAME();
return process.env.RP_PROJECT || project;
}
};
32 changes: 10 additions & 22 deletions tests/e2e/constants/TIMEOUT_CONSTANTS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,23 @@
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
export const TIMEOUT_CONSTANTS: {
TS_FIND_EXTENSION_TEST_TIMEOUT: number;
TS_SELENIUM_WORKSPACE_STATUS_POLLING: number;
TS_CLICK_DASHBOARD_ITEM_TIMEOUT: number;
TS_COMMON_DASHBOARD_WAIT_TIMEOUT: number;
TS_EXPAND_PROJECT_TREE_ITEM_TIMEOUT: number;
TS_DIALOG_WINDOW_DEFAULT_TIMEOUT: number;
TS_COMMON_PLUGIN_TEST_TIMEOUT: number;
TS_DASHBOARD_WORKSPACE_STOP_TIMEOUT: number;
TS_DIALOG_WINDOW_DEFAULT_TIMEOUT: number;
TS_EDITOR_TAB_INTERACTION_TIMEOUT: number;
TS_EXPAND_PROJECT_TREE_ITEM_TIMEOUT: number;
TS_FIND_EXTENSION_TEST_TIMEOUT: number;
TS_IDE_LOAD_TIMEOUT: number;
TS_SELENIUM_CLICK_ON_VISIBLE_ITEM: number;
TS_SELENIUM_DEFAULT_ATTEMPTS: number;
TS_SELENIUM_WORKSPACE_STATUS_ATTEMPTS: number;
TS_SELENIUM_WAIT_FOR_URL: number;
TS_SELENIUM_DEFAULT_POLLING: number;
TS_IDE_LOAD_TIMEOUT: number;
TS_SELENIUM_LOAD_PAGE_TIMEOUT: number;
TS_SELENIUM_START_WORKSPACE_TIMEOUT: number;
TS_SELENIUM_WAIT_FOR_URL: number;
TS_WAIT_LOADER_ABSENCE_TIMEOUT: number;
TS_WAIT_LOADER_PRESENCE_TIMEOUT: number;
TS_SELENIUM_START_WORKSPACE_TIMEOUT: number;
TS_SELENIUM_LOAD_PAGE_TIMEOUT: number;
TS_CLICK_DASHBOARD_ITEM_TIMEOUT: number;
TS_COMMON_PLUGIN_TEST_TIMEOUT: number;
TS_EDITOR_TAB_INTERACTION_TIMEOUT: number;
} = {
/**
* default amount of tries, "5" by default.
Expand All @@ -45,16 +43,6 @@ export const TIMEOUT_CONSTANTS: {
*/
TS_SELENIUM_WAIT_FOR_URL: Number(process.env.TS_SELENIUM_WAIT_FOR_URL) || 10_000,

/**
* amount of tries for checking workspace status.
*/
TS_SELENIUM_WORKSPACE_STATUS_ATTEMPTS: Number(process.env.TS_SELENIUM_WORKSPACE_STATUS_ATTEMPTS) || 90,

/**
* delay in milliseconds between checking workspace status tries.
*/
TS_SELENIUM_WORKSPACE_STATUS_POLLING: Number(process.env.TS_SELENIUM_WORKSPACE_STATUS_POLLING) || 10000,

/**
* wait between workspace started and IDE ready to be used, "20 000" by default.
*/
Expand Down
Loading

0 comments on commit 9fb1a12

Please sign in to comment.