TestElement prototype to greatly reduce e2e coding time (#6525)

* TestElement prototype

* introduce byText wrapper

* extend TestElement api

* cleanup tests a bit more

* cleanup e2e

* more e2e cleanup

* add missing CSS classes

* fix test
This commit is contained in:
Denys Vuika
2021-01-15 11:31:45 +00:00
committed by GitHub
parent 6f3ce8b6f3
commit c9705b06d5
30 changed files with 484 additions and 758 deletions

View File

@@ -15,42 +15,13 @@
* limitations under the License.
*/
import { element, by } from 'protractor';
import { BrowserVisibility, BrowserActions } from '@alfresco/adf-testing';
import { TestElement } from '@alfresco/adf-testing';
export class LockFilePage {
cancelButton = element(by.css('button[data-automation-id="lock-dialog-btn-cancel"]'));
saveButton = element(by.cssContainingText('button span', 'Save'));
lockFileCheckboxText = element(by.cssContainingText('mat-checkbox label span', ' Lock file '));
lockFileCheckbox = element(by.css('mat-checkbox[data-automation-id="adf-lock-node-checkbox"]'));
allowOwnerCheckbox = element(by.cssContainingText('mat-checkbox[class*="adf-lock-file-name"] span', ' Allow the owner to modify this file '));
async checkLockFileCheckboxIsDisplayed(): Promise<void> {
await BrowserVisibility.waitUntilElementIsVisible(this.lockFileCheckboxText);
}
async checkCancelButtonIsDisplayed(): Promise<void> {
await BrowserVisibility.waitUntilElementIsVisible(this.cancelButton);
}
async checkSaveButtonIsDisplayed(): Promise<void> {
await BrowserVisibility.waitUntilElementIsVisible(this.saveButton);
}
async clickCancelButton(): Promise<void> {
await BrowserActions.click(this.cancelButton);
}
async clickLockFileCheckbox(): Promise<void> {
await BrowserActions.click(this.lockFileCheckbox);
}
async clickSaveButton(): Promise<void> {
await BrowserActions.click(this.saveButton);
}
async clickAllowOwnerCheckbox(): Promise<void> {
await BrowserActions.click(this.allowOwnerCheckbox);
}
cancelButton = TestElement.byCss('button[data-automation-id="lock-dialog-btn-cancel"]');
saveButton = TestElement.byText('button span', 'Save');
lockFileCheckboxText = TestElement.byText('mat-checkbox label span', ' Lock file ');
lockFileCheckbox = TestElement.byCss('mat-checkbox[data-automation-id="adf-lock-node-checkbox"]');
allowOwnerCheckbox = TestElement.byText('mat-checkbox[class*="adf-lock-file-name"] span', ' Allow the owner to modify this file ');
}

View File

@@ -15,12 +15,7 @@
* limitations under the License.
*/
import {
DataTableComponentPage,
AddPermissionsDialogPage,
BrowserVisibility,
BrowserActions
} from '@alfresco/adf-testing';
import { DataTableComponentPage, AddPermissionsDialogPage, TestElement } from '@alfresco/adf-testing';
import { browser, by, element } from 'protractor';
export class PermissionsPage {
@@ -28,7 +23,7 @@ export class PermissionsPage {
dataTableComponentPage = new DataTableComponentPage();
addPermissionsDialog = new AddPermissionsDialogPage();
addPermissionButton = element(by.css("button[data-automation-id='adf-add-permission-button']"));
addPermissionButton = TestElement.byCss("button[data-automation-id='adf-add-permission-button']");
addPermissionDialog = element(by.css('adf-add-permission-dialog'));
searchUserInput = element(by.id('searchInput'));
searchResults = element(by.css('#adf-add-permission-authority-results #adf-search-results-content'));
@@ -37,11 +32,7 @@ export class PermissionsPage {
noPermissions = element(by.id('adf-no-permissions-template'));
deletePermissionButton = element(by.css(`button[data-automation-id='adf-delete-permission-button']`));
permissionDisplayContainer = element(by.id('adf-permission-display-container'));
closeButton = element(by.id('add-permission-dialog-close-button'));
async clickCloseButton(): Promise<void> {
await BrowserActions.click(this.closeButton);
}
closeButton = TestElement.byCss('#add-permission-dialog-close-button');
async changePermission(name: string, role: string): Promise<void> {
await this.addPermissionsDialog.clickRoleDropdownByUserOrGroupName(name);
@@ -49,8 +40,4 @@ export class PermissionsPage {
await browser.sleep(500);
await this.dataTableComponentPage.checkRowIsNotSelected('Authority ID', name);
}
async checkAddPermissionButtonIsDisplayed(): Promise<void> {
await BrowserVisibility.waitUntilElementIsVisible(this.addPermissionButton);
}
}

View File

@@ -15,29 +15,26 @@
* limitations under the License.
*/
import { Locator, element, by, protractor, browser } from 'protractor';
import { BrowserVisibility, BrowserActions } from '@alfresco/adf-testing';
import { element, by, protractor, browser } from 'protractor';
import { BrowserActions, TestElement } from '@alfresco/adf-testing';
export class TagPage {
addTagButton = element(by.id('add-tag'));
addTagButton = TestElement.byCss('#add-tag');
insertNodeIdElement = element(by.css('input[id="nodeId"]'));
newTagInput = element(by.css('input[id="new-tag-text"]'));
tagListRow = element(by.css('adf-tag-node-actions-list mat-list-item'));
tagListByNodeIdRow = element(by.css('adf-tag-node-list mat-chip'));
errorMessage = element(by.css('mat-hint[data-automation-id="errorMessage"]'));
tagListRowLocator: Locator = by.css('adf-tag-node-actions-list mat-list-item div');
tagListByNodeIdRowLocator: Locator = by.css('adf-tag-node-list mat-chip span');
tagListContentServicesRowLocator: Locator = by.css('div[class*="adf-list-tag"]');
showDeleteButton = element(by.id('adf-remove-button-tag'));
showMoreButton = element(by.css('button[data-automation-id="show-more-tags"]'));
showLessButton = element(by.css('button[data-automation-id="show-fewer-tags"]'));
newTagInput = TestElement.byCss('input[id="new-tag-text"]');
tagListRow = TestElement.byCss('adf-tag-node-actions-list mat-list-item');
tagListByNodeIdRow = TestElement.byCss('adf-tag-node-list mat-chip');
errorMessage = TestElement.byCss('mat-hint[data-automation-id="errorMessage"]');
tagListContentServicesRowLocator = by.css('div[class*="adf-list-tag"]');
showDeleteButton = TestElement.byCss('#adf-remove-button-tag');
showMoreButton = TestElement.byCss('button[data-automation-id="show-more-tags"]');
showLessButton = TestElement.byCss('button[data-automation-id="show-fewer-tags"]');
tagsOnPage = element.all(by.css('div[class*="adf-list-tag"]'));
confirmTag = element(by.id('adf-tag-node-send'));
confirmTag = TestElement.byCss('#adf-tag-node-send');
async getNodeId(): Promise<string> {
await BrowserVisibility.waitUntilElementIsVisible(this.insertNodeIdElement);
return this.insertNodeIdElement.getAttribute('value');
getNodeId(): Promise<string> {
return new TestElement(this.insertNodeIdElement).getAttribute('value');
}
async insertNodeId(nodeId) {
@@ -47,163 +44,48 @@ export class TagPage {
await this.insertNodeIdElement.sendKeys(' ');
await browser.sleep(200);
await this.insertNodeIdElement.sendKeys(protractor.Key.BACK_SPACE);
await this.clickConfirmTag();
}
async addNewTagInput(tag: string) {
await BrowserActions.clearSendKeys(this.newTagInput, tag);
await this.confirmTag.click();
}
async addTag(tag: string): Promise<void> {
await this.addNewTagInput(tag);
await BrowserActions.click(this.addTagButton);
await this.newTagInput.typeText(tag);
return this.addTagButton.click();
}
async deleteTagFromTagListByNodeId(name: string): Promise<void> {
const deleteChip = element(by.id('tag_chips_delete_' + name));
await BrowserActions.click(deleteChip);
deleteTagFromTagListByNodeId(name: string): Promise<void> {
return TestElement.byId('tag_chips_delete_' + name).click();
}
async deleteTagFromTagList(name: string): Promise<void> {
const deleteChip = element(by.id('tag_chips_delete_' + name));
await BrowserActions.click(deleteChip);
}
async getNewTagInput(): Promise<string> {
await BrowserVisibility.waitUntilElementIsVisible(this.newTagInput);
return this.newTagInput.getAttribute('value');
}
async getNewTagPlaceholder(): Promise<string> {
await BrowserVisibility.waitUntilElementIsVisible(this.newTagInput);
return this.newTagInput.getAttribute('data-placeholder');
deleteTagFromTagList(name: string): Promise<void> {
return TestElement.byId('tag_chips_delete_' + name).click();
}
async addTagButtonIsEnabled(): Promise<boolean> {
await BrowserVisibility.waitUntilElementIsVisible(this.addTagButton);
await this.addTagButton.waitVisible();
return this.addTagButton.isEnabled();
}
async checkTagIsDisplayedInTagList(tagName: string): Promise<void> {
const tag = element(by.cssContainingText('div[id*="tag_name"]', tagName));
await BrowserVisibility.waitUntilElementIsVisible(tag);
checkTagIsDisplayedInTagList(tagName: string): Promise<void> {
return TestElement.byText('div[id*="tag_name"]', tagName).waitVisible();
}
async checkTagIsNotDisplayedInTagList(tagName: string): Promise<void> {
const tag = element(by.cssContainingText('div[id*="tag_name"]', tagName));
await BrowserVisibility.waitUntilElementIsNotVisible(tag);
checkTagIsNotDisplayedInTagList(tagName: string): Promise<void> {
return TestElement.byText('div[id*="tag_name"]', tagName).waitNotVisible();
}
async checkTagIsNotDisplayedInTagListByNodeId(tagName: string): Promise<void> {
const tag = element(by.cssContainingText('span[id*="tag_name"]', tagName));
await BrowserVisibility.waitUntilElementIsNotVisible(tag);
checkTagIsNotDisplayedInTagListByNodeId(tagName: string): Promise<void> {
return TestElement.byText('span[id*="tag_name"]', tagName).waitNotVisible();
}
async checkTagIsDisplayedInTagListByNodeId(tagName: string): Promise<void> {
const tag = element(by.cssContainingText('span[id*="tag_name"]', tagName));
await BrowserVisibility.waitUntilElementIsVisible(tag);
checkTagIsDisplayedInTagListByNodeId(tagName: string): Promise<void> {
return TestElement.byText('span[id*="tag_name"]', tagName).waitVisible();
}
async checkTagListIsEmpty(): Promise<void> {
await BrowserVisibility.waitUntilElementIsNotVisible(this.tagListRow);
checkDeleteTagFromTagListByNodeIdIsDisplayed(name: string): Promise<void> {
return TestElement.byId('tag_chips_delete_' + name).waitVisible();
}
async checkTagListByNodeIdIsEmpty(): Promise<void> {
await BrowserVisibility.waitUntilElementIsNotVisible(this.tagListByNodeIdRow);
}
async checkTagIsDisplayedInTagListContentServices(tagName: string): Promise<void> {
const tag = element(by.cssContainingText('.adf-list-tag[id*="tag_name"]', tagName));
await BrowserVisibility.waitUntilElementIsVisible(tag);
}
async getErrorMessage(): Promise<string> {
return BrowserActions.getText(this.errorMessage);
}
async checkTagListIsOrderedAscending(): Promise<any> {
await this.checkListIsSorted(false, this.tagListRowLocator);
}
async checkTagListByNodeIdIsOrderedAscending(): Promise<any> {
await this.checkListIsSorted(false, this.tagListByNodeIdRowLocator);
}
async checkTagListContentServicesIsOrderedAscending(): Promise<any> {
await this.checkListIsSorted(false, this.tagListContentServicesRowLocator);
}
async checkListIsSorted(sortOrder, locator): Promise<boolean> {
const tagList = element.all(locator);
await BrowserVisibility.waitUntilElementIsVisible(tagList.first());
const initialList = [];
await tagList.each(async (currentElement) => {
const text = await BrowserActions.getText(currentElement);
initialList.push(text);
});
let sortedList = initialList;
sortedList = sortedList.sort();
if (sortOrder === false) {
sortedList = sortedList.reverse();
}
return initialList.toString() === sortedList.toString();
}
async checkDeleteTagFromTagListByNodeIdIsDisplayed(name: string): Promise<void> {
const deleteChip = element(by.id('tag_chips_delete_' + name));
await BrowserVisibility.waitUntilElementIsVisible(deleteChip);
}
async checkDeleteTagFromTagListByNodeIdIsNotDisplayed(name: string): Promise<void> {
const deleteChip = element(by.id('tag_chips_delete_' + name));
await BrowserVisibility.waitUntilElementIsNotVisible(deleteChip);
}
async clickShowDeleteButtonSwitch(): Promise<void> {
await BrowserActions.click(this.showDeleteButton);
}
async checkShowMoreButtonIsDisplayed(): Promise<void> {
await BrowserVisibility.waitUntilElementIsVisible(this.showMoreButton);
}
async clickShowMoreButton(): Promise<void> {
await BrowserActions.click(this.showMoreButton);
}
async clickShowLessButton(): Promise<void> {
await BrowserActions.click(this.showLessButton);
}
async clickConfirmTag(): Promise<void> {
await BrowserActions.click(this.confirmTag);
}
async checkTagsOnList(): Promise<number> {
return this.tagsOnPage.count();
}
async checkShowLessButtonIsDisplayed(): Promise<void> {
await BrowserVisibility.waitUntilElementIsVisible(this.showLessButton);
}
async checkShowLessButtonIsNotDisplayed(): Promise<void> {
await BrowserVisibility.waitUntilElementIsNotVisible(this.showLessButton);
}
async clickShowMoreButtonUntilNotDisplayed(): Promise<void> {
const visible = await this.showMoreButton.isDisplayed();
if (visible) {
await BrowserActions.click(this.showMoreButton);
await this.clickShowMoreButtonUntilNotDisplayed();
}
}
async clickShowLessButtonUntilNotDisplayed(): Promise<void> {
const visible = await this.showLessButton.isDisplayed();
if (visible) {
await BrowserActions.click(this.showLessButton);
await this.clickShowLessButtonUntilNotDisplayed();
}
checkDeleteTagFromTagListByNodeIdIsNotDisplayed(name: string): Promise<void> {
return TestElement.byId('tag_chips_delete_' + name).waitNotVisible();
}
}