diff --git a/lib/testing/src/lib/core/actions/api.ts b/lib/testing/src/lib/core/actions/api.ts index fdc267a251..3bdb4d8f1d 100644 --- a/lib/testing/src/lib/core/actions/api.ts +++ b/lib/testing/src/lib/core/actions/api.ts @@ -15,24 +15,25 @@ * limitations under the License. */ -import { AlfrescoApi } from '@alfresco/js-api'; import { browser } from 'protractor'; +import { ApiService } from './api.service'; export abstract class Api { - public api: AlfrescoApi; - constructor(root: string) { - this.api = this.configureApi(root); + public api: ApiService; + + constructor() { + this.api = this.configureApi(); } - private configureApi(root: string): AlfrescoApi { + private configureApi(): ApiService { const config = browser.params.adminapp.apiConfig; - return new AlfrescoApi({ + return new ApiService({ provider: 'BPM', authType: config.authType, oauth2: config.oauth2, - hostBpm: config.bpmHost + '/' + root + hostBpm: config.bpmHost }); } diff --git a/lib/testing/src/lib/core/models/public-api.ts b/lib/testing/src/lib/core/models/public-api.ts index 5b16ef57a6..dee0bd51ba 100644 --- a/lib/testing/src/lib/core/models/public-api.ts +++ b/lib/testing/src/lib/core/models/public-api.ts @@ -16,3 +16,4 @@ */ export * from './user.model'; +export * from './application-model'; diff --git a/lib/testing/src/lib/core/utils/browser-actions.ts b/lib/testing/src/lib/core/utils/browser-actions.ts index ba924b3d08..69118a6df6 100644 --- a/lib/testing/src/lib/core/utils/browser-actions.ts +++ b/lib/testing/src/lib/core/utils/browser-actions.ts @@ -19,6 +19,9 @@ import { browser, by, element, ElementArrayFinder, ElementFinder, protractor } f import { BrowserVisibility } from '../utils/browser-visibility'; import { Logger } from './logger'; +import * as path from 'path'; +import * as fs from 'fs'; + export class BrowserActions { static async click(elementFinder: ElementFinder): Promise { @@ -124,4 +127,16 @@ export class BrowserActions { // if the opened menu has only disabled items, pressing escape to close it won't work await browser.actions().sendKeys(protractor.Key.ENTER).perform(); } + + static async takeScreenshot(screenshotFilePath: string, fileName: string) { + const pngData = await browser.takeScreenshot(); + const filenameWithExt = `${fileName}.png`; + Logger.info('Taking screenshot: ', filenameWithExt); + + const fileWithPath = path.join(screenshotFilePath, filenameWithExt); + const stream = fs.createWriteStream(fileWithPath); + stream.write(new Buffer(pngData, 'base64')); + stream.end(); + } + } diff --git a/lib/testing/src/lib/process-services-cloud/actions/application.ts b/lib/testing/src/lib/process-services-cloud/actions/application.ts index 3aa1fd7746..f138466af8 100644 --- a/lib/testing/src/lib/process-services-cloud/actions/application.ts +++ b/lib/testing/src/lib/process-services-cloud/actions/application.ts @@ -16,7 +16,6 @@ */ import { E2eRequestApiHelper } from '../../core/actions/e2e-request-api.helper'; -import { Api } from '../../core/actions/api'; import { Logger } from '../../core/utils/logger'; import { ResultSetPaging } from '@alfresco/js-api'; import { ApiService } from '../../core/actions/api.service'; @@ -26,7 +25,7 @@ export class Application { requestApiHelper: E2eRequestApiHelper; endPoint = `/deployment-service/v1/applications/`; - constructor(api: Api | ApiService) { + constructor(api: ApiService) { this.requestApiHelper = new E2eRequestApiHelper(api); } diff --git a/lib/testing/src/lib/process-services-cloud/actions/descriptor.ts b/lib/testing/src/lib/process-services-cloud/actions/descriptor.ts index a4532b7b62..ae8f3be3ec 100644 --- a/lib/testing/src/lib/process-services-cloud/actions/descriptor.ts +++ b/lib/testing/src/lib/process-services-cloud/actions/descriptor.ts @@ -17,56 +17,57 @@ import { NodeEntry } from '@alfresco/js-api'; import { E2eRequestApiHelper } from '../../core/actions/e2e-request-api.helper'; -import { Api } from '../../core/actions/api'; import { ApplicationRepresentation } from '../../core/models/application-model'; import { Logger } from '../../core/utils/logger'; import { ApiUtil } from '../../core/actions/api.util'; +import { ApiService } from '../../core/actions/api.service'; export class Descriptor { - requestApiHelper: E2eRequestApiHelper; - endPoint = `/v1/descriptors/`; - constructor(api: Api) { - this.requestApiHelper = new E2eRequestApiHelper(api); - } + requestApiHelper: E2eRequestApiHelper; + endPoint = `deployment-service/v1/descriptors/`; - async create(model: ApplicationRepresentation): Promise { - try { - await this.requestApiHelper.post(this.endPoint, { - bodyParam: model - }); - Logger.info(`[Descriptor] Descriptor has been created with name: ${model.name}.`); - } catch (error) { - Logger.error(`[Descriptor] Create descriptor ${model.name} failed with message: ${error.message}`); - throw error; + constructor(api: ApiService) { + this.requestApiHelper = new E2eRequestApiHelper(api); } - } - async delete(name: string): Promise { - try { - await this.retryUntilDescriptorIsInStatus(name, `DescriptorCreated`); - await this.requestApiHelper.delete(`${this.endPoint}${name}`); - Logger.info(`[Descriptor] Descriptor '${name}' was deleted successfully.`); - } catch (error) { - Logger.error(`[Descriptor] Delete descriptor ${name} failed with message: ${error.message}`); + async create(model: ApplicationRepresentation): Promise { + try { + await this.requestApiHelper.post(this.endPoint, { + bodyParam: model + }); + Logger.info(`[Descriptor] Descriptor has been created with name: ${model.name}.`); + } catch (error) { + Logger.error(`[Descriptor] Create descriptor ${model.name} failed with message: ${error.message}`); + throw error; + } } - } - async get(name: string): Promise { - Logger.info(`[Descriptor] Get descriptor ${name} details.`); - try { - return this.requestApiHelper.get(`${this.endPoint}${name}`); - } catch (error) { - Logger.error(`[Descriptor] Get descriptor ${name} details failed with message: ${error.message}`); + async delete(name: string): Promise { + try { + await this.retryUntilDescriptorIsInStatus(name, `DescriptorCreated`); + await this.requestApiHelper.delete(`${this.endPoint}${name}`); + Logger.info(`[Descriptor] Descriptor '${name}' was deleted successfully.`); + } catch (error) { + Logger.error(`[Descriptor] Delete descriptor ${name} failed with message: ${error.message}`); + } } - } - async retryUntilDescriptorIsInStatus(name: string, expectedStatus: string): Promise { - const predicate = (result: { status: string }) => { - return result.status === expectedStatus; - }; - const apiCall = async () => this.get(name); + async get(name: string): Promise { + Logger.info(`[Descriptor] Get descriptor ${name} details.`); + try { + return this.requestApiHelper.get(`${this.endPoint}${name}`); + } catch (error) { + Logger.error(`[Descriptor] Get descriptor ${name} details failed with message: ${error.message}`); + } + } - return ApiUtil.waitForApi(apiCall, predicate); - } + async retryUntilDescriptorIsInStatus(name: string, expectedStatus: string): Promise { + const predicate = (result: { status: string }) => { + return result.status === expectedStatus; + }; + const apiCall = async () => this.get(name); + + return ApiUtil.waitForApi(apiCall, predicate); + } } diff --git a/lib/testing/src/lib/process-services-cloud/actions/modeling-api.ts b/lib/testing/src/lib/process-services-cloud/actions/modeling-api.ts index b5d58912d1..20ba3585a6 100644 --- a/lib/testing/src/lib/process-services-cloud/actions/modeling-api.ts +++ b/lib/testing/src/lib/process-services-cloud/actions/modeling-api.ts @@ -24,18 +24,18 @@ import { NodeEntry, ResultSetPaging } from '@alfresco/js-api'; export class ModelingAPI extends Api { public project: Project; - constructor(ROOT: string = 'modeling-service') { - super(ROOT); + constructor() { + super(); } async setUp(): Promise { await this.login(); - this.project = new Project(this); + this.project = new Project(this.api); return this; } async tearDown(): Promise { - await this.api.logout(); + await this.api.apiService.logout(); } private async login(): Promise { @@ -74,5 +74,4 @@ export class ModelingAPI extends Api { const projects = await this.project.searchProjects(); return projects; } - } diff --git a/lib/testing/src/lib/process-services-cloud/actions/project.ts b/lib/testing/src/lib/process-services-cloud/actions/project.ts index 1bee98814a..30d7824820 100644 --- a/lib/testing/src/lib/process-services-cloud/actions/project.ts +++ b/lib/testing/src/lib/process-services-cloud/actions/project.ts @@ -16,26 +16,25 @@ */ import { browser } from 'protractor'; -import { ModelingAPI } from './modeling-api'; import { NodeEntry, ResultSetPaging } from '@alfresco/js-api'; import { ApiUtil } from '../../core/actions/api.util'; import { E2eRequestApiHelper, E2eRequestApiHelperOptions } from '../../core/actions/e2e-request-api.helper'; import * as fs from 'fs'; import { StringUtil } from '../../core/utils/string.util'; import { Logger } from '../../core/utils/logger'; +import { ApiService } from '../../core/actions/api.service'; export class Project { requestApiHelper: E2eRequestApiHelper; - endPoint = '/v1/projects/'; + endPoint = 'modeling-service/v1/projects/'; namePrefix: string = browser.params.namePrefix; - constructor(api: ModelingAPI) { + constructor(api: ApiService) { this.requestApiHelper = new E2eRequestApiHelper(api); } async create(modelName: string = this.getRandomName()): Promise { - const project = await this.requestApiHelper - .post(this.endPoint, {bodyParam: { name: modelName }}); + const project = await this.requestApiHelper.post(this.endPoint, {bodyParam: { name: modelName }}); Logger.info( `[Project] Project created with name: ${project.entry.name} and id: ${ @@ -57,11 +56,11 @@ export class Project { } async get(projectId: string): Promise { - return this.requestApiHelper.get(`/v1/projects/${projectId}`); + return this.requestApiHelper.get(`${this.endPoint}${projectId}`); } async delete(projectId: string): Promise { - await this.requestApiHelper.delete(`/v1/projects/${projectId}`); + await this.requestApiHelper.delete(`${this.endPoint}${projectId}`); Logger.info( `[Project] Project '${projectId}' was deleted successfully.` ); @@ -70,7 +69,7 @@ export class Project { async release(projectId: string): Promise { try { const release = await this.requestApiHelper - .post(`/v1/projects/${projectId}/releases`); + .post(`${this.endPoint}${projectId}/releases`); Logger.info(`[Project] Project '${projectId}' was released.`); return release; } catch (error) { @@ -82,7 +81,7 @@ export class Project { async getProjectRelease(projectId: string): Promise { try { return await this.requestApiHelper - .get(`/v1/projects/${projectId}/releases`); + .get(`${this.endPoint}${projectId}/releases`); } catch (error) { Logger.error(`[Project] Not able to fetch project release!`); throw error; @@ -97,7 +96,7 @@ export class Project { }; try { const project = await this.requestApiHelper - .post(`/v1/projects/import`, requestOptions); + .post(`${this.endPoint}import`, requestOptions); Logger.info(`[Project] Project imported with name '${project.entry.name}' and id '${project.entry.id}'.`); return project; } catch (error) {