-
Notifications
You must be signed in to change notification settings - Fork 261
/
form-fields.ts
245 lines (201 loc) · 9.01 KB
/
form-fields.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
/*!
* @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 { browser, Locator, by, element, ElementFinder } from 'protractor';
import { BrowserVisibility, BrowserActions } from '../../utils/public-api';
import { DropdownPage } from '../material/dropdown.page';
export class FormFields {
formContent = element(by.css('adf-form-renderer'));
refreshButton = element(by.css('div[class*="form-reload-button"] mat-icon'));
saveButton = element(by.cssContainingText('mat-card-actions[class*="adf-for"] span', 'SAVE'));
valueLocator: Locator = by.css('input');
labelLocator: Locator = by.css('label');
noFormMessage = element(by.css('.adf-empty-content__title'));
noFormMessageStandaloneTask = element(by.css('adf-task-standalone #adf-no-form-message'));
noFormTemplate = element(by.css('adf-empty-content'));
completedTaskNoFormMessage = element(by.css('div[id*="completed-form-message"] p'));
completedStandaloneTaskNoFormMessage = element(by.css('adf-task-standalone #adf-completed-form-message'));
attachFormButton = element(by.id('adf-attach-form-attach-button'));
completeButton = element(by.id('adf-form-complete'));
completeNoFormButton = element(by.id('adf-no-form-complete-button'));
cancelButton = element(by.id('adf-no-form-cancel-button'));
errorMessage: Locator = by.css('.adf-error-text-container .adf-error-text');
selectFormDropdown = new DropdownPage(element.all(by.css('.adf-attach-form .mat-select-arrow')).first());
async setFieldValue(locator, field, value: string): Promise<void> {
const fieldElement = element(locator(field));
await BrowserActions.clearSendKeys(fieldElement, value);
}
async checkWidgetIsVisible(fieldId: string): Promise<void> {
const fieldElement = element.all(by.css(`adf-form-field div[id='field-${fieldId}-container']`)).first();
await BrowserVisibility.waitUntilElementIsVisible(fieldElement);
}
async checkWidgetsAreVisible(fieldsId: string[]): Promise<void> {
for (const fieldId of fieldsId) {
await this.checkWidgetIsVisible(fieldId);
}
}
async checkWidgetIsClickable(fieldId: string): Promise<void> {
const fieldElement = element.all(by.css(`adf-form-field div[id='field-${fieldId}-container']`)).first();
await BrowserVisibility.waitUntilElementIsClickable(fieldElement);
}
async checkWidgetIsHidden(fieldId: string): Promise<void> {
const hiddenElement = element(by.css(`adf-form-field div[id='field-${fieldId}-container']`));
await BrowserVisibility.waitUntilElementIsNotVisible(hiddenElement, 6000);
}
getWidget(fieldId: string): ElementFinder {
return element(by.css(`adf-form-field div[id='field-${fieldId}-container']`));
}
async getFieldValue(fieldId: string, valueLocatorParam?: any): Promise<string> {
const valueWidget = await (await this.getWidget(fieldId)).element(valueLocatorParam || this.valueLocator);
await BrowserVisibility.waitUntilElementIsVisible(valueWidget);
return BrowserActions.getInputValue(valueWidget);
}
async getFieldLabel(fieldId: string, labelLocatorParam?: any) {
const label = await (await this.getWidget(fieldId)).all(labelLocatorParam || this.labelLocator).first();
return BrowserActions.getText(label);
}
async getFieldErrorMessage(fieldId: string): Promise<string> {
const error = await this.getWidget(fieldId).element(this.errorMessage);
return BrowserActions.getText(error);
}
async getFieldText(fieldId: string, labelLocatorParam?: any) {
const label = await (await this.getWidget(fieldId)).element(labelLocatorParam || this.labelLocator);
return BrowserActions.getText(label);
}
async getFieldPlaceHolder(fieldId: string, locator = 'input'): Promise<string> {
const placeHolderLocator = element(by.css(`${locator}#${fieldId}`));
await BrowserVisibility.waitUntilElementIsVisible(placeHolderLocator);
return BrowserActions.getAttribute(placeHolderLocator, 'data-placeholder');
}
async checkFieldValue(locator, field, val): Promise<void> {
await BrowserVisibility.waitUntilElementHasValue(element(locator(field)), val);
}
async refreshForm(): Promise<void> {
await BrowserActions.click(this.refreshButton);
await browser.sleep(500);
}
async saveForm(): Promise<void> {
await BrowserActions.click(this.saveButton);
}
async isNoFormTemplateDisplayed(): Promise<boolean> {
try {
await BrowserVisibility.waitUntilElementIsVisible(
this.noFormTemplate
);
return true;
} catch (error) {
return false;
}
}
async noFormIsDisplayed(): Promise<void> {
await BrowserVisibility.waitUntilElementIsNotVisible(this.formContent);
}
async checkFormIsDisplayed(): Promise<void> {
await BrowserVisibility.waitUntilElementIsVisible(this.formContent);
}
async getNoFormMessage(): Promise<string> {
return BrowserActions.getText(this.noFormMessage);
}
async getNoFormMessageStandaloneTask(): Promise<string> {
return BrowserActions.getText(this.noFormMessageStandaloneTask);
}
async getCompletedTaskNoFormMessage(): Promise<string> {
return BrowserActions.getText(this.completedTaskNoFormMessage);
}
async getCompletedStandaloneTaskNoFormMessage(): Promise<string> {
return BrowserActions.getText(this.completedStandaloneTaskNoFormMessage);
}
async isStandaloneTaskNoFormMessageDisplayed(): Promise<boolean> {
try {
await BrowserVisibility.waitUntilElementIsVisible(this.noFormMessageStandaloneTask);
return true;
} catch (error) {
return false;
}
}
async isAttachFormButtonDisplayed(): Promise<boolean> {
try {
await BrowserVisibility.waitUntilElementIsVisible(this.attachFormButton);
return true;
} catch (error) {
return false;
}
}
async clickOnAttachFormButton(): Promise<void> {
await BrowserActions.click(this.attachFormButton);
}
async selectForm(formName: string): Promise<void> {
await this.selectFormDropdown.selectDropdownOption(formName);
}
async selectFormFromDropDown(formName: string): Promise<void> {
const formNameElement = element(by.cssContainingText('span', formName));
await BrowserActions.click(formNameElement);
}
async checkWidgetIsReadOnlyMode(fieldId: string): Promise<ElementFinder> {
const widget = element(by.css(`adf-form-field #field-${fieldId}-container .adf-readonly`));
await BrowserVisibility.waitUntilElementIsVisible(widget);
return widget;
}
async isFormFieldEnabled(formFieldId: string): Promise<boolean> {
return element(by.id(`${formFieldId}`)).isEnabled();
}
async completeForm(): Promise<void> {
await BrowserActions.click(this.completeButton);
}
async completeNoFormTask(): Promise<void> {
await BrowserActions.click(this.completeNoFormButton);
}
async clickCancelButton(): Promise<void> {
await BrowserActions.click(this.cancelButton);
}
async setValueInInputById(fieldId: string, value: string): Promise<void> {
const input = element(by.id(fieldId));
await BrowserActions.clearSendKeys(input, value);
}
async isCompleteButtonDisplayed(): Promise<boolean> {
try {
await BrowserVisibility.waitUntilElementIsVisible(this.completeButton);
return true;
} catch (error) {
return false;
}
}
async isCompleteNoFormButtonDisplayed(): Promise<boolean> {
try {
await BrowserVisibility.waitUntilElementIsVisible(this.completeNoFormButton);
return true;
} catch (error) {
return false;
}
}
async isCompleteFormButtonEnabled(): Promise<boolean> {
return this.completeButton.isEnabled();
}
async isCompleteNoFormButtonEnabled(): Promise<boolean> {
return this.completeNoFormButton.isEnabled();
}
async isCancelButtonDisplayed(): Promise<boolean> {
try {
await BrowserVisibility.waitUntilElementIsVisible(this.cancelButton);
return true;
} catch (error) {
return false;
}
}
async isCancelButtonEnabled(): Promise<boolean> {
return this.cancelButton.isEnabled();
}
}