[ACA-1920] automate tests for Create file from template (#1303)

* change component ancestor from ElementFinder to string for better usability
better naming for some methods
small code cleanup

* add test components and automate tests for Create File from Template action

* ignore e2e-downloads folder

* add return types

* enable check

* enable check after issue got fixed
This commit is contained in:
Adina Parpalita
2020-01-16 13:16:18 +02:00
committed by Cilibiu Bogdan
parent 0bc4a3453b
commit 569ee98e8d
61 changed files with 1262 additions and 416 deletions
+84
View File
@@ -0,0 +1,84 @@
/*!
* @license
* Alfresco Example Content Application
*
* Copyright (C) 2005 - 2019 Alfresco Software Limited
*
* This file is part of the Alfresco Example Content Application.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
import { RepoClient, NodeContentTree } from './repo-client/repo-client';
import { PersonEntry, NodeEntry } from '@alfresco/js-api';
import { PersonModel } from './repo-client/apis/people/people-api-models';
export class AdminActions {
private adminApi: RepoClient;
constructor() {
this.adminApi = new RepoClient();
}
async getDataDictionaryId(): Promise<string> {
return await this.adminApi.nodes.getNodeIdFromParent('Data Dictionary', '-root-');
}
async getNodeTemplatesFolderId(): Promise<string> {
return await this.adminApi.nodes.getNodeIdFromParent('Node Templates', await this.getDataDictionaryId());
}
async createUser(user: PersonModel): Promise<PersonEntry> {
return await this.adminApi.people.createUser(user);
}
async createNodeTemplate(name: string, title: string = '', description: string = '', author: string = ''): Promise<NodeEntry> {
const templatesRootFolderId: string = await this.getNodeTemplatesFolderId();
return await this.adminApi.nodes.createFile(name, templatesRootFolderId, title, description, author);
}
async createNodeTemplatesHierarchy(hierarchy: NodeContentTree): Promise<any> {
return await this.adminApi.nodes.createContent(hierarchy, `Data Dictionary/Node Templates`);
}
async removeUserAccessOnNode(nodeName: string): Promise<NodeEntry> {
const templatesRootFolderId = await this.getNodeTemplatesFolderId();
const nodeId: string = await this.adminApi.nodes.getNodeIdFromParent(nodeName, templatesRootFolderId);
return await this.adminApi.nodes.setInheritPermissions(nodeId, false);
}
async cleanNodeTemplatesFolder(): Promise<void> {
return await this.adminApi.nodes.deleteNodeChildren(await this.getNodeTemplatesFolderId());
}
async createLinkToFileId(originalFileId: string, destinationParentId: string): Promise<NodeEntry> {
return await this.adminApi.nodes.createNodeLink(originalFileId, destinationParentId);
}
async createLinkToFileName(originalFileName: string, originalFileParentId: string, destinationParentId?: string): Promise<NodeEntry> {
if (!destinationParentId) {
destinationParentId = originalFileParentId
};
const nodeId = await this.adminApi.nodes.getNodeIdFromParent(originalFileName, originalFileParentId);
return await this.createLinkToFileId(nodeId, destinationParentId);
}
}
@@ -36,7 +36,7 @@ export class NodesApi extends RepoApi {
super(username, password);
}
async getNodeByPath(relativePath: string = '/'): Promise<NodeEntry> {
async getNodeByPath(relativePath: string = '/'): Promise<NodeEntry|null> {
try {
await this.apiAuth();
return await this.nodesApi.getNode('-my-', { relativePath });
@@ -46,7 +46,7 @@ export class NodesApi extends RepoApi {
}
}
async getNodeById(id: string): Promise<NodeEntry> {
async getNodeById(id: string): Promise<NodeEntry|null> {
try {
await this.apiAuth();
const node = await this.nodesApi.getNode(id);
@@ -77,7 +77,17 @@ export class NodesApi extends RepoApi {
}
}
async getNodeProperty(nodeId: string, property: string): Promise<any> {
async getNodeTitle(name: string, parentId: string): Promise<string> {
try {
const children = (await this.getNodeChildren(parentId)).list.entries;
return children.find(elem => elem.entry.name === name).entry.properties['cm:title'] || '';
} catch (error) {
this.handleError(`${this.constructor.name} ${this.getNodeTitle.name}`, error);
return '';
}
}
async getNodeProperty(nodeId: string, property: string): Promise<string> {
try {
const node = await this.getNodeById(nodeId);
return (node.entry.properties && node.entry.properties[property]) || '';
@@ -179,7 +189,7 @@ export class NodesApi extends RepoApi {
}
}
async getNodeChildren(nodeId: string): Promise<NodeChildAssociationPaging> {
async getNodeChildren(nodeId: string): Promise<NodeChildAssociationPaging|null> {
try {
const opts = {
include: [ 'properties' ]
@@ -202,7 +212,7 @@ export class NodesApi extends RepoApi {
}
}
async createImageNode(name: string, parentId: string = '-my-', title: string = '', description: string = ''): Promise<any> {
async createImageNode(name: string, parentId: string = '-my-', title: string = '', description: string = ''): Promise<NodeEntry|null> {
const imageProps = {
'exif:pixelXDimension': 1000,
'exif:pixelYDimension': 1200
@@ -211,10 +221,30 @@ export class NodesApi extends RepoApi {
return await this.createNode('cm:content', name, parentId, title, description, imageProps);
} catch (error) {
this.handleError(`${this.constructor.name} ${this.createImageNode.name}`, error);
return null;
}
}
async createNode(nodeType: string, name: string, parentId: string = '-my-', title: string = '', description: string = '', imageProps: any = null, author: string = '', majorVersion: boolean = true): Promise<any> {
async createNodeLink(originalNodeId: string, destinationId: string): Promise<NodeEntry|null> {
const name = (await this.getNodeById(originalNodeId)).entry.name;
const nodeBody = {
name: `Link to ${name}.url`,
nodeType: 'app:filelink',
properties: {
'cm:destination': originalNodeId
}
}
try {
await this.apiAuth();
return await this.nodesApi.createNode(destinationId, nodeBody);
} catch (error) {
this.handleError(`${this.constructor.name} ${this.createNode.name}`, error);
return null;
}
}
async createNode(nodeType: string, name: string, parentId: string = '-my-', title: string = '', description: string = '', imageProps: any = null, author: string = '', majorVersion: boolean = true): Promise<NodeEntry|null> {
const nodeBody = {
name,
nodeType,
@@ -234,34 +264,38 @@ export class NodesApi extends RepoApi {
return await this.nodesApi.createNode(parentId, nodeBody, { majorVersion });
} catch (error) {
this.handleError(`${this.constructor.name} ${this.createNode.name}`, error);
return null;
}
}
async createFile(name: string, parentId: string = '-my-', title: string = '', description: string = '', author: string = '', majorVersion: boolean = true): Promise<any> {
async createFile(name: string, parentId: string = '-my-', title: string = '', description: string = '', author: string = '', majorVersion: boolean = true): Promise<NodeEntry> {
try {
return await this.createNode('cm:content', name, parentId, title, description, null, author, majorVersion);
} catch (error) {
this.handleError(`${this.constructor.name} ${this.createFile.name}`, error);
return null;
}
}
async createImage(name: string, parentId: string = '-my-', title: string = '', description: string = ''): Promise<any> {
async createImage(name: string, parentId: string = '-my-', title: string = '', description: string = ''): Promise<NodeEntry|null> {
try {
return await this.createImageNode(name, parentId, title, description);
} catch (error) {
this.handleError(`${this.constructor.name} ${this.createImage.name}`, error);
return null;
}
}
async createFolder(name: string, parentId: string = '-my-', title: string = '', description: string = '', author: string = ''): Promise<any> {
async createFolder(name: string, parentId: string = '-my-', title: string = '', description: string = '', author: string = ''): Promise<NodeEntry|null> {
try {
return await this.createNode('cm:folder', name, parentId, title, description, null, author);
} catch (error) {
this.handleError(`${this.constructor.name} ${this.createFolder.name}`, error);
return null;
}
}
async createChildren(data: NodeBodyCreate[]): Promise<any> {
async createChildren(data: NodeBodyCreate[]): Promise<NodeEntry|any> {
try {
await this.apiAuth();
return await this.nodesApi.createNode('-my-', <any>data);
@@ -270,7 +304,7 @@ export class NodesApi extends RepoApi {
}
}
async createContent(content: NodeContentTree, relativePath: string = '/'): Promise<any> {
async createContent(content: NodeContentTree, relativePath: string = '/'): Promise<NodeEntry|any> {
try {
return await this.createChildren(flattenNodeContentTree(content, relativePath));
} catch (error) {
@@ -278,7 +312,7 @@ export class NodesApi extends RepoApi {
}
}
async createFolders(names: string[], relativePath: string = '/'): Promise<any> {
async createFolders(names: string[], relativePath: string = '/'): Promise<NodeEntry|any> {
try {
return await this.createContent({ folders: names }, relativePath);
} catch (error) {
@@ -286,7 +320,7 @@ export class NodesApi extends RepoApi {
}
}
async createFiles(names: string[], relativePath: string = '/'): Promise<any> {
async createFiles(names: string[], relativePath: string = '/'): Promise<NodeEntry|any> {
try {
return await this.createContent({ files: names }, relativePath);
} catch (error) {
@@ -325,6 +359,22 @@ export class NodesApi extends RepoApi {
}
// node permissions
async setInheritPermissions(nodeId: string, inheritPermissions: boolean): Promise<NodeEntry|null> {
const data = {
permissions: {
isInheritanceEnabled: inheritPermissions
}
};
try {
await this.apiAuth();
return await this.nodesApi.updateNode(nodeId, data);
} catch (error) {
this.handleError(`${this.constructor.name} ${this.setGranularPermission.name}`, error);
return null;
}
}
async setGranularPermission(nodeId: string, inheritPermissions: boolean = false, username: string, role: string): Promise<NodeEntry|null> {
const data = {
permissions: {
@@ -372,7 +422,7 @@ export class NodesApi extends RepoApi {
}
}
async getLockType(nodeId: string): Promise<any> {
async getLockType(nodeId: string): Promise<string> {
try {
const lockType = await this.getNodeProperty(nodeId, 'cm:lockType');
return lockType || '';
@@ -382,7 +432,7 @@ export class NodesApi extends RepoApi {
}
}
async getLockOwner(nodeId: string): Promise<any> {
async getLockOwner(nodeId: string): Promise<string> {
try {
const lockOwner = await this.getNodeProperty(nodeId, 'cm:lockOwner');
return lockOwner || '';
+30 -22
View File
@@ -23,7 +23,7 @@
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
import { browser, protractor, promise, ElementFinder, ExpectedConditions as EC, by } from 'protractor';
import { browser, protractor, ElementFinder, ExpectedConditions as EC, by, logging } from 'protractor';
import { BROWSER_WAIT_TIMEOUT, E2E_ROOT_PATH, EXTENSIBILITY_CONFIGS } from '../configs';
const path = require('path');
@@ -41,35 +41,35 @@ export class Utils {
lighter track cinema tread tick climate lend summit singer radical flower visual negotiation promises cooperative live';
// generate a random value
static random() {
static random(): string {
return Math.random().toString(36).substring(5, 10).toLowerCase();
}
// local storage
static clearLocalStorage(): promise.Promise<any> {
return browser.executeScript('window.localStorage.clear();');
static async clearLocalStorage(): Promise<void> {
await browser.executeScript('window.localStorage.clear();');
}
// session storage
static clearSessionStorage(): promise.Promise<any> {
return browser.executeScript('window.sessionStorage.clear();');
static async clearSessionStorage(): Promise<void> {
await browser.executeScript('window.sessionStorage.clear();');
}
static getSessionStorage() {
return browser.executeScript('return window.sessionStorage.getItem("app.extension.config");');
static async getSessionStorage(): Promise<any> {
return await browser.executeScript('return window.sessionStorage.getItem("app.extension.config");');
}
static setSessionStorageFromConfig(configFileName: string) {
static async setSessionStorageFromConfig(configFileName: string): Promise<void> {
const configFile = `${E2E_ROOT_PATH}/resources/extensibility-configs/${configFileName}`;
const fileContent = JSON.stringify(fs.readFileSync(configFile, { encoding: 'utf8' }));
return browser.executeScript(`window.sessionStorage.setItem('app.extension.config', ${fileContent});`);
await browser.executeScript(`window.sessionStorage.setItem('app.extension.config', ${fileContent});`);
}
static resetExtensionConfig() {
static async resetExtensionConfig(): Promise<void> {
const defConfig = `${E2E_ROOT_PATH}/resources/extensibility-configs/${EXTENSIBILITY_CONFIGS.DEFAULT_EXTENSIONS_CONFIG}`;
return this.setSessionStorageFromConfig(defConfig);
await this.setSessionStorageFromConfig(defConfig);
}
static retryCall(fn: () => Promise<any>, retry: number = 30, delay: number = 1000): Promise<any> {
@@ -80,11 +80,11 @@ export class Utils {
return run(retry);
}
static async waitUntilElementClickable(element: ElementFinder) {
static async waitUntilElementClickable(element: ElementFinder): Promise<void> {
await browser.wait(EC.elementToBeClickable(element), BROWSER_WAIT_TIMEOUT).catch(Error);
}
static async typeInField(elem: ElementFinder, value: string) {
static async typeInField(elem: ElementFinder, value: string): Promise<void> {
for (let i = 0; i < value.length; i++) {
const c = value.charAt(i);
await elem.sendKeys(c);
@@ -99,7 +99,7 @@ export class Utils {
}
}
static async fileExistsOnOS(fileName: string, folderName: string = '', subFolderName: string = '') {
static async fileExistsOnOS(fileName: string, folderName: string = '', subFolderName: string = ''): Promise<any> {
const config = await browser.getProcessedConfig();
const filePath = path.join(config.params.downloadFolder, folderName, subFolderName, fileName);
@@ -124,7 +124,7 @@ export class Utils {
});
}
static async renameFile(oldName: string, newName: string) {
static async renameFile(oldName: string, newName: string): Promise<void> {
const config = await browser.getProcessedConfig();
const oldFilePath = path.join(config.params.downloadFolder, oldName);
const newFilePath = path.join(config.params.downloadFolder, newName);
@@ -140,7 +140,7 @@ export class Utils {
}
}
static async unzip(filename: string, unzippedName: string = '') {
static async unzip(filename: string, unzippedName: string = ''): Promise<void> {
const config = await browser.getProcessedConfig();
const filePath = path.join(config.params.downloadFolder, filename);
const output = path.join(config.params.downloadFolder, unzippedName ? unzippedName : '');
@@ -162,23 +162,31 @@ export class Utils {
});
}
static async pressEscape() {
static async pressEscape(): Promise<void> {
await browser.actions().sendKeys(protractor.Key.ESCAPE).perform();
}
static async pressTab() {
static async pressTab(): Promise<void> {
await browser.actions().sendKeys(protractor.Key.TAB).perform();
}
static async getBrowserLog() {
static async pressCmd(): Promise<void> {
await browser.actions().sendKeys(protractor.Key.COMMAND).perform();
}
static async releaseKeyPressed(): Promise<void> {
await browser.actions().sendKeys(protractor.Key.NULL).perform();
}
static async getBrowserLog(): Promise<logging.Entry[]> {
return browser.manage().logs().get('browser');
}
static formatDate(date: string) {
static formatDate(date: string): string {
return new Date(date).toLocaleDateString('en-US');
}
static async uploadFileNewVersion(fileFromOS: string) {
static async uploadFileNewVersion(fileFromOS: string): Promise<void> {
const el = browser.element(by.id('app-upload-file-version'));
await el.sendKeys(`${E2E_ROOT_PATH}/resources/test-files/${fileFromOS}`);
}