adf-testing package (#4152)

* add new lib adf-testing

* fix the prefix

* Improve package

* Add testing project

* remove useless stuff

* Remove useless code
This commit is contained in:
Maurizio Vitale
2019-02-19 15:08:41 +00:00
committed by Eugenio Romano
parent 81ec4ed441
commit 08231bbf33
36 changed files with 717 additions and 5 deletions

View File

@@ -0,0 +1,20 @@
/*!
* @license
* Copyright 2016 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.
*/
export class ExampleAction {
}

View File

@@ -0,0 +1,5 @@
/*
* Public API Surface of testing
*/
export * from './example.action';

View File

@@ -0,0 +1,20 @@
/*!
* @license
* Copyright 2016 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.
*/
export class ExamplePage {
}

View File

@@ -0,0 +1,5 @@
/*
* Public API Surface of testing
*/
export * from './example.page';

View File

@@ -0,0 +1,6 @@
/*
* Public API Surface of testing
*/
export * from './pages/public-api';
export * from './actions/public-api';

View File

@@ -0,0 +1,3 @@
/*
* Public API Surface of testing
*/

View File

@@ -0,0 +1,83 @@
/*!
* @license
* Copyright 2016 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 { browser, protractor } from 'protractor';
let until = protractor.ExpectedConditions;
const DEFAULT_TIMEOUT = 40000;
export class BrowserVisibility {
constructor() {}
/*
* Wait for element is visible
*/
static waitUntilElementIsVisible(elementToCheck, waitTimeout: number = DEFAULT_TIMEOUT) {
let isDisplayed = false;
return browser.wait(() => {
browser.waitForAngularEnabled();
elementToCheck.isDisplayed().then(
() => {
isDisplayed = true;
},
(err) => {
isDisplayed = false;
}
);
return isDisplayed;
}, waitTimeout, 'Element is not visible ' + elementToCheck.locator());
}
/*
* Wait for element to be clickable
*/
static waitUntilElementIsClickable(elementToCheck, waitTimeout: number = DEFAULT_TIMEOUT) {
let isDisplayed = false;
return browser.wait(() => {
browser.waitForAngularEnabled();
elementToCheck.isDisplayed().then(
() => {
isDisplayed = true;
},
(err) => {
isDisplayed = false;
}
);
return isDisplayed;
}, waitTimeout, 'Element is not visible ' + elementToCheck.locator());
}
/*
* Wait for element to have value
*/
static waitUntilElementHasValue(elementToCheck, elementValue, waitTimeout: number = DEFAULT_TIMEOUT) {
browser.waitForAngularEnabled();
browser.wait(until.textToBePresentInElementValue(elementToCheck, elementValue), waitTimeout, 'Element doesn\'t have a value ' + elementToCheck.locator());
}
/*
* Wait for element to not be visible
*/
static waitUntilElementIsNotOnPage(elementToCheck, waitTimeout: number = DEFAULT_TIMEOUT) {
return browser.wait(until.not(until.visibilityOf(elementToCheck)), waitTimeout, 'Element is not in the page ' + elementToCheck.locator());
}
}

View File

@@ -0,0 +1,138 @@
/*!
* @license
* Copyright 2016 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 { element, by, protractor } from 'protractor';
import { BrowserVisibility } from '../browser-visibility';
export class HeaderPage {
checkBox = element(by.cssContainingText('.mat-checkbox-label', 'Show menu button'));
headerColor = element(by.css('option[value="primary"]'));
titleInput = element(by.css('input[name="title"]'));
iconInput = element(by.css('input[placeholder="URL path"]'));
hexColorInput = element(by.css('input[placeholder="hex color code"]'));
logoHyperlinkInput = element(by.css('input[placeholder="Redirect URL"]'));
logoTooltipInput = element(by.css('input[placeholder="Tooltip text"]'));
positionStart = element.all(by.css('mat-radio-button[value="start"]')).first();
positionEnd = element.all(by.css('mat-radio-button[value="end"]')).first();
sideBarPositionRight = element(by.css('mat-sidenav.mat-drawer.mat-sidenav.mat-drawer-end'));
sideBarPositionLeft = element(by.css('mat-sidenav.mat-drawer.mat-sidenav'));
checkShowMenuCheckBoxIsDisplayed() {
return BrowserVisibility.waitUntilElementIsVisible(this.checkBox);
}
checkChooseHeaderColourIsDisplayed() {
return BrowserVisibility.waitUntilElementIsVisible(this.headerColor);
}
checkChangeTitleIsDisplayed() {
return BrowserVisibility.waitUntilElementIsVisible(this.titleInput);
}
checkChangeUrlPathIsDisplayed() {
return BrowserVisibility.waitUntilElementIsVisible(this.iconInput);
}
clickShowMenuButton() {
let checkBox = element.all(by.css('mat-checkbox'));
BrowserVisibility.waitUntilElementIsVisible(checkBox);
return checkBox.get(0).click();
}
changeHeaderColor(color) {
let headerColor = element(by.css('option[value="' + color + '"]'));
return headerColor.click();
}
checkAppTitle(name) {
let title = element(by.cssContainingText('.adf-app-title', name));
return BrowserVisibility.waitUntilElementIsVisible(title);
}
addTitle(title) {
BrowserVisibility.waitUntilElementIsVisible(this.titleInput);
this.titleInput.click();
this.titleInput.sendKeys(title);
this.titleInput.sendKeys(protractor.Key.ENTER);
}
checkIconIsDisplayed(url) {
let icon = element(by.css('img[src="' + url + '"]'));
BrowserVisibility.waitUntilElementIsVisible(icon);
}
addIcon(url) {
BrowserVisibility.waitUntilElementIsVisible(this.iconInput);
this.iconInput.click();
this.iconInput.sendKeys(url);
this.iconInput.sendKeys(protractor.Key.ENTER);
}
checkHexColorInputIsDisplayed() {
return BrowserVisibility.waitUntilElementIsVisible(this.hexColorInput);
}
checkLogoHyperlinkInputIsDisplayed() {
return BrowserVisibility.waitUntilElementIsVisible(this.logoHyperlinkInput);
}
checkLogoTooltipInputIsDisplayed() {
return BrowserVisibility.waitUntilElementIsVisible(this.logoTooltipInput);
}
addHexCodeColor(hexCode) {
BrowserVisibility.waitUntilElementIsVisible(this.hexColorInput);
this.hexColorInput.click();
this.hexColorInput.sendKeys(hexCode);
return this.hexColorInput.sendKeys(protractor.Key.ENTER);
}
addLogoHyperlink(hyperlink) {
BrowserVisibility.waitUntilElementIsVisible(this.logoHyperlinkInput);
BrowserVisibility.waitUntilElementIsClickable(this.logoHyperlinkInput);
this.logoHyperlinkInput.click();
this.logoHyperlinkInput.sendKeys(hyperlink);
return this.logoHyperlinkInput.sendKeys(protractor.Key.ENTER);
}
addLogoTooltip(tooltip) {
BrowserVisibility.waitUntilElementIsVisible(this.logoTooltipInput);
this.logoTooltipInput.click();
this.logoTooltipInput.sendKeys(tooltip);
return this.logoTooltipInput.sendKeys(protractor.Key.ENTER);
}
sideBarPositionStart() {
BrowserVisibility.waitUntilElementIsVisible(this.positionStart);
return this.positionStart.click();
}
sideBarPositionEnd() {
BrowserVisibility.waitUntilElementIsVisible(this.positionEnd);
return this.positionEnd.click();
}
checkSidebarPositionStart() {
return BrowserVisibility.waitUntilElementIsVisible(this.sideBarPositionLeft);
}
checkSidebarPositionEnd() {
return BrowserVisibility.waitUntilElementIsVisible(this.sideBarPositionRight);
}
}

View File

@@ -0,0 +1,5 @@
/*
* Public API Surface of testing
*/
export * from './header.page';

View File

@@ -0,0 +1,6 @@
/*
* Public API Surface of testing
*/
export * from './browser-visibility';
export * from './pages/public-api';

View File

@@ -0,0 +1,169 @@
/*!
* @license
* Copyright 2016 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 { BrowserVisibility } from '../../core/browser-visibility';
import { by, element } from 'protractor';
export class FormFieldsPage {
formContent = element(by.css('adf-form'));
refreshButton = element(by.css('div[class*="form-reload-button"] mat-icon'));
saveButton = element(by.cssContainingText('mat-card-actions[class*="adf-for"] span', 'SAVE'));
valueLocator = by.css('input');
labelLocator = by.css('label');
noFormMessage = element(by.css('span[id*="no-form-message"]'));
completedTaskNoFormMessage = element(by.css('div[id*="completed-form-message"] p'));
attachFormButton = element(by.id('adf-no-form-attach-form-button'));
selectFormDropDownArrow = element.all(by.css('adf-attach-form div[class*="mat-select-arrow"]')).first();
selectFormContent = element(by.css('div[class*="mat-select-panel"]'));
completeButton = element(by.id('adf-form-complete'));
errorMessage = by.css('.adf-error-text-container .adf-error-text');
setFieldValue(locator, field, value) {
let fieldElement: any = element(locator(field));
BrowserVisibility.waitUntilElementIsVisible(fieldElement);
fieldElement.clear().sendKeys(value);
return this;
}
checkWidgetIsVisible(fieldId) {
let fieldElement = element.all(by.css(`adf-form-field div[id='field-${fieldId}-container']`)).first();
BrowserVisibility.waitUntilElementIsVisible(fieldElement);
}
checkWidgetIsHidden(fieldId) {
let hiddenElement = element(by.css(`adf-form-field div[id='field-${fieldId}-container'][hidden]`));
BrowserVisibility.waitUntilElementIsVisible(hiddenElement);
}
getWidget(fieldId) {
let widget = element(by.css(`adf-form-field div[id='field-${fieldId}-container']`));
BrowserVisibility.waitUntilElementIsVisible(widget);
return widget;
}
getFieldValue(fieldId, valueLocatorParam) {
let value = this.getWidget(fieldId).element(valueLocatorParam || this.valueLocator);
BrowserVisibility.waitUntilElementIsVisible(value);
return value.getAttribute('value');
}
getFieldLabel(fieldId, labelLocatorParam) {
let label = this.getWidget(fieldId).all(labelLocatorParam || this.labelLocator).first();
BrowserVisibility.waitUntilElementIsVisible(label);
return label.getText();
}
getFieldErrorMessage(fieldId) {
let error = this.getWidget(fieldId).element(this.errorMessage);
return error.getText();
}
getFieldText(fieldId, labelLocatorParam) {
let label = this.getWidget(fieldId).element(labelLocatorParam || this.labelLocator);
BrowserVisibility.waitUntilElementIsVisible(label);
return label.getText();
}
getFieldPlaceHolder(fieldId, locator = 'input') {
let placeHolderLocator = element(by.css(`${locator}#${fieldId}`)).getAttribute('placeholder');
BrowserVisibility.waitUntilElementIsVisible(placeHolderLocator);
return placeHolderLocator;
}
checkFieldValue(locator, field, val) {
BrowserVisibility.waitUntilElementHasValue(element(locator(field)), val);
return this;
}
refreshForm() {
BrowserVisibility.waitUntilElementIsVisible(this.refreshButton);
this.refreshButton.click();
return this;
}
saveForm() {
BrowserVisibility.waitUntilElementIsVisible(this.saveButton);
BrowserVisibility.waitUntilElementIsClickable(this.saveButton);
this.saveButton.click();
return this;
}
noFormIsDisplayed() {
BrowserVisibility.waitUntilElementIsNotOnPage(this.formContent);
return this;
}
checkFormIsDisplayed() {
BrowserVisibility.waitUntilElementIsVisible(this.formContent);
return this;
}
getNoFormMessage() {
BrowserVisibility.waitUntilElementIsVisible(this.noFormMessage);
return this.noFormMessage.getText();
}
getCompletedTaskNoFormMessage() {
BrowserVisibility.waitUntilElementIsVisible(this.completedTaskNoFormMessage);
return this.completedTaskNoFormMessage.getText();
}
clickOnAttachFormButton() {
BrowserVisibility.waitUntilElementIsVisible(this.attachFormButton);
this.attachFormButton.click();
return this;
}
selectForm(formName) {
BrowserVisibility.waitUntilElementIsVisible(this.selectFormDropDownArrow);
this.selectFormDropDownArrow.click();
BrowserVisibility.waitUntilElementIsVisible(this.selectFormContent);
this.selectFormFromDropDown(formName);
return this;
}
selectFormFromDropDown(formName) {
let formNameElement = element(by.cssContainingText('span', formName));
BrowserVisibility.waitUntilElementIsVisible(formNameElement);
formNameElement.click();
}
checkWidgetIsReadOnlyMode(fieldId) {
let widget = element(by.css(`adf-form-field div[id='field-${fieldId}-container']`));
let widgetReadOnly = widget.element(by.css('div[class*="adf-readonly"]'));
BrowserVisibility.waitUntilElementIsVisible(widgetReadOnly);
return widgetReadOnly;
}
completeForm() {
BrowserVisibility.waitUntilElementIsVisible(this.completeButton);
return this.completeButton.click();
}
setValueInInputById(fieldId, value) {
let input: any = element(by.id(fieldId));
BrowserVisibility.waitUntilElementIsVisible(input);
input.clear().sendKeys(value);
return this;
}
isCompleteFormButtonDisabled() {
BrowserVisibility.waitUntilElementIsVisible(this.completeButton);
return this.completeButton.getAttribute('disabled');
}
}

View File

@@ -0,0 +1,5 @@
/*
* Public API Surface of testing
*/
export * from './form-fields.page';

View File

@@ -0,0 +1,5 @@
/*
* Public API Surface of testing
*/
export * from './pages/public-api';

View File

@@ -0,0 +1,9 @@
import { NgModule } from '@angular/core';
@NgModule({
declarations: [],
imports: [
],
exports: []
})
export class TestingModule { }

View File

@@ -0,0 +1,12 @@
import { TestBed } from '@angular/core/testing';
import { TestingService } from './testing.service';
describe('TestingService', () => {
beforeEach(() => TestBed.configureTestingModule({}));
it('should be created', () => {
const service: TestingService = TestBed.get(TestingService);
expect(service).toBeTruthy();
});
});

View File

@@ -0,0 +1,10 @@
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class TestingService {
constructor() { }
}

View File

@@ -0,0 +1,8 @@
/*
* Public API Surface of testing
*/
export * from './lib/core/public-api';
export * from './lib/content-services/public-api';
export * from './lib/process-services/public-api';
export * from './lib/testing.module';

22
lib/testing/src/test.ts Normal file
View File

@@ -0,0 +1,22 @@
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
import 'core-js/es7/reflect';
import 'zone.js/dist/zone';
import 'zone.js/dist/zone-testing';
import { getTestBed } from '@angular/core/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing';
declare const require: any;
// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(
BrowserDynamicTestingModule,
platformBrowserDynamicTesting()
);
// Then we find all the tests.
const context = require.context('./', true, /\.spec\.ts$/);
// And load the modules.
context.keys().map(context);