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,140 +15,30 @@
* limitations under the License.
*/
import { by, element, protractor } from 'protractor';
import { BrowserVisibility, BrowserActions } from '@alfresco/adf-testing';
import { by, element } from 'protractor';
import { BrowserActions, TestElement } from '@alfresco/adf-testing';
export class CreateLibraryDialogPage {
libraryDialog = element(by.css('[role="dialog"]'));
libraryTitle = element(by.css('.adf-library-dialog>h2'));
libraryNameField = element(by.css('input[formcontrolname="title"]'));
libraryIdField = element(by.css('input[formcontrolname="id"]'));
libraryDescriptionField = element(by.css('textarea[formcontrolname="description"]'));
publicRadioButton = element(by.css('[data-automation-id="PUBLIC"]>label'));
privateRadioButton = element(by.css('[data-automation-id="PRIVATE"]>label'));
moderatedRadioButton = element(by.css('[data-automation-id="MODERATED"]>label'));
cancelButton = element(by.css('button[data-automation-id="cancel-library-id"]'));
createButton = element(by.css('button[data-automation-id="create-library-id"]'));
errorMessage = element(by.css('.mat-dialog-content .mat-error'));
libraryDialog = TestElement.byCss('[role="dialog"]');
libraryTitle = TestElement.byCss('.adf-library-dialog>h2');
libraryNameField = TestElement.byCss('input[formcontrolname="title"]');
libraryIdField = TestElement.byCss('input[formcontrolname="id"]');
libraryDescriptionField = TestElement.byCss('textarea[formcontrolname="description"]');
publicRadioButton = TestElement.byCss('[data-automation-id="PUBLIC"]>label');
privateRadioButton = TestElement.byCss('[data-automation-id="PRIVATE"]>label');
moderatedRadioButton = TestElement.byCss('[data-automation-id="MODERATED"]>label');
cancelButton = TestElement.byCss('button[data-automation-id="cancel-library-id"]');
createButton = TestElement.byCss('button[data-automation-id="create-library-id"]');
errorMessage = TestElement.byCss('.mat-dialog-content .mat-error');
errorMessages = element.all(by.css('.mat-dialog-content .mat-error'));
libraryNameHint = element(by.css('adf-library-dialog .mat-hint'));
libraryNameHint = TestElement.byCss('adf-library-dialog .mat-hint');
async getSelectedRadio(): Promise<string> {
const radio = element(by.css('.mat-radio-button[class*="checked"]'));
return BrowserActions.getText(radio);
}
async waitForDialogToOpen(): Promise<void> {
await BrowserVisibility.waitUntilElementIsVisible(this.libraryDialog);
}
async waitForDialogToClose(): Promise<void> {
await BrowserVisibility.waitUntilElementIsNotPresent(this.libraryDialog, 60000);
}
async isDialogOpen(): Promise<any> {
return BrowserVisibility.waitUntilElementIsVisible(this.libraryDialog);
}
async getTitle(): Promise<string> {
return BrowserActions.getText(this.libraryTitle);
}
async waitUntilLibraryIdTextHasValue(value: string): Promise<void> {
await BrowserVisibility.waitUntilElementHasValue(this.libraryIdField, value);
}
async waitErrorMessageIsDisplayed(): Promise<void> {
await BrowserVisibility.waitUntilElementIsVisible(this.errorMessage, 60000);
}
async getErrorMessage(): Promise<string> {
return BrowserActions.getText(this.errorMessage);
}
async getErrorMessages(position: number): Promise<string> {
return BrowserActions.getText(this.errorMessages.get(position));
}
async waitForLibraryNameHint(): Promise<void> {
await BrowserVisibility.waitUntilElementIsVisible(this.libraryNameHint);
}
async getLibraryNameHint(): Promise<string> {
return BrowserActions.getText(this.libraryNameHint);
}
async isNameDisplayed(): Promise<boolean> {
return this.libraryNameField.isDisplayed();
}
async isLibraryIdDisplayed(): Promise<boolean> {
return this.libraryIdField.isDisplayed();
}
async isDescriptionDisplayed(): Promise<boolean> {
return this.libraryDescriptionField.isDisplayed();
}
async isPublicDisplayed(): Promise<boolean> {
return this.publicRadioButton.isDisplayed();
}
async isModeratedDisplayed(): Promise<boolean> {
return this.moderatedRadioButton.isDisplayed();
}
async isPrivateDisplayed(): Promise<boolean> {
return this.privateRadioButton.isDisplayed();
}
async isCreateEnabled(): Promise<boolean> {
return this.createButton.isEnabled();
}
async isCancelEnabled(): Promise<boolean> {
return this.cancelButton.isEnabled();
}
async clickCreate(): Promise<void> {
await BrowserActions.click(this.createButton);
}
async clickCancel(): Promise<void> {
await BrowserActions.click(this.cancelButton);
}
async typeLibraryName(libraryName: string): Promise<void> {
await BrowserActions.clearSendKeys(this.libraryNameField, libraryName);
}
async typeLibraryId(libraryId: string): Promise<void> {
await BrowserActions.clearSendKeys(this.libraryIdField, libraryId);
}
async typeLibraryDescription(libraryDescription: string): Promise<void> {
await BrowserActions.clearSendKeys(this.libraryDescriptionField, libraryDescription);
}
async clearLibraryName(): Promise<void> {
await this.libraryNameField.clear();
await this.libraryNameField.sendKeys(' ', protractor.Key.CONTROL, 'a', protractor.Key.NULL, protractor.Key.BACK_SPACE);
}
async clearLibraryId(): Promise<void> {
await this.libraryIdField.clear();
await this.libraryIdField.sendKeys(' ', protractor.Key.CONTROL, 'a', protractor.Key.NULL, protractor.Key.BACK_SPACE);
}
async selectPublic(): Promise<void> {
await BrowserActions.click(this.publicRadioButton);
}
async selectPrivate(): Promise<void> {
await BrowserActions.click(this.privateRadioButton);
}
async selectModerated(): Promise<void> {
await BrowserActions.click(this.moderatedRadioButton);
}
}