[ACS-4586] Implemented Playwright Framework and add it to CI/CD (#2985)

This commit is contained in:
Kristian Dimitrov
2023-02-16 17:23:08 +00:00
committed by GitHub
parent 197ef8f0e3
commit d68deab2bd
47 changed files with 1413 additions and 117 deletions

View File

@@ -0,0 +1,122 @@
/*
* Copyright © 2005 - 2023 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.
*/
import {
AdminTenantsApi,
AdminUsersApi,
AlfrescoApi,
ContentClient,
GroupsApi,
NodesApi,
PeopleApi,
QueriesApi,
SearchApi,
SecurityGroupsApi,
SecurityMarksApi,
SitesApi,
UploadApi
} from '@alfresco/js-api';
import { users } from '../page-objects';
import { logger } from '@alfresco/adf-cli/scripts/logger';
import { ActionTypes, Rule } from './rules-api';
export interface AcaBackend {
sites: SitesApi;
upload: UploadApi;
nodes: NodesApi;
tearDown(): Promise<any>;
}
const config = {
authType: process.env.APP_CONFIG_AUTH_TYPE,
hostBpm: process.env.APP_CONFIG_BPM_HOST,
hostEcm: process.env.APP_CONFIG_ECM_HOST,
provider: process.env.APP_CONFIG_PROVIDER,
contextRoot: 'alfresco'
};
export class ApiClientFactory {
public alfrescoApi: AlfrescoApi;
public sites: SitesApi;
public upload: UploadApi;
public nodes: NodesApi;
public people: PeopleApi;
public adminUsers: AdminUsersApi;
public adminTenant: AdminTenantsApi;
public groups: GroupsApi;
public queries: QueriesApi;
public search: SearchApi;
public securityGroupsApi: SecurityGroupsApi;
public securityMarksApi: SecurityMarksApi;
public contentClient: ContentClient;
constructor() {
this.alfrescoApi = new AlfrescoApi(config);
}
public async setUpAcaBackend(userProfile: keyof typeof users): Promise<AcaBackend> {
await this.login(userProfile);
this.sites = new SitesApi(this.alfrescoApi);
this.upload = new UploadApi(this.alfrescoApi);
this.nodes = new NodesApi(this.alfrescoApi);
this.people = new PeopleApi(this.alfrescoApi);
this.adminUsers = new AdminUsersApi(this.alfrescoApi);
this.adminTenant = new AdminTenantsApi(this.alfrescoApi);
this.groups = new GroupsApi(this.alfrescoApi);
this.queries = new QueriesApi(this.alfrescoApi);
this.search = new SearchApi(this.alfrescoApi);
this.securityGroupsApi = new SecurityGroupsApi(this.alfrescoApi);
this.securityMarksApi = new SecurityMarksApi(this.alfrescoApi);
return this;
}
async tearDown(): Promise<ApiClientFactory> {
await this.alfrescoApi.logout();
return this;
}
private callApi(path: string, httpMethod: string, body: object = {}): Promise<any> {
// APIs used by this service are still private and not yet available for public use
const params = [{}, {}, {}, {}, body, ['application/json'], ['application/json']];
return this.alfrescoApi.contentPrivateClient.callApi(path, httpMethod, ...params);
}
async createRule(nodeId: string, rule: Partial<Rule>, ruleSetId: string = '-default-'): Promise<Rule> {
const response = await this.callApi(`/nodes/${nodeId}/rule-sets/${ruleSetId}/rules`, 'POST', { ...rule });
return response.entry;
}
async createRandomRule(folderId: string, ruleName: string): Promise<Rule> {
const response = await this.createRule(folderId, {
name: ruleName,
isEnabled: true,
actions: [ActionTypes.ADDFEATURES.value, ActionTypes.CHECKIN.value]
});
return response;
}
async login(userProfile: keyof typeof users) {
const userToLog =
users[
Object.keys(users)
.filter((user) => user.match(new RegExp(`^${userProfile.toString()}$`)))
.toString()
] || userProfile;
let e: any;
try {
e = await this.alfrescoApi.login(userToLog.username, userToLog.password);
} catch (error) {
logger.error(`[API Client Factory] Log in user ${userToLog.username} failed ${e}`);
throw error;
}
}
}

View File

@@ -0,0 +1,10 @@
/*
* Copyright © 2005 - 2023 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 * from './rules-api';
export * from './api-client-factory';

View File

@@ -0,0 +1,56 @@
/*
* Copyright © 2005 - 2023 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.
*/
type RuleTrigger = 'inbound' | 'update' | 'outbound';
export interface RuleCompositeCondition {
inverted: boolean;
booleanMode: 'and' | 'or';
compositeConditions: RuleCompositeCondition[];
simpleConditions: RuleSimpleCondition[];
}
export interface RuleSimpleCondition {
field: string;
comparator: string;
parameter: string;
}
export interface Rule {
id: string;
name: string;
description: string;
isEnabled: boolean;
isInheritable: boolean;
isAsynchronous: boolean;
errorScript: string;
isShared: boolean;
triggers: RuleTrigger[];
conditions: RuleCompositeCondition;
actions: RuleAction[];
}
export interface RuleAction {
actionDefinitionId: string;
params?: { [key: string]: unknown };
}
export class ActionTypes {
static ADDFEATURES = new ActionTypes('ADDFEATURES', {
actionDefinitionId: 'add-features',
params: { 'aspect-name': 'cm:thumbnailed' }
});
static CHECKIN = new ActionTypes('CHECKIN', {
actionDefinitionId: 'check-in',
params: {
description: 'test',
minorChange: true
}
});
constructor(public key: string, public value: RuleAction) {}
}

View File

@@ -0,0 +1,46 @@
/*
* Copyright © 2005 - 2023 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.
*/
import { chromium, FullConfig } from '@playwright/test';
import { LoginPage } from '../page-objects';
import fs from 'fs';
const E2E_HOST = process.env.PLAYWRIGHT_E2E_HOST;
const E2E_PORT = process.env.PLAYWRIGHT_E2E_PORT;
const acsAdminUser = process.env.ADMIN_EMAIL;
const acsAdminUserPassword = process.env.ADMIN_PASSWORD;
async function globalSetup(config: FullConfig) {
const { use } = config.projects[0];
let baseUrl: string;
if (use.baseURL) {
baseUrl = use.baseURL;
} else {
if (E2E_HOST?.match(/localhost/)) {
baseUrl = `${E2E_HOST}:${E2E_PORT}`;
} else {
baseUrl = E2E_HOST;
}
}
const browser = await chromium.launch({
args: ['--disable-web-security']
});
const page = await browser.newPage();
const loginPage = new LoginPage(page);
fs.mkdirSync(`./storage-state`, { recursive: true });
await page.goto(baseUrl);
await loginPage.loginUser({ username: acsAdminUser, password: acsAdminUserPassword }, { withNavigation: false, waitForLoading: true });
await page.context().storageState({ path: `./storage-state/AdminUserState.json` });
await browser.close();
}
export default globalSetup;

View File

@@ -0,0 +1,9 @@
/*
* Copyright © 2005 - 2023 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 * from './global.setup';

View File

@@ -0,0 +1,29 @@
/*!
* @license
* Alfresco Example Content Application
*
* Copyright (C) 2005 - 2023 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/>.
*/
export * from './api';
export * from './base-config';
export * from './models';
export * from './page-objects';

View File

@@ -0,0 +1,9 @@
/*
* Copyright © 2005 - 2023 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 * from './user-model';

View File

@@ -0,0 +1,44 @@
/*
* Copyright © 2005 - 2023 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.
*/
import { StringUtil } from '@alfresco/adf-testing';
const LOWER_CASE_ALPHA = 'helloworld';
export class UserModel {
firstName?: string = StringUtil.generateRandomCharset(length, LOWER_CASE_ALPHA)(7);
lastName?: string = StringUtil.generateRandomCharset(length, LOWER_CASE_ALPHA)(7);
password?: string = StringUtil.generateRandomCharset(length, LOWER_CASE_ALPHA)(7);
email?: string;
username?: string;
idIdentityService?: string;
type = 'enterprise';
tenantId?: number;
company?: string;
id: number;
constructor(details: any = {}) {
const EMAIL_DOMAIN = 'alfresco';
this.firstName = details.firstName ?? this.firstName;
this.lastName = details.lastName ?? this.lastName;
const USER_IDENTIFY = `${this.firstName}${this.lastName}.${StringUtil.generateRandomCharset(length, LOWER_CASE_ALPHA)(7)}`;
this.password = details.password ?? this.password;
this.email = details.email ?? `${USER_IDENTIFY}@${EMAIL_DOMAIN}.com`;
this.username = details.username ?? USER_IDENTIFY;
this.idIdentityService = details.idIdentityService ?? this.idIdentityService;
this.type = details.type ?? this.type;
this.tenantId = details.tenantId ?? this.tenantId;
this.company = details.company ?? this.company;
this.id = details.id ?? this.id;
}
get fullName(): string {
return `${this.firstName ?? ''} ${this.lastName ?? ''}`;
}
}

View File

@@ -0,0 +1,8 @@
{
"name": "playwright-shared",
"version": "3.0.0",
"main": "index.ts",
"dependencies": {
"tslib": "^2.0.0"
}
}

View File

@@ -0,0 +1,48 @@
/*
* Copyright © 2005 - 2023 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.
*/
import { Locator, Page } from '@playwright/test';
import { PlaywrightBase } from '../playwright-base';
export abstract class BaseComponent extends PlaywrightBase {
private rootElement: string;
private overlayElement = this.page.locator('.cdk-overlay-backdrop-showing');
constructor(page: Page, rootElement: string) {
super(page);
this.rootElement = rootElement;
}
/**
* Method which should be used across the repository, while creating
* reference to elements, which are in root element of component.
*
* @param cssLocator css selector as String. Need to be in the tree under the root element
* @param options if you want to localize it by text, then provide an optional hasText
* @returns Locator object
*/
getChild(cssLocator: string, options?: { hasText?: string | RegExp; has?: Locator }): Locator {
return this.page.locator(`${this.rootElement} ${cssLocator}`, options);
}
async closeAdditionalOverlayElementIfVisible(): Promise<void> {
if (await this.overlayElement.isVisible()) {
await this.page.keyboard.press('Escape');
await this.overlayElement.waitFor({ state: 'detached', timeout: 5000 });
}
}
async spinnerWaitForReload(): Promise<void> {
try {
await this.page.locator('mat-progress-spinner').waitFor({ state: 'attached', timeout: 2000 });
await this.page.locator('mat-progress-spinner').waitFor({ state: 'detached', timeout: 2000 });
} catch (e) {
this.logger.info('Spinner was not present');
}
}
}

View File

@@ -0,0 +1,143 @@
/*
* Copyright © 2005 - 2023 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.
*/
import { Locator, Page } from '@playwright/test';
import { BaseComponent } from '../base.component';
import { MatMenuComponent } from './mat-menu.component';
export class DataTableComponent extends BaseComponent {
private static rootElement = 'adf-datatable';
contextMenuActions = new MatMenuComponent(this.page);
constructor(page: Page, rootElement = DataTableComponent.rootElement) {
super(page, rootElement);
}
getEmptyFolderLocator = this.getChild('.adf-empty-folder');
getEmptyContentTitleLocator = this.getChild('adf-empty-content .adf-empty-content__title');
getEmptyContentSubTitleLocator = this.getChild('adf-empty-content .adf-empty-content__subtitle');
/** Locator for row (or rows) */
getRowLocator = this.getChild(`adf-datatable-row`);
/**
* Method used in cases where we want to check that some record is visible in the datatable. It will consider whole row
*
* @returns reference to cell element which contains text.
*/
getRowByName = (name: string | number): Locator => this.getChild(`adf-datatable-row`, { hasText: name.toString() });
/**
* Method used in cases where we want to check that some record is visible in the datatable.
* But we want to check it by column header title and value of this column.
*
* @returns reference to cell element which contains text.
*/
getRowByColumnTitleAndItsCellValue = (columnTitle: string, cellValue: string | number): Locator =>
this.page.locator(`//div[contains(@title, '${columnTitle}')]//span[contains(text(), '${cellValue}')]/ancestor::adf-datatable-row`);
/**
* Method used in cases where user have possibility to navigate "inside" the element (it's clickable and has link attribute).
* Perform action .click() to navigate inside it
*
* @returns reference to cell element which contains link.
*/
getCellLinkByName = (name: string): Locator => this.getChild('.adf-datatable-cell-value[role="link"]', { hasText: name });
/**
* Method used in cases where we want to localize the element by [aria-label]
*
* @returns reference to cell element.
*/
getByAriaLabelTitle = (title: string): Locator => this.getChild(`[aria-label="${title}"]`);
/**
* Method used in cases where we want to get the button (hamburger menu) for row element
*
* @returns reference to menu placed in row localized by the name
*/
getActionsButtonByName = (name: string): Locator =>
this.getRowByName(name).locator('mat-icon', { hasText: new RegExp(`^\\s*more_vert\\s*$`, 'g') });
/**
* Method used in cases where we want to get the edit button and there is no hamburger menu
*
* @returns reference to edit button placed in row localized by the name
*/
getEditButtonByName = (name: string): Locator => this.getRowByName(name).locator('button#editButton');
/**
* Method used in cases where we want to get the button and there is no hamburger menu
*
* @returns reference to button placed in row localized by the name
*/
getButtonByNameForSpecificRow = (elementTitleInRow: string, buttonTitle: string): Locator =>
this.getRowByName(elementTitleInRow).locator('button', { hasText: buttonTitle });
/**
* Method used in cases where you want to get some specific cell (by column name) for row which contains some name/title/etc.
*
* @returns reference to cell element
*/
getCellByColumnNameAndRowItem = (item: string | number, columnName: string): Locator => this.getRowByName(item).locator(`[title="${columnName}"]`);
/**
* Method used in cases where we want to get the checkbox for row element
*
* @returns reference to checkbox placed in row localized by the name
*/
getCheckboxForElement = (item: string): Locator => this.getRowByName(item).locator('mat-checkbox');
getColumnHeaderByTitleLocator = (headerTitle: string): Locator => this.getChild('[role="columnheader"]', { hasText: headerTitle });
async sortBy(columnTitle: string, order: 'Ascending' | 'Descending'): Promise<void> {
const columnHeaderLocator = this.getColumnHeaderByTitleLocator(columnTitle);
await this.spinnerWaitForReload();
await columnHeaderLocator.click();
const sortAttribute = await columnHeaderLocator.getAttribute('aria-sort');
if (sortAttribute !== order) {
await columnHeaderLocator.click();
}
await this.spinnerWaitForReload();
}
/**
* This method is used when we want to perform right mouse click on the dataTable row and perform some action
*
* @param name of the data table element with which we want to click
* @param action provide which action you want to perform
*/
async performActionFromExpandableMenu(name: string | number, action: string): Promise<void> {
const actionButtonLocator = await this.getActionLocatorFromExpandableMenu(name, action);
await actionButtonLocator.click();
await this.spinnerWaitForReload();
}
/**
* Click action from the expandable kebab menu for the element in datatable
*
* @param name title of the record you would like to proceed
* @param action provide button title for the action
* @param subAction if the action is in sub menu, then provide it here
*/
async performActionForElement(name: string, action: string, subAction?: string): Promise<void> {
await this.getActionsButtonByName(name).click();
await this.contextMenuActions.getButtonByText(action).click();
if (subAction) {
await this.contextMenuActions.getButtonByText(subAction).click();
}
}
async getActionLocatorFromExpandableMenu(name: string | number, action: string): Promise<Locator> {
await this.getRowByName(name).click({ button: 'right' });
return this.contextMenuActions.getButtonByText(action);
}
}

View File

@@ -0,0 +1,11 @@
/*
* Copyright © 2005 - 2023 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 * from './data-table.component';
export * from './mat-menu.component';
export * from './toolbar.component';

View File

@@ -0,0 +1,22 @@
/*
* Copyright © 2005 - 2023 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.
*/
import { Page } from '@playwright/test';
import { BaseComponent } from '../base.component';
export class MatMenuComponent extends BaseComponent {
private static rootElement = '.mat-menu-content';
constructor(page: Page) {
super(page, MatMenuComponent.rootElement);
}
public getMenuItemsLocator = this.getChild('button');
public getButtonByText = (text: string) => this.getChild('button', { hasText: text });
}

View File

@@ -0,0 +1,23 @@
/*
* Copyright © 2005 - 2023 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.
*/
import { BaseComponent } from '../base.component';
import { Page } from '@playwright/test';
export class ToolbarComponent extends BaseComponent {
private static rootElement = 'adf-toolbar';
private createRuleButton = this.getChild('[data-automation-id="manage-rules-create-button"]');
constructor(page: Page) {
super(page, ToolbarComponent.rootElement);
}
async clickCreateRuleButton(): Promise<void> {
await this.createRuleButton.click();
}
}

View File

@@ -0,0 +1,11 @@
/*
* Copyright © 2005 - 2023 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 * from './base.component';
export * from './snack-bar.component';
export * from './spinner.component';

View File

@@ -0,0 +1,21 @@
/*
* Copyright © 2005 - 2023 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.
*/
import { Page } from '@playwright/test';
import { BaseComponent } from './base.component';
export class SnackBarComponent extends BaseComponent {
private static rootElement = 'simple-snack-bar';
public message = this.getChild(' > span');
public getByMessageLocator = (message: string) => this.getChild('span', { hasText: message });
constructor(page: Page, rootElement = SnackBarComponent.rootElement) {
super(page, rootElement);
}
}

View File

@@ -0,0 +1,27 @@
/*
* Copyright © 2005 - 2023 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.
*/
import { Page } from '@playwright/test';
import { BaseComponent } from './base.component';
export class SpinnerComponent extends BaseComponent {
private static rootElement = 'mat-progress-spinner';
constructor(page: Page, rootElement = SpinnerComponent.rootElement) {
super(page, rootElement);
}
async waitForReload(): Promise<void> {
try {
await this.getChild('').waitFor({ state: 'attached', timeout: 2000 });
await this.getChild('').waitFor({ state: 'detached', timeout: 2000 });
} catch (e) {
this.logger.info('Spinner was not present');
}
}
}

View File

@@ -0,0 +1,37 @@
/*
* Copyright © 2005 - 2023 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.
*/
const env = process.env;
export const testEmailDomain = env.E2E_EMAIL_DOMAIN;
export const users = {
superadmin: {
username: env.SUPERADMIN_EMAIL,
password: env.SUPERADMIN_PASSWORD
},
identity: {
username: env.IDENTITY_USER_EMAIL,
password: env.IDENTITY_USER_PASSWORD
},
hruser: {
username: env.HR_USER,
password: env.HR_USER_PASSWORD
},
salesuser: {
username: env.SALES_USER,
password: env.SALES_USER_PASSWORD
},
admin: {
username: env.ADMIN_EMAIL,
password: env.ADMIN_PASSWORD
},
contentIdentity: {
username: env.CONTENT_IDENTITY_USERNAME,
password: env.CONTENT_IDENTITY_PASSWORD
}
};

View File

@@ -0,0 +1,13 @@
/*
* Copyright © 2005 - 2023 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 * from './global-variables';
export * from './playwright-base';
export * from './components';
export * from './components/dataTable';
export * from './pages';

View File

@@ -0,0 +1,80 @@
/*
* Copyright © 2005 - 2023 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.
*/
import { Page } from '@playwright/test';
import { PlaywrightBase } from '../playwright-base';
import { SnackBarComponent, SpinnerComponent } from '../components';
export interface NavigateOptions {
query?: string;
waitForRequest?: boolean;
waitUntil?: 'networkidle' | 'commit' | 'load' | 'domcontentloaded';
remoteUrl?: string;
}
export abstract class BasePage extends PlaywrightBase {
private pageUrl: string;
private urlRequest: RegExp;
public snackBar: SnackBarComponent;
public spinner: SpinnerComponent;
constructor(page: Page, pageUrl: string, urlRequest?: RegExp) {
super(page);
this.pageUrl = pageUrl;
this.urlRequest = urlRequest;
this.snackBar = new SnackBarComponent(this.page);
this.spinner = new SpinnerComponent(this.page);
}
/**
* Method which navigate to appropriate page or remoteURL
*
* @param options object with configurable options
* @property {string} query if you would like to navigate to page which support query,
* then pass it in this option - e.g. '?appName=content'
* @property {boolean} waitForRequest if you would like to NOT wait for request (which need to be passed
* in the constructor of the page), then pass false. By default it'll wait for request to be fulfilled.
* @property {'networkidle' | 'commit' | 'load' | 'domcontentloaded'} waitUntil by default will wait until 'networkidle' but you can change it if needed
* @property {string} remoteUrl if you need to navigate to third part site, then you need to pass all of the URL in this option
*/
async navigate(options?: Partial<NavigateOptions>): Promise<void> {
const actualOptions: NavigateOptions = {
query: '',
waitForRequest: true,
remoteUrl: '',
...options
};
if (actualOptions.remoteUrl) {
await this.page.goto(actualOptions.remoteUrl, {
waitUntil: actualOptions.waitUntil
});
} else {
if (this.urlRequest && actualOptions.waitForRequest) {
await Promise.all([
this.page.goto(`./#/${this.pageUrl}${actualOptions.query}`, { waitUntil: 'load' }),
this.page.waitForResponse(this.urlRequest)
]);
} else {
await this.page.goto(`./#/${this.pageUrl}${actualOptions.query}`, {
waitUntil: actualOptions.waitUntil,
timeout: 10000
});
}
}
await this.spinner.waitForReload();
}
async reload(options?: Pick<NavigateOptions, 'waitUntil'>): Promise<void> {
const actualOptions: Pick<NavigateOptions, 'waitUntil'> = {
waitUntil: 'networkidle',
...options
};
await this.page.reload(actualOptions);
}
}

View File

@@ -0,0 +1,10 @@
/*
* Copyright © 2005 - 2023 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 * from './base.page';
export * from './login.page';

View File

@@ -0,0 +1,38 @@
/*
* Copyright © 2005 - 2023 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.
*/
import { Page } from '@playwright/test';
import { BasePage } from './base.page';
import { UserModel } from '../../models';
interface LoginOptions {
waitForLoading?: boolean;
withNavigation?: boolean;
}
export class LoginPage extends BasePage {
constructor(page: Page) {
super(page, '');
}
private username = this.page.locator('#username');
private password = this.page.locator('#password');
private submitButton = this.page.locator('#login-button');
async loginUser(userData: { username: string; password: string } | UserModel, options?: LoginOptions): Promise<void> {
if (options?.withNavigation) {
await this.navigate();
}
await this.username.fill(userData.username);
await this.password.fill(userData.password);
await this.submitButton.click();
if (options?.waitForLoading) {
await Promise.all([this.page.waitForLoadState('domcontentloaded'), this.spinner.waitForReload()]);
}
}
}

View File

@@ -0,0 +1,20 @@
/*
* Copyright © 2005 - 2023 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.
*/
import { GenericLogger, LoggerLike } from '@alfresco/adf-testing';
import { Page } from '@playwright/test';
export abstract class PlaywrightBase {
public page: Page;
public logger: LoggerLike;
constructor(page: Page) {
this.page = page;
this.logger = new GenericLogger(process.env.PLAYWRIGHT_CUSTOM_LOG_LEVEL);
}
}

View File

@@ -0,0 +1,24 @@
{
"extends": "../../tsconfig.e2e.json",
"compilerOptions": {
"outDir": "../../../out-tsc/playwright-testing",
"target": "es2015",
"module": "es2015",
"moduleResolution": "node",
"declaration": true,
"sourceMap": true,
"inlineSources": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"importHelpers": true,
"lib": ["dom", "es2018"]
},
"angularCompilerOptions": {
"skipTemplateCodegen": true,
"strictMetadataEmit": true,
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true,
"enableResourceInlining": true
},
"exclude": ["node_modules"]
}

View File

@@ -0,0 +1,34 @@
/*
* Copyright © 2005 - 2023 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.
*/
import { PersonalFilesPage, NodesPage } from '../page-objects';
import { test as base } from '@playwright/test';
import { ApiClientFactory } from '@alfresco/playwright-shared';
interface Pages {
personalFiles: PersonalFilesPage;
nodesPage: NodesPage;
}
interface Api {
apiClient: ApiClientFactory;
}
export const test = base.extend<Pages & Api>({
personalFiles: async ({ page }, use) => {
await use(new PersonalFilesPage(page));
},
nodesPage: async ({ page }, use) => {
await use(new NodesPage(page));
},
apiClient: async ({}, use) => {
const apiClient = new ApiClientFactory();
await apiClient.setUpAcaBackend('admin');
await use(apiClient);
}
});

View File

@@ -0,0 +1,32 @@
/*
* Copyright © 2005 - 2023 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.
*/
import { Locator, Page } from '@playwright/test';
import { BaseComponent } from '@alfresco/playwright-shared';
export enum ActionType {
Aspect = 'Add aspect',
SimpleWorkflow = 'Add simple workflow',
IncrementCounter = 'Increment Counter'
}
export class ActionsDropdownComponent extends BaseComponent {
private static rootElement = '.mat-select-panel';
public getOptionLocator = (optionName: string): Locator => this.getChild('.mat-option-text', { hasText: optionName });
constructor(page: Page) {
super(page, ActionsDropdownComponent.rootElement);
}
async selectAction(action: Partial<ActionType>): Promise<void> {
await this.page.locator(`aca-edit-rule-dialog [data-automation-id="rule-action-select"]`).click();
const option = this.getOptionLocator(action);
await option.click();
}
}

View File

@@ -0,0 +1,50 @@
/*
* Copyright © 2005 - 2023 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.
*/
import { Locator, Page } from '@playwright/test';
import { ManageRulesDialogComponent } from './manage-rules-dialog.component';
export enum Field {
Name = 'Name',
Size = 'Size',
Mimetype = 'Mimetype'
}
export enum Comparator {
Equals = '(=) Equals',
Contains = 'Contains',
StartsWith = 'Starts with',
EndsWith = 'Ends with'
}
export class ConditionComponent extends ManageRulesDialogComponent {
private getOptionLocator = (optionName: string): Locator => this.page.locator(`.cdk-overlay-pane .mat-option span`, { hasText: optionName });
constructor(page: Page) {
super(page);
}
private async selectField(fields: Partial<Field>): Promise<void> {
await this.fieldDropDown.click();
const option = this.getOptionLocator(fields);
await option.click();
}
private async selectComparator(comparators: Partial<Comparator>): Promise<void> {
await this.comparatorDropDown.click();
const option = this.getOptionLocator(comparators);
await option.click();
}
async addCondition(fields: Partial<Field>, comparators: Partial<Comparator>, value: string): Promise<void> {
await this.addConditionButton.click();
await this.selectField(fields);
await this.selectComparator(comparators);
await this.typeConditionValue(value);
}
}

View File

@@ -0,0 +1,33 @@
/*
* Copyright © 2005 - 2023 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.
*/
import { BaseComponent } from '@alfresco/playwright-shared';
import { Page } from '@playwright/test';
export class ManageRulesDialogComponent extends BaseComponent {
private static rootElement = 'aca-edit-rule-dialog';
public createRuleButton = this.getChild('[data-automation-id="edit-rule-dialog-submit"]');
private ruleNameInputLocator = this.getChild('[id="rule-details-name-input"]');
public addConditionButton = this.getChild('[data-automation-id="add-condition-button"]');
public fieldDropDown = this.getChild('[data-automation-id="field-select"]');
public comparatorDropDown = this.getChild('[data-automation-id="comparator-select"]');
private valueField = this.getChild('[data-automation-id="value-input"]');
constructor(page: Page) {
super(page, ManageRulesDialogComponent.rootElement);
}
async typeRuleName(ruleName: string): Promise<void> {
await this.ruleNameInputLocator.type(ruleName, { delay: 50 });
}
async typeConditionValue(ruleName: string): Promise<void> {
await this.valueField.type(ruleName, { delay: 50 });
}
}

View File

@@ -0,0 +1,21 @@
/*
* Copyright © 2005 - 2023 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.
*/
import { Locator, Page } from '@playwright/test';
import { BaseComponent } from '@alfresco/playwright-shared';
export class ManageRules extends BaseComponent {
private static rootElement = '.aca-manage-rules';
public getGroupsList = (optionName: string): Locator => this.getChild('.aca-rule-list-item__header', { hasText: optionName });
public disableRuleToggle = this.getChild('.aca-manage-rules__container .mat-slide-toggle-bar').first();
constructor(page: Page) {
super(page, ManageRules.rootElement);
}
}

View File

@@ -0,0 +1,10 @@
/*
* Copyright © 2005 - 2023 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 * from './pages/personal-files.page';
export * from './pages/nodes.page';

View File

@@ -0,0 +1,28 @@
/*
* Copyright © 2005 - 2023 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.
*/
import { BasePage, ToolbarComponent } from '@alfresco/playwright-shared';
import { Page } from '@playwright/test';
import { ManageRulesDialogComponent } from '../components/manage-rules-dialog.component';
import { ActionsDropdownComponent } from '../components/actions-dropdown.component';
import { ConditionComponent } from '../components/conditions.component';
import { ManageRules } from '../components/manage-rules.component';
export class NodesPage extends BasePage {
private static pageUrl = 'nodes';
constructor(page: Page) {
super(page, NodesPage.pageUrl);
}
public toolbar = new ToolbarComponent(this.page);
public manageRulesDialog = new ManageRulesDialogComponent(this.page);
public actionsDropdown = new ActionsDropdownComponent(this.page);
public conditionsDropdown = new ConditionComponent(this.page);
public manageRules = new ManageRules(this.page);
}

View File

@@ -0,0 +1,20 @@
/*
* Copyright © 2005 - 2023 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.
*/
import { BasePage, DataTableComponent } from '@alfresco/playwright-shared';
import { Page } from '@playwright/test';
export class PersonalFilesPage extends BasePage {
private static pageUrl = 'personal-files';
constructor(page: Page) {
super(page, PersonalFilesPage.pageUrl);
}
public dataTable = new DataTableComponent(this.page);
}

View File

@@ -0,0 +1,52 @@
import { PlaywrightTestConfig, devices } from '@playwright/test';
require('dotenv').config();
export const config: PlaywrightTestConfig = {
testDir: './',
expect: {
/**
* Maximum time expect() should wait for the condition to be met.
* For example in `await expect(locator).toHaveText();`
*/
timeout: 10000
},
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: 5,
timeout: 20000,
globalSetup: require.resolve('../../shared/base-config/global.setup'),
use: {
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
storageState: './storage-state/AdminUserState.json',
actionTimeout: 0,
/* Base URL to use in actions like `await page.goto('/')`. */
baseURL: process.env.PLAYWRIGHT_E2E_HOST,
ignoreHTTPSErrors: true,
bypassCSP: true,
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
launchOptions: {
devtools: false,
args: ['--disable-web-security', '--no-sandbox', '--disable-site-isolation-trials']
}
},
/* Configure projects for major browsers */
projects: [
{
name: 'chromium',
use: {
...devices['Desktop Chrome']
}
}
]
};
export default config;

View File

@@ -0,0 +1,34 @@
import { test } from '../fixtures/page-initialization';
import { NodeBodyCreate } from '@alfresco/aca-testing-shared';
import { ActionType } from '../page-objects/components/actions-dropdown.component';
import { expect } from '@playwright/test';
test.describe('Folder Rules Actions', () => {
const randomFolderName = `playwright-folder-${(Math.random() + 1).toString(36).substring(6)}`;
const randomRuleName = `playwright-rule-${(Math.random() + 1).toString(36).substring(6)}`;
let folderId: string;
test.beforeAll(async ({ apiClient }) => {
folderId = (await apiClient.nodes.createNode('-my-', new NodeBodyCreate(randomFolderName, 'cm:folder'))).entry.id;
});
test.beforeEach(async ({ personalFiles }) => {
await personalFiles.navigate({ waitUntil: 'domcontentloaded' });
});
test.afterAll(async ({ apiClient }) => {
await apiClient.nodes.deleteNode(folderId);
});
test('Create a rule with actions', async ({ personalFiles, nodesPage }) => {
await personalFiles.dataTable.performActionFromExpandableMenu(randomFolderName, 'Manage rules');
await nodesPage.toolbar.clickCreateRuleButton();
await nodesPage.manageRulesDialog.typeRuleName(randomRuleName);
await nodesPage.actionsDropdown.selectAction(ActionType.IncrementCounter);
await nodesPage.manageRulesDialog.createRuleButton.click();
await expect.soft(nodesPage.manageRules.getGroupsList(randomRuleName)).toBeVisible();
});
});

View File

@@ -0,0 +1,37 @@
import { test } from '../fixtures/page-initialization';
import { NodeBodyCreate } from '@alfresco/aca-testing-shared';
import { ActionType } from '../page-objects/components/actions-dropdown.component';
import { Comparator, Field } from '../page-objects/components/conditions.component';
import { expect } from '@playwright/test';
test.describe('Folder Rules Conditions', () => {
const randomFolderName = `playwright-folder-${(Math.random() + 1).toString(36).substring(6)}`;
const randomRuleName = `playwright-rule-${(Math.random() + 1).toString(36).substring(6)}`;
const specialChars = '!@£$%^&*()~#/';
let folderId: string;
test.beforeAll(async ({ apiClient }) => {
folderId = (await apiClient.nodes.createNode('-my-', new NodeBodyCreate(randomFolderName, 'cm:folder'))).entry.id;
});
test.beforeEach(async ({ personalFiles }) => {
await personalFiles.navigate();
});
test.afterAll(async ({ apiClient }) => {
await apiClient.nodes.deleteNode(folderId);
});
test('Create a rule with condition', async ({ personalFiles, nodesPage }) => {
await personalFiles.dataTable.performActionFromExpandableMenu(randomFolderName, 'Manage rules');
await nodesPage.toolbar.clickCreateRuleButton();
await nodesPage.manageRulesDialog.typeRuleName(randomRuleName);
await nodesPage.conditionsDropdown.addCondition(Field.Size, Comparator.Equals, specialChars);
await nodesPage.actionsDropdown.selectAction(ActionType.IncrementCounter);
await nodesPage.manageRulesDialog.createRuleButton.click();
await expect.soft(nodesPage.manageRules.getGroupsList(randomRuleName)).toBeVisible();
});
});

View File

@@ -0,0 +1,27 @@
import { test } from '../fixtures/page-initialization';
import { NodeBodyCreate } from '@alfresco/aca-testing-shared';
test.describe('Rules - Manage Rules', () => {
const randomName = `playwright-folder-${(Math.random() + 1).toString(36).substring(6)}`;
const randomRuleName = `playwright-rule-${(Math.random() + 1).toString(36).substring(6)}`;
let folderId: string;
test.beforeAll(async ({ apiClient }) => {
folderId = (await apiClient.nodes.createNode('-my-', new NodeBodyCreate(randomName, 'cm:folder'))).entry.id;
await apiClient.createRandomRule(folderId, randomRuleName);
});
test.beforeEach(async ({ personalFiles }) => {
await personalFiles.navigate();
});
test.afterAll(async ({ apiClient }) => {
await apiClient.nodes.deleteNode(folderId);
});
test('Disable an existing rule', async ({ personalFiles, nodesPage }) => {
await personalFiles.dataTable.performActionFromExpandableMenu(randomName, 'Manage rules');
await nodesPage.manageRules.disableRuleToggle.click();
});
});