[AAE-1884] e2e shared file and refactor custom sources (#5506)

* fix lint
e2e shared file and refactor custom sources
additional tests for search chip list (#5523)

* modify wait startegy

* fix metadata problem

* improve method retry

* login before to execute call

* login before to execute call
This commit is contained in:
Eugenio Romano
2020-03-02 10:28:38 +00:00
committed by GitHub
parent 7c849d87f4
commit 7a2af38699
23 changed files with 145 additions and 132 deletions

View File

@@ -125,7 +125,7 @@ export class FormFields {
}
async selectForm(formName): Promise<void> {
await this.selectFormDropdown.clickDropdownWithOption(formName);
await this.selectFormDropdown.selectDropdownOption(formName);
}
async selectFormFromDropDown(formName): Promise<void> {

View File

@@ -47,7 +47,7 @@ export class SettingsPage {
}
async setProvider(option): Promise<void> {
await this.providerDropdown.clickDropdownWithOption(option);
await this.providerDropdown.selectDropdownOption(option);
await this.providerDropdown.checkOptionIsSelected(option);
}

View File

@@ -0,0 +1,52 @@
/*!
* @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.
*/
/*
* Copyright 2005-2019 Alfresco Software, Ltd. All rights reserved.
*
* License rights for this program may be obtained from Alfresco Software, Ltd.
* pursuant to a written agreement and any use of this program without such an
* agreement is prohibited.
*/
export type ApiResultPredicate<T> = (result: T) => boolean;
export type ApiCall<T> = () => Promise<T>;
export class ApiUtil {
static async waitForApi<T>(apiCall: ApiCall<T>, predicate: ApiResultPredicate<T>, retry: number = 30, delay: number = 1000) {
const apiCallWithPredicateChecking = async () => {
const apiCallResult = await apiCall();
if (predicate(apiCallResult)) {
return Promise.resolve(apiCallResult);
} else {
return Promise.reject(apiCallResult);
}
};
return ApiUtil.retryCall(apiCallWithPredicateChecking, retry, delay);
}
static retryCall(fn: () => Promise<any>, retry: number = 30, delay: number = 1000): Promise<any> {
const pause = duration => new Promise(res => setTimeout(res, duration));
const run = retries => {
return fn().catch(err => (retries > 1 ? pause(delay).then(() => run(retries - 1)) : Promise.reject(err)));
};
return run(retry);
}
}

View File

@@ -18,7 +18,7 @@
import { browser } from 'protractor';
import { ModelingAPI } from './modeling-api';
import { NodeEntry, ResultSetPaging } from '@alfresco/js-api';
import { UtilApi } from './utilapi';
import { ApiUtil } from './api.util';
import { E2eRequestApiHelper, E2eRequestApiHelperOptions } from './e2e-request-api.helper';
import * as fs from 'fs';
import { StringUtil } from '../utils/string.util';
@@ -123,7 +123,7 @@ export class Project {
};
const apiCall = () => this.searchProjects();
return UtilApi.waitForApi(apiCall, predicate);
return ApiUtil.waitForApi(apiCall, predicate);
}
private getRandomName(): string {

View File

@@ -16,6 +16,6 @@
*/
export * from './api';
export * from './utilapi';
export * from './api.util';
export * from './deployment-api';
export * from './modeling-api';

View File

@@ -1,44 +0,0 @@
/*!
* @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.
*/
export type ApiResultPredicate<T> = (result: T) => boolean;
export type ApiCall<T> = () => Promise<T>;
export class UtilApi {
static async waitForApi<T>(apiCall: ApiCall<T>, predicate: ApiResultPredicate<T>) {
const apiCallWithPredicateChecking = async () => {
const apiCallResult = await apiCall();
if (predicate(apiCallResult)) {
return Promise.resolve(apiCallResult);
} else {
return Promise.reject(apiCallResult);
}
};
return UtilApi.retryCall(apiCallWithPredicateChecking);
}
static retryCall(fn: () => Promise<any>, retry: number = 30, delay: number = 1000): Promise<any> {
const pause = (duration: number) => new Promise((res) => setTimeout(res, duration));
const run = (retries: number) => {
return fn().catch((err) => (retries > 1 ? pause(delay).then(() => run(retries - 1)) : Promise.reject(err)));
};
return run(retry);
}
}

View File

@@ -19,17 +19,9 @@ export class StringUtil {
static generatePasswordString(length: number = 8): string {
let text = '';
const possibleUpperCase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
const possibleLowerCase = 'abcdefghijklmnopqrstuvwxyz';
const lowerCaseLimit = Math.floor(length / 2);
for (let i = 0; i < lowerCaseLimit; i++) {
text += possibleLowerCase.charAt(Math.floor(Math.random() * possibleLowerCase.length));
}
for (let i = 0; i < length - lowerCaseLimit; i++) {
text += possibleUpperCase.charAt(Math.floor(Math.random() * possibleUpperCase.length));
}
text += StringUtil.generateRandomCharset(lowerCaseLimit, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ');
text += StringUtil.generateRandomCharset(length - lowerCaseLimit, 'abcdefghijklmnopqrstuvwxyz');
return text;
}
@@ -38,17 +30,9 @@ export class StringUtil {
* Generates a random string.
*
* @param length If this parameter is not provided the length is set to 8 by default.
* @method generateRandomString
*/
static generateRandomString(length: number = 8): string {
let text = '';
const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
for (let i = 0; i < length; i++) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
return text;
return StringUtil.generateRandomCharset(length, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789');
}
/**
@@ -56,16 +40,9 @@ export class StringUtil {
*
* @param domain
* @param length
* @method generateRandomEmail
*/
static generateRandomEmail(domain: string, length: number = 5): string {
let email = '';
const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
for (let i = 0; i < length; i++) {
email += possible.charAt(Math.floor(Math.random() * possible.length));
}
let email = StringUtil.generateRandomCharset(length, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789');
email += domain;
return email.toLowerCase();
}
@@ -74,33 +51,34 @@ export class StringUtil {
* Generates a random string - digits only.
*
* @param length {int} If this parameter is not provided the length is set to 8 by default.
* @method generateRandomString
*/
static generateRandomStringDigits(length: number = 8): string {
let text = '';
const possible = '0123456789';
for (let i = 0; i < length; i++) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
return text;
return StringUtil.generateRandomCharset(length, '0123456789');
}
/**
* Generates a random string - non-latin characters only.
*
* @param length {int} If this parameter is not provided the length is set to 3 by default.
* @method generateRandomString
*/
static generateRandomStringNonLatin(length: number = 3): string {
return StringUtil.generateRandomCharset(length, '密码你好𠮷');
}
/**
* Generates a random string.
*
* @param length If this parameter is not provided the length is set to 8 by default.
* @param charSet to use
*/
static generateRandomCharset(length: number = 8, charSet: string): string {
let text = '';
const possible = '密码你好𠮷';
for (let i = 0; i < length; i++) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
text += charSet.charAt(Math.floor(Math.random() * charSet.length));
}
return text;
}
}

View File

@@ -80,7 +80,7 @@ export class DropdownPage {
await BrowserVisibility.waitUntilElementIsNotVisible(element(by.cssContainingText('mat-option span.mat-option-text', option)));
}
async clickDropdownWithOption(option: string): Promise<void> {
async selectDropdownOption(option: string): Promise<void> {
await this.clickDropdown();
await this.selectOption(option);
}

View File

@@ -61,7 +61,7 @@ export class EditProcessFilterCloudComponentPage {
}
async setStatusFilterDropDown(option: string): Promise<void> {
await this.statusDropdown.clickDropdownWithOption(option);
await this.statusDropdown.selectDropdownOption(option);
}
async getStateFilterDropDownValue(): Promise<string> {
@@ -69,7 +69,7 @@ export class EditProcessFilterCloudComponentPage {
}
async setSortFilterDropDown(option): Promise<void> {
await this.sortDropdown.clickDropdownWithOption(option);
await this.sortDropdown.selectDropdownOption(option);
}
async getSortFilterDropDownValue(): Promise<string> {
@@ -78,7 +78,7 @@ export class EditProcessFilterCloudComponentPage {
}
async setOrderFilterDropDown(option): Promise<void> {
await this.orderDropdown.clickDropdownWithOption(option);
await this.orderDropdown.selectDropdownOption(option);
await browser.sleep(1500);
}
@@ -87,7 +87,7 @@ export class EditProcessFilterCloudComponentPage {
}
async setAppNameDropDown(option: string): Promise<void> {
await this.appNameDropdown.clickDropdownWithOption(option);
await this.appNameDropdown.selectDropdownOption(option);
}
async getApplicationSelected(): Promise<string> {

View File

@@ -65,7 +65,7 @@ export class EditTaskFilterCloudComponentPage {
}
async setStatusFilterDropDown(option: string): Promise<void> {
await this.statusDropdown.clickDropdownWithOption(option);
await this.statusDropdown.selectDropdownOption(option);
}
async getStatusFilterDropDownValue(): Promise<string> {
@@ -73,7 +73,7 @@ export class EditTaskFilterCloudComponentPage {
}
async setSortFilterDropDown(option: string): Promise<void> {
await this.sortDropdown.clickDropdownWithOption(option);
await this.sortDropdown.selectDropdownOption(option);
}
async getSortFilterDropDownValue(): Promise<string> {
@@ -81,7 +81,7 @@ export class EditTaskFilterCloudComponentPage {
}
async setOrderFilterDropDown(option: string): Promise<void> {
await this.orderDropdown.clickDropdownWithOption(option);
await this.orderDropdown.selectDropdownOption(option);
await browser.sleep(1500);
}
@@ -193,7 +193,7 @@ export class EditTaskFilterCloudComponentPage {
}
async setAppNameDropDown(option: string): Promise<void> {
await this.appNameDropdown.clickDropdownWithOption(option);
await this.appNameDropdown.selectDropdownOption(option);
}
async getAppNameDropDownValue(): Promise<string> {