mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
[ADF-3962] sso download directive automated (#4452)
* sso download directive automated * temp changes * temp changes * moving of services under lib testing and ADF-3962 automated * removed the browser sleep * cspell and linting fixes. * codacy improvements * export public-api update * remove circular dep * remove circular dep * fixes * fix user info test * fix datatable * random commit * move other string * fix lint * fix lint * fix prolem type * fix failing test * fix tag test * fix problems after rebase * fix lint * remove space * remove visibility method duplicated
This commit is contained in:
committed by
Eugenio Romano
parent
89f612bbb0
commit
4376d357ac
290
e2e/util/util.ts
290
e2e/util/util.ts
@@ -15,117 +15,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { browser, protractor } from 'protractor';
|
||||
import { browser } from 'protractor';
|
||||
import fs = require('fs');
|
||||
import path = require('path');
|
||||
import TestConfig = require('../test.config');
|
||||
|
||||
const until = protractor.ExpectedConditions;
|
||||
const DEFAULT_TIMEOUT = parseInt(TestConfig.main.timeout, 10);
|
||||
|
||||
export class Util {
|
||||
|
||||
/**
|
||||
* creates an absolute path string if multiple file uploads are required
|
||||
*/
|
||||
static uploadParentFolder(filePath) {
|
||||
const parentFolder = path.resolve(path.join(__dirname, 'test'));
|
||||
return path.resolve(path.join(parentFolder, filePath));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 = '';
|
||||
const 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 = '';
|
||||
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));
|
||||
}
|
||||
|
||||
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 = '';
|
||||
const 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 = '';
|
||||
const 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, ...
|
||||
*
|
||||
@@ -144,72 +38,6 @@ export class Util {
|
||||
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 = '';
|
||||
const 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
|
||||
*
|
||||
* @method generateRandomDateFormat
|
||||
*/
|
||||
static generateRandomDateFormat(): string {
|
||||
const day = Math.floor(Math.random() * (29 - 1) + 1);
|
||||
const month = Math.floor(Math.random() * (12 - 1) + 1);
|
||||
const 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.
|
||||
*
|
||||
* @method generateRandomDate
|
||||
*/
|
||||
static generateRandomDate(): string {
|
||||
let dayText;
|
||||
let monthText;
|
||||
|
||||
const day = (Math.floor(Math.random() * (29 - 1) + 1));
|
||||
if (day < 10) {
|
||||
dayText = '0' + day.toString();
|
||||
}
|
||||
const month = Math.floor(Math.random() * (12 - 1) + 1);
|
||||
if (month < 10) {
|
||||
monthText = '0' + month.toString();
|
||||
}
|
||||
const 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.
|
||||
*
|
||||
@@ -228,122 +56,6 @@ export class Util {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the content of the file and provides it on callback
|
||||
*
|
||||
* @param filePath
|
||||
* @param callback
|
||||
* @method readFile
|
||||
*/
|
||||
static readFile(filePath, callback) {
|
||||
const 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 () {
|
||||
const 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');");
|
||||
}
|
||||
|
Reference in New Issue
Block a user