mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-26 17:24:56 +00:00
* library dialog * integrate with demo shell * update resources * fix license * auto focus for the first input * update e2e tests * try close the dialog between tests * fix afterEach * Revert "try close the dialog between tests" This reverts commit 63464f2b03c226c606d09b18c7d2782e3bb52c0a. * update code due to css lint issues * csslint settings for vs code * missing import lint fix remove not used import convert errorPage js to ts convert tasklistpage js to ts fix redirection creation folder in root fix lint issue fix e2e * e2e fix * fix PS tests * navigation import * fix tests tooltip convert paginapage to ts * fix lint * fix lock files e2e filterspage to ts * fix lint * fix cs cre git dept 3 and not 50 as default in travis * quiet log git download * add some delay and change the delete lock * fix node entry * convert searchDialog to typescript parallel protractor * disable browser execute * restote test * change search tests * move search in a separate e2e folder * experiment fix e2e * change util presence change protractor conf * fix unshare test * improve query viewerPage using css over xpath * waitForAngularEnabled before browser redirect * convert util to ts and more * convert other files to ts * convert to ts other files * trigger build * function fixes use arrow function * process service fixes * lint fix review timeout default * fix failing tests * restore timeout * share dialog fix * remove * use configuration admin * fix APS 2 login sso
422 lines
13 KiB
TypeScript
422 lines
13 KiB
TypeScript
/*!
|
|
* @license
|
|
* Copyright 2016 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, protractor } from 'protractor';
|
|
import * as moment from 'moment';
|
|
import fs = require('fs');
|
|
import path = require('path');
|
|
import TestConfig = require('../test.config');
|
|
|
|
let until = protractor.ExpectedConditions;
|
|
let DEFAULT_TIMEOUT = parseInt(TestConfig.main.timeout, 10);
|
|
|
|
export class Util {
|
|
|
|
/**
|
|
* creates an absolute path string if multiple file uploads are required
|
|
*/
|
|
static uploadParentFolder(filePath) {
|
|
let parentFolder = path.resolve(path.join(__dirname, 'test'));
|
|
return path.resolve(path.join(parentFolder, filePath));
|
|
}
|
|
|
|
/**
|
|
* Get current date in long format: Oct 24, 2016
|
|
*
|
|
* @return {string}
|
|
* @method getCrtDateLongFormat
|
|
*/
|
|
static getCrtDateLongFormat() {
|
|
let currentDate = new Date();
|
|
let months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
|
|
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
|
|
];
|
|
|
|
return months[currentDate.getMonth()] + ' ' + currentDate.getDate() + ', ' + (currentDate.getFullYear() + 1900);
|
|
}
|
|
|
|
/**
|
|
* Get current date in specified format
|
|
*
|
|
* @return {string}
|
|
* @method getCrtDateInFormat
|
|
*/
|
|
static getCrtDateInFormat(dateFormat) {
|
|
return moment().format(dateFormat);
|
|
}
|
|
|
|
/**
|
|
* Get specific date after current date in specific format
|
|
*
|
|
* @return {string}
|
|
* @method getCrtDateInFormat
|
|
*/
|
|
static getSpecificDateAfterCrtDateInFormat(dateFormat, days) {
|
|
return moment(new Date()).add(days, 'days').format(dateFormat);
|
|
}
|
|
|
|
/**
|
|
* Generates a random string.
|
|
*
|
|
* @param length {int} If this parameter is not provided the length is set to 8 by default.
|
|
* @return {string}
|
|
* @method generateRandomString
|
|
*/
|
|
static generateRandomString(length: number = 8): string {
|
|
let text = '';
|
|
let possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
|
|
for (let i = 0; i < length; i++) {
|
|
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
|
}
|
|
|
|
return text;
|
|
}
|
|
|
|
static generatePasswordString(length: number = 8): string {
|
|
let text = '';
|
|
let possibleUpperCase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
let possibleLowerCase = 'abcdefghijklmnopqrstuvwxyz';
|
|
let 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));
|
|
}
|
|
|
|
return text;
|
|
}
|
|
|
|
/**
|
|
* Generates a random string - digits only.
|
|
*
|
|
* @param length {int} If this parameter is not provided the length is set to 8 by default.
|
|
* @return {string}
|
|
* @method generateRandomString
|
|
*/
|
|
static generateRandomStringDigits(length: number = 8): string {
|
|
let text = '';
|
|
let possible = '0123456789';
|
|
|
|
for (let i = 0; i < length; i++) {
|
|
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
|
}
|
|
|
|
return text;
|
|
}
|
|
|
|
/**
|
|
* 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.
|
|
* @return {string}
|
|
* @method generateRandomString
|
|
*/
|
|
static generateRandomStringNonLatin(length: number = 3): string {
|
|
let text = '';
|
|
let possible = '密码你好𠮷';
|
|
|
|
for (let i = 0; i < length; i++) {
|
|
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
|
}
|
|
|
|
return text;
|
|
}
|
|
|
|
/**
|
|
* Generates a random string to lowercase.
|
|
*
|
|
* @param length {int} If this parameter is not provided the length is set to 8 by default.
|
|
* @return {string}
|
|
* @method generateRandomString
|
|
*/
|
|
static generateRandomStringToLowerCase(length?: number): string {
|
|
return this.generateRandomString(length).toLowerCase();
|
|
}
|
|
|
|
/**
|
|
* Generates a random string to uppercase.
|
|
*
|
|
* @param length {int} If this parameter is not provided the length is set to 8 by default.
|
|
* @return {string}
|
|
* @method generateRandomString
|
|
*/
|
|
static generateRandomStringToUpperCase(length?: number): string {
|
|
return this.generateRandomString(length).toUpperCase();
|
|
}
|
|
|
|
/**
|
|
* Generates a sequence of files with name: baseName + index + extension (e.g.) baseName1.txt, baseName2.txt, ...
|
|
*
|
|
* @param startIndex {int}
|
|
* @param endIndex {int}
|
|
* @param baseName{string} the base name of all files
|
|
* @param extension{string} the extension of the file
|
|
* @return fileNames
|
|
* @method generateSequenceFiles
|
|
*/
|
|
static generateSequenceFiles(startIndex, endIndex, baseName, extension) {
|
|
let fileNames = [];
|
|
for (let i = startIndex; i <= endIndex; i++) {
|
|
fileNames.push(baseName + i + extension);
|
|
}
|
|
return fileNames;
|
|
}
|
|
|
|
/**
|
|
* Generates a random number (as int) in the interval [min, max).
|
|
*
|
|
* @param min {int}
|
|
* @param max {int}
|
|
* @return {number}
|
|
* @method generateRandomInt
|
|
*/
|
|
static generateRandomInt(min, max) {
|
|
return Math.floor(Math.random() * (max - min) + min);
|
|
}
|
|
|
|
/**
|
|
* Generates a random email address following the format: abcdef@activiti.test.com
|
|
*
|
|
* @param length {int}
|
|
* @return {string}
|
|
* @method generateRandomEmail
|
|
*/
|
|
static generateRandomEmail(length: number = 5): string {
|
|
let email = '';
|
|
let possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
|
|
for (let i = 0; i < length; i++) {
|
|
email += possible.charAt(Math.floor(Math.random() * possible.length));
|
|
}
|
|
|
|
email += '@activiti.test.com';
|
|
return email.toLowerCase();
|
|
}
|
|
|
|
/**
|
|
* Generates a random date inside the interval [1990, 2100) following the format dd.mm.yyyy
|
|
*
|
|
* @return {string}
|
|
* @method generateRandomDateFormat
|
|
*/
|
|
static generateRandomDateFormat() {
|
|
let day = Math.floor(Math.random() * (29 - 1) + 1);
|
|
let month = Math.floor(Math.random() * (12 - 1) + 1);
|
|
let year = Math.floor(Math.random() * (2100 - 1990) + 1990);
|
|
|
|
return day + '.' + month + '.' + year;
|
|
}
|
|
|
|
/**
|
|
* Generates a random date inside the interval [1990, 2100) following the format dd-mm-yyyy.
|
|
*
|
|
* @return {string}
|
|
* @method generateRandomDate
|
|
*/
|
|
static generateRandomDate() {
|
|
let dayText, monthText;
|
|
|
|
let day = (Math.floor(Math.random() * (29 - 1) + 1));
|
|
if (day < 10) {
|
|
dayText = '0' + day.toString();
|
|
}
|
|
let month = Math.floor(Math.random() * (12 - 1) + 1);
|
|
if (month < 10) {
|
|
monthText = '0' + month.toString();
|
|
}
|
|
let year = Math.floor(Math.random() * (2100 - 1990) + 1990);
|
|
|
|
return dayText + '-' + monthText + '-' + year.toString();
|
|
}
|
|
|
|
/**
|
|
* Returns TRUE if the first array contains all elements from the second one.
|
|
*
|
|
* @param {array} superset
|
|
* @param {array} subset
|
|
*
|
|
* @return {boolean}
|
|
* @method arrayContainsArray
|
|
*/
|
|
static arrayContainsArray(superset, subset) {
|
|
if (0 === subset.length) {
|
|
return false;
|
|
}
|
|
return subset.every(function (value) {
|
|
return (superset.indexOf(value) >= 0);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Reads the content of the file and provides it on callback
|
|
*
|
|
* @param filePath
|
|
* @param callback
|
|
* @method readFile
|
|
*/
|
|
static readFile(filePath, callback) {
|
|
let absolutePath = path.join(TestConfig.main.rootPath + filePath);
|
|
fs.readFile(absolutePath, { encoding: 'utf8' }, function (err, data) {
|
|
if (err) {
|
|
throw err;
|
|
}
|
|
callback(data);
|
|
});
|
|
}
|
|
|
|
static waitUntilElementIsVisible(elementToCheck, waitTimeout: number = DEFAULT_TIMEOUT) {
|
|
let isDisplayed = false;
|
|
return browser.wait(() => {
|
|
browser.waitForAngularEnabled();
|
|
|
|
elementToCheck.isDisplayed().then(
|
|
() => {
|
|
isDisplayed = true;
|
|
},
|
|
(err) => {
|
|
isDisplayed = false;
|
|
}
|
|
);
|
|
return isDisplayed;
|
|
}, waitTimeout, 'Element is not visible ' + elementToCheck.locator());
|
|
}
|
|
|
|
static waitUntilElementIsPresent(elementToCheck, waitTimeout: number = DEFAULT_TIMEOUT) {
|
|
browser.waitForAngularEnabled();
|
|
|
|
return browser.wait(until.presenceOf(elementToCheck), waitTimeout, 'Element is not present ' + elementToCheck.locator());
|
|
}
|
|
|
|
/*
|
|
* Wait for element to have value
|
|
*/
|
|
static waitUntilElementHasValue(elementToCheck, elementValue, waitTimeout: number = DEFAULT_TIMEOUT) {
|
|
browser.waitForAngularEnabled();
|
|
|
|
browser.wait(until.textToBePresentInElementValue(elementToCheck, elementValue), waitTimeout, 'Element doesn\'t have a value ' + elementToCheck.locator());
|
|
}
|
|
|
|
/*
|
|
* Wait for element to be clickable
|
|
*/
|
|
static waitUntilElementIsClickable(elementToCheck, waitTimeout: number = DEFAULT_TIMEOUT) {
|
|
return browser.wait(() => {
|
|
browser.waitForAngularEnabled();
|
|
return until.elementToBeClickable(elementToCheck);
|
|
}, waitTimeout, 'Element is not Clickable' + elementToCheck.locator());
|
|
}
|
|
|
|
/*
|
|
* Wait for element to not be visible
|
|
*/
|
|
static waitUntilElementIsNotVisible(elementToCheck, waitTimeout: number = DEFAULT_TIMEOUT) {
|
|
return browser.wait(() => {
|
|
browser.waitForAngularEnabled();
|
|
return elementToCheck.isPresent().then(function (present) {
|
|
return !present;
|
|
});
|
|
}, waitTimeout, 'Element is Visible and it should not' + elementToCheck.locator());
|
|
}
|
|
|
|
static waitUntilElementIsNotDisplayed(elementToCheck, waitTimeout: number = DEFAULT_TIMEOUT) {
|
|
return browser.wait(() => {
|
|
browser.waitForAngularEnabled();
|
|
return elementToCheck.isDisplayed().then(function (present) {
|
|
return !present;
|
|
});
|
|
}, waitTimeout, 'Element is dysplayed and it should not' + elementToCheck.locator());
|
|
}
|
|
|
|
/*
|
|
* Wait for element to not be visible
|
|
*/
|
|
static waitUntilElementIsStale(elementToCheck, waitTimeout: number = DEFAULT_TIMEOUT) {
|
|
return browser.wait(until.stalenessOf(elementToCheck), waitTimeout, 'Element is not in stale ' + elementToCheck.locator());
|
|
}
|
|
|
|
/*
|
|
* Wait for element to not be visible
|
|
*/
|
|
static waitUntilElementIsNotOnPage(elementToCheck, waitTimeout: number = DEFAULT_TIMEOUT) {
|
|
return browser.wait(() => {
|
|
browser.waitForAngularEnabled();
|
|
return browser.wait(until.not(until.visibilityOf(elementToCheck)));
|
|
}, waitTimeout, 'Element is not in the page ' + elementToCheck.locator());
|
|
}
|
|
|
|
static waitUntilElementIsOnPage(elementToCheck, waitTimeout: number = DEFAULT_TIMEOUT) {
|
|
return browser.wait(browser.wait(until.visibilityOf(elementToCheck)), waitTimeout);
|
|
}
|
|
|
|
/**
|
|
* @method waitForPage
|
|
*/
|
|
static waitForPage() {
|
|
browser.wait(function () {
|
|
let deferred = protractor.promise.defer();
|
|
browser.executeScript('return document.readyState').then((text) => {
|
|
deferred.fulfill(() => {
|
|
return text === 'complete';
|
|
});
|
|
});
|
|
return deferred.promise;
|
|
});
|
|
}
|
|
|
|
static openNewTabInBrowser() {
|
|
browser.driver.executeScript("window.open('about: blank', '_blank');");
|
|
}
|
|
|
|
static switchToWindowHandler(windowNumber) {
|
|
browser.driver.getAllWindowHandles().then((handles) => {
|
|
browser.waitForAngularEnabled();
|
|
browser.driver.switchTo().window(handles[windowNumber]);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Verify file exists
|
|
* @param filePath - absolute path to the searched file
|
|
* @param retries - number of retries
|
|
* @returns - true if file is found, false otherwise
|
|
*/
|
|
static fileExists(filePath, retries) {
|
|
let tries = 0;
|
|
return new Promise(function (resolve, reject) {
|
|
let checkExist = setInterval(() => {
|
|
fs.stat(filePath, function (error, stats) {
|
|
tries++;
|
|
|
|
if (error && tries === retries) {
|
|
clearInterval(checkExist);
|
|
resolve(false);
|
|
}
|
|
|
|
if (!error) {
|
|
clearInterval(checkExist);
|
|
resolve(true);
|
|
}
|
|
});
|
|
}, 2000);
|
|
});
|
|
}
|
|
}
|