mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
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:
@@ -20,3 +20,4 @@ export * from './pages/public-api';
|
||||
export * from './models/public-api';
|
||||
export * from './dialog/public-api';
|
||||
export * from './utils/public-api';
|
||||
export * from './test-element';
|
||||
|
90
lib/testing/src/lib/core/test-element.ts
Normal file
90
lib/testing/src/lib/core/test-element.ts
Normal file
@@ -0,0 +1,90 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { by, element, ElementFinder, protractor } from 'protractor';
|
||||
import { BrowserActions } from './utils/browser-actions';
|
||||
import { BrowserVisibility } from './utils/browser-visibility';
|
||||
|
||||
export class TestElement {
|
||||
constructor(public elementFinder: ElementFinder) {}
|
||||
|
||||
static byId(id: string): TestElement {
|
||||
return new TestElement(element(by.id(id)));
|
||||
}
|
||||
|
||||
static byCss(selector: string): TestElement {
|
||||
return new TestElement(element(by.css(selector)));
|
||||
}
|
||||
|
||||
static byText(selector: string, text: string): TestElement {
|
||||
return new TestElement(element(by.cssContainingText(selector, text)));
|
||||
}
|
||||
|
||||
static byTag(selector: string): TestElement {
|
||||
return new TestElement(element(by.tagName(selector)));
|
||||
}
|
||||
|
||||
async click() {
|
||||
return BrowserActions.click(this.elementFinder);
|
||||
}
|
||||
|
||||
async waitVisible(waitTimeout?: number) {
|
||||
return BrowserVisibility.waitUntilElementIsVisible(this.elementFinder, waitTimeout);
|
||||
}
|
||||
|
||||
async waitNotVisible(waitTimeout?: number) {
|
||||
return BrowserVisibility.waitUntilElementIsNotVisible(this.elementFinder, waitTimeout);
|
||||
}
|
||||
|
||||
async waitPresent(waitTimeout?: number) {
|
||||
return BrowserVisibility.waitUntilElementIsPresent(this.elementFinder, waitTimeout);
|
||||
}
|
||||
|
||||
async waitNotPresent(waitTimeout?: number) {
|
||||
return BrowserVisibility.waitUntilElementIsNotPresent(this.elementFinder, waitTimeout);
|
||||
}
|
||||
|
||||
async waitHasValue(value: string) {
|
||||
return BrowserVisibility.waitUntilElementHasValue(this.elementFinder, value);
|
||||
}
|
||||
|
||||
async isEnabled(): Promise<boolean> {
|
||||
return this.elementFinder.isEnabled();
|
||||
}
|
||||
|
||||
async isDisplayed(): Promise<boolean> {
|
||||
return this.elementFinder.isDisplayed();
|
||||
}
|
||||
|
||||
async getAttribute(name: string): Promise<string> {
|
||||
await this.waitVisible();
|
||||
return this.elementFinder.getAttribute(name);
|
||||
}
|
||||
|
||||
async getText(): Promise<string> {
|
||||
return BrowserActions.getText(this.elementFinder);
|
||||
}
|
||||
|
||||
async typeText(text: string) {
|
||||
return BrowserActions.clearSendKeys(this.elementFinder, text);
|
||||
}
|
||||
|
||||
async clearInput() {
|
||||
await this.elementFinder.clear();
|
||||
await this.elementFinder.sendKeys(' ', protractor.Key.CONTROL, 'a', protractor.Key.NULL, protractor.Key.BACK_SPACE);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user