From 327bc56c0287bd917e6c729adbae77d690116296 Mon Sep 17 00:00:00 2001 From: Eugenio Romano Date: Mon, 9 Sep 2019 17:25:10 +0100 Subject: [PATCH] Log class in e2e plus check PS cloud CS works before run test (#5057) * check cs work on ps cloud add log class * fix env config --- .travis.yml | 1 + e2e/test.config.js | 15 ++---- .../actions/identity/applications.service.ts | 4 +- .../core/actions/identity/identity.service.ts | 7 ++- .../core/actions/identity/query.service.ts | 7 ++- .../core/actions/identity/tasks.service.ts | 25 ++++------ lib/testing/src/lib/core/utils/logger.ts | 48 +++++++++++++++++++ lib/testing/src/lib/core/utils/public-api.ts | 1 + .../actions/process-definitions.service.ts | 7 ++- .../actions/process-instances.service.ts | 9 ++-- lib/testing/src/lib/test.configuration.ts | 2 + protractor.conf.ts | 34 +++++-------- .../travis/e2e/process-services-cloud-e2e.sh | 2 + 13 files changed, 96 insertions(+), 66 deletions(-) create mode 100644 lib/testing/src/lib/core/utils/logger.ts diff --git a/.travis.yml b/.travis.yml index 15358fd2e1..ee98c32771 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ git: depth: 3 quiet: true + language: node_js dist: trusty sudo: required diff --git a/e2e/test.config.js b/e2e/test.config.js index 3e812a00d6..75b9126fa9 100644 --- a/e2e/test.config.js +++ b/e2e/test.config.js @@ -3,15 +3,7 @@ * @class config.test.config */ -let load_env_file = function () { - let ENV_FILE = process.env.ENV_FILE; - - if (ENV_FILE) { - require('dotenv').config({path: ENV_FILE}); - } -}; - -load_env_file(); +require('dotenv').config({path: process.env.ENV_FILE}); const HOST = process.env.URL_HOST_ADF; const HOST_BPM = process.env.URL_HOST_BPM_ADF; @@ -62,10 +54,12 @@ if (LOG) { module.exports = { - projectName :'ADF', + projectName: 'ADF', appConfig: appConfig, + log: LOG, + main: { timeout: TIMEOUT, rootPath: __dirname @@ -211,4 +205,5 @@ module.exports = { clientIdSso: "activiti" } + }; diff --git a/lib/testing/src/lib/core/actions/identity/applications.service.ts b/lib/testing/src/lib/core/actions/identity/applications.service.ts index 5d3bf554a1..2317df927d 100644 --- a/lib/testing/src/lib/core/actions/identity/applications.service.ts +++ b/lib/testing/src/lib/core/actions/identity/applications.service.ts @@ -16,6 +16,7 @@ */ import { ApiService } from '../api.service'; +import { Logger } from '../../utils/logger'; export class ApplicationsService { @@ -34,8 +35,7 @@ export class ApplicationsService { return this.api.performBpmOperation(path, method, queryParams, postBody); } catch (error) { - // tslint:disable-next-line:no-console - console.log('Get Applications - Service error, Response: ', JSON.parse(JSON.stringify(error)).response.text); + Logger.error('Get Applications - Service error, Response: ', JSON.parse(JSON.stringify(error)).response.text); } } diff --git a/lib/testing/src/lib/core/actions/identity/identity.service.ts b/lib/testing/src/lib/core/actions/identity/identity.service.ts index a7e4f08202..abfeae9fe9 100644 --- a/lib/testing/src/lib/core/actions/identity/identity.service.ts +++ b/lib/testing/src/lib/core/actions/identity/identity.service.ts @@ -19,6 +19,7 @@ import { ApiService } from '../api.service'; import { UserModel } from '../../models/user.model'; import { PersonBodyCreate } from '@alfresco/js-api'; import { RolesService } from './roles.service'; +import { Logger } from '../../utils/logger'; export class IdentityService { @@ -101,8 +102,7 @@ export class IdentityService { return this.api.performIdentityOperation(path, method, queryParams, postBody); } catch (error) { - // tslint:disable-next-line:no-console - console.log('Create User - Service error, Response: ', JSON.parse(JSON.stringify(error)).response.text); + Logger.error('Create User - Service error, Response: ', JSON.parse(JSON.stringify(error)).response.text); } } @@ -140,8 +140,7 @@ export class IdentityService { return this.api.performIdentityOperation(path, method, queryParams, postBody); } catch (error) { - // tslint:disable-next-line:no-console - console.log('Add User To Group - Service error, Response: ', JSON.parse(JSON.stringify(error))); + Logger.error('Add User To Group - Service error, Response: ', JSON.parse(JSON.stringify(error))); } } diff --git a/lib/testing/src/lib/core/actions/identity/query.service.ts b/lib/testing/src/lib/core/actions/identity/query.service.ts index d4dc8fef30..c516b795d3 100644 --- a/lib/testing/src/lib/core/actions/identity/query.service.ts +++ b/lib/testing/src/lib/core/actions/identity/query.service.ts @@ -16,6 +16,7 @@ */ import { ApiService } from '../api.service'; +import { Logger } from '../../utils/logger'; export class QueryService { @@ -34,8 +35,7 @@ export class QueryService { return this.api.performBpmOperation(path, method, queryParams, postBody); } catch (error) { - // tslint:disable-next-line:no-console - console.log('get process-instances Service error'); + Logger.error('get process-instances Service error'); } } @@ -48,8 +48,7 @@ export class QueryService { return this.api.performBpmOperation(path, method, queryParams, {}); } catch (error) { - // tslint:disable-next-line:no-console - console.log('get subprocesses process-instances Service error'); + Logger.error('get subprocesses process-instances Service error'); } } diff --git a/lib/testing/src/lib/core/actions/identity/tasks.service.ts b/lib/testing/src/lib/core/actions/identity/tasks.service.ts index b354c41cea..5692459516 100644 --- a/lib/testing/src/lib/core/actions/identity/tasks.service.ts +++ b/lib/testing/src/lib/core/actions/identity/tasks.service.ts @@ -16,6 +16,7 @@ */ import { ApiService } from '../api.service'; +import { Logger } from '../../utils/logger'; export class TasksService { @@ -38,8 +39,7 @@ export class TasksService { return this.api.performBpmOperation(path, method, queryParams, postBody); } catch (error) { - // tslint:disable-next-line:no-console - console.log('Create Task - Service error, Response: ', JSON.parse(JSON.stringify(error))); + Logger.error('Create Task - Service error, Response: ', JSON.parse(JSON.stringify(error))); } } @@ -57,8 +57,7 @@ export class TasksService { return this.api.performBpmOperation(path, method, queryParams, postBody); } catch (error) { - // tslint:disable-next-line:no-console - console.log('Create FormTask - Service error, Response: ', JSON.parse(JSON.stringify(error))); + Logger.error('Create FormTask - Service error, Response: ', JSON.parse(JSON.stringify(error))); } } @@ -71,8 +70,7 @@ export class TasksService { return this.api.performBpmOperation(path, method, queryParams, postBody); } catch (error) { - // tslint:disable-next-line:no-console - console.log('Complete Task - Service error, Response: ', JSON.parse(JSON.stringify(error)).response.text); + Logger.error('Complete Task - Service error, Response: ', JSON.parse(JSON.stringify(error)).response.text); } } @@ -86,8 +84,7 @@ export class TasksService { return this.api.performBpmOperation(path, method, queryParams, postBody); } catch (error) { - // tslint:disable-next-line:no-console - console.log('Claim Task - Service error, Response: ', JSON.parse(JSON.stringify(error)).response.text); + Logger.error('Claim Task - Service error, Response: ', JSON.parse(JSON.stringify(error)).response.text); } } @@ -100,8 +97,7 @@ export class TasksService { return this.api.performBpmOperation(path, method, queryParams, postBody); } catch (error) { - // tslint:disable-next-line:no-console - console.log('Delete Task - Service error, Response: ', JSON.parse(JSON.stringify(error)).response.text); + Logger.error('Delete Task - Service error, Response: ', JSON.parse(JSON.stringify(error)).response.text); } } @@ -121,8 +117,7 @@ export class TasksService { return this.api.performBpmOperation(path, method, queryParams, postBody); } catch (error) { - // tslint:disable-next-line:no-console - console.log('Get Task - Service error, Response: ', JSON.parse(JSON.stringify(error)).response.text); + Logger.error('Get Task - Service error, Response: ', JSON.parse(JSON.stringify(error)).response.text); } } @@ -136,8 +131,7 @@ export class TasksService { const data = await this.api.performBpmOperation(path, method, queryParams, postBody); return data.list.entries && data.list.entries.length > 0 ? data.list.entries[0].entry.id : null; } catch (error) { - // tslint:disable-next-line:no-console - console.log('Get Task Id - Service error, Response: ', JSON.parse(JSON.stringify(error)).response.text); + Logger.error('Get Task Id - Service error, Response: ', JSON.parse(JSON.stringify(error)).response.text); } } @@ -151,8 +145,7 @@ export class TasksService { return this.api.performBpmOperation(path, method, queryParams, postBody); } catch (error) { - // tslint:disable-next-line:no-console - console.log('Create Task - Service error, Response: ', JSON.parse(JSON.stringify(error)).response.text); + Logger.error('Create Task - Service error, Response: ', JSON.parse(JSON.stringify(error)).response.text); } } diff --git a/lib/testing/src/lib/core/utils/logger.ts b/lib/testing/src/lib/core/utils/logger.ts new file mode 100644 index 0000000000..65c6ac6724 --- /dev/null +++ b/lib/testing/src/lib/core/utils/logger.ts @@ -0,0 +1,48 @@ +/*! + * @license + * Copyright 2019 Alfresco Software, Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { browser } from 'protractor'; + +const infoColor = '\x1b[36m%s\x1b[0m', + logColor = '\x1b[35m%s\x1b[0m', + warnColor = '\x1b[33m%s\x1b[0m', + errorColor = '\x1b[31m%s\x1b[0m'; + +/* tslint:disable:no-console */ +export class Logger { + static info(...messages): void { + if (browser.params.config.log) { + console.log(infoColor, messages.join('')); + } + } + + static log(...messages): void { + if (browser.params.config.log) { + console.log(logColor, messages.join('')); + } + } + + static warn(...messages): void { + if (browser.params.config.log) { + console.log(warnColor, messages.join('')); + } + } + + static error(...messages): void { + console.log(errorColor, messages.join('')); + } +} diff --git a/lib/testing/src/lib/core/utils/public-api.ts b/lib/testing/src/lib/core/utils/public-api.ts index 4daa98e0da..94c3f185d7 100644 --- a/lib/testing/src/lib/core/utils/public-api.ts +++ b/lib/testing/src/lib/core/utils/public-api.ts @@ -23,3 +23,4 @@ export * from './local-storage.util'; export * from './file-browser.util'; export * from './form.util'; export * from './date-util'; +export * from './logger'; diff --git a/lib/testing/src/lib/process-services-cloud/actions/process-definitions.service.ts b/lib/testing/src/lib/process-services-cloud/actions/process-definitions.service.ts index af4c10df42..0a92fe1ce8 100644 --- a/lib/testing/src/lib/process-services-cloud/actions/process-definitions.service.ts +++ b/lib/testing/src/lib/process-services-cloud/actions/process-definitions.service.ts @@ -16,6 +16,7 @@ */ import { ApiService } from '../../core/actions/api.service'; +import { Logger } from '../../core/utils/logger'; export class ProcessDefinitionsService { @@ -35,11 +36,9 @@ export class ProcessDefinitionsService { return this.api.performBpmOperation(path, method, queryParams, {}); } catch (error) { if (error.status === 404) { - // tslint:disable-next-line:no-console - console.log(`${appName} not present`); + Logger.error(`${appName} not present`); } else if (error.status === 403) { - // tslint:disable-next-line:no-console - console.log(`Access to the requested resource has been denied ${appName}`); + Logger.error(`Access to the requested resource has been denied ${appName}`); } } } diff --git a/lib/testing/src/lib/process-services-cloud/actions/process-instances.service.ts b/lib/testing/src/lib/process-services-cloud/actions/process-instances.service.ts index 8e40b78f75..7539d208e3 100644 --- a/lib/testing/src/lib/process-services-cloud/actions/process-instances.service.ts +++ b/lib/testing/src/lib/process-services-cloud/actions/process-instances.service.ts @@ -16,6 +16,7 @@ */ import { ApiService } from '../../core/actions/api.service'; +import { Logger } from '../../core/utils/logger'; export class ProcessInstancesService { @@ -40,7 +41,7 @@ export class ProcessInstancesService { } catch (error) { // tslint:disable-next-line:no-console - console.log('create process-instances Service not working', error.message); + Logger.error('create process-instances Service not working', error.message); } } @@ -56,7 +57,7 @@ export class ProcessInstancesService { } catch (error) { // tslint:disable-next-line:no-console - console.log('suspend process-instances Service not working', error.message); + Logger.error('suspend process-instances Service not working', error.message); } } @@ -71,7 +72,7 @@ export class ProcessInstancesService { } catch (error) { // tslint:disable-next-line:no-console - console.log('delete process-instances Service not working', error.message); + Logger.error('delete process-instances Service not working', error.message); } } @@ -87,7 +88,7 @@ export class ProcessInstancesService { } catch (error) { // tslint:disable-next-line:no-console - console.log('complete process-instances Service not working', error.message); + Logger.error('complete process-instances Service not working', error.message); } } } diff --git a/lib/testing/src/lib/test.configuration.ts b/lib/testing/src/lib/test.configuration.ts index 7ef07fc559..e20943ed23 100644 --- a/lib/testing/src/lib/test.configuration.ts +++ b/lib/testing/src/lib/test.configuration.ts @@ -19,6 +19,8 @@ export interface TestConfiguration { appConfig: any; + log: boolean; + identityAdmin: { email: string, password: string diff --git a/protractor.conf.ts b/protractor.conf.ts index a46ccfe3dd..3c4bdcf410 100644 --- a/protractor.conf.ts +++ b/protractor.conf.ts @@ -12,15 +12,11 @@ const argv = require('yargs').argv; const projectRoot = path.resolve(__dirname); const width = 1366, height = 768; -let load_env_file = function () { - let ENV_FILE = process.env.ENV_FILE; +let ENV_FILE = process.env.ENV_FILE; - if (ENV_FILE) { - require('dotenv').config({ path: ENV_FILE }); - } -}; - -load_env_file(); +if (ENV_FILE) { + require('dotenv').config({ path: ENV_FILE }); +} let HOST = process.env.URL_HOST_ADF; let BROWSER_RUN = !!process.env.BROWSER_RUN; @@ -44,22 +40,10 @@ if (LOG) { console.log('SELENIUM_SERVER : ' + SELENIUM_SERVER); } -let browser_options = function () { - let args_options = ['--incognito', `--window-size=${width},${height}`, '--disable-gpu', '--disable-web-security', '--disable-browser-side-navigation']; - - if (BROWSER_RUN !== true) { - args_options.push('--headless') ; - } - - return args_options; -}; - -let args_options = browser_options(); - let downloadFolder = path.join(__dirname, 'e2e/downloads'); let specs = () => { - let specsToRun = './**/e2e/' + FOLDER + '/**/*.e2e.ts'; + let specsToRun = FOLDER ? './**/e2e/' + FOLDER + '/**/*.e2e.ts' : './**/e2e/**/*.e2e.ts'; if (LIST_SPECS.length === 0) { arraySpecs = [specsToRun]; @@ -100,7 +84,12 @@ exports.config = { 'default_directory': downloadFolder } }, - args: args_options + args: ['--incognito', + `--window-size=${width},${height}`, + '--disable-gpu', + '--disable-web-security', + '--disable-browser-side-navigation', + ...(BROWSER_RUN === true ? [] : ['--headless'])] } }, @@ -162,6 +151,7 @@ exports.config = { require('ts-node').register({ project: 'e2e/tsconfig.e2e.json' }); + require("tsconfig-paths").register({ project: 'e2e/tsconfig.e2e.json', baseUrl: 'e2e/', diff --git a/scripts/travis/e2e/process-services-cloud-e2e.sh b/scripts/travis/e2e/process-services-cloud-e2e.sh index 23385be4e7..a8269ec7a4 100755 --- a/scripts/travis/e2e/process-services-cloud-e2e.sh +++ b/scripts/travis/e2e/process-services-cloud-e2e.sh @@ -16,6 +16,8 @@ RUN_E2E=$(echo ./scripts/test-e2e-lib.sh -host http://localhost:4200 -proxy "$E2 if [[ $AFFECTED_LIBS =~ "testing" || $AFFECTED_LIBS =~ "$CONTEXT_ENV" || $TRAVIS_PULL_REQUEST == "false" ]]; then node ./scripts/check-env/check-activiti-env.js --host "$E2E_HOST_BPM" --oauth "$E2E_HOST_SSO" -u "$E2E_USERNAME" -p "$E2E_PASSWORD" --client 'activiti' || exit 1 + node ./scripts/check-env/check-cs-env.js --host "$E2E_HOST_BPM" -u "$E2E_USERNAME" -p "$E2E_PASSWORD" || exit 1 + $RUN_E2E --folder $CONTEXT_ENV else if [[ $AFFECTED_E2E = "e2e/$CONTEXT_ENV" ]]; then