@amanat-qa/ui-core 1.0.5 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/dist/baseForm.js +74 -0
  2. package/dist/elements/baseElement.js +443 -0
  3. package/dist/elements/baseElementChildren/button.js +25 -0
  4. package/dist/elements/baseElementChildren/checkbox.js +34 -0
  5. package/dist/elements/baseElementChildren/label.js +25 -0
  6. package/dist/elements/baseElementChildren/radioButton.js +25 -0
  7. package/dist/elements/baseElementChildren/switch.js +34 -0
  8. package/dist/elements/baseElementChildren/textbox.js +25 -0
  9. package/{src → dist}/index.js +3 -1
  10. package/dist/locators/baseLocator.js +29 -0
  11. package/dist/locators/baseLocatorChildren/ATTR.js +25 -0
  12. package/dist/locators/baseLocatorChildren/CSS.js +25 -0
  13. package/dist/locators/baseLocatorChildren/ID.js +25 -0
  14. package/dist/locators/baseLocatorChildren/TAG.js +25 -0
  15. package/dist/locators/baseLocatorChildren/TEXT.js +25 -0
  16. package/dist/locators/baseLocatorChildren/XPATH.js +25 -0
  17. package/package.json +29 -20
  18. package/src/baseForm.js +0 -57
  19. package/src/elements/baseElement.js +0 -361
  20. package/src/elements/baseElementChildren/button.js +0 -5
  21. package/src/elements/baseElementChildren/checkbox.js +0 -9
  22. package/src/elements/baseElementChildren/label.js +0 -5
  23. package/src/elements/baseElementChildren/radioButton.js +0 -5
  24. package/src/elements/baseElementChildren/switch.js +0 -9
  25. package/src/elements/baseElementChildren/textbox.js +0 -5
  26. package/src/locators/baseLocator.js +0 -13
  27. package/src/locators/baseLocatorChildren/ATTR.js +0 -5
  28. package/src/locators/baseLocatorChildren/CSS.js +0 -5
  29. package/src/locators/baseLocatorChildren/ID.js +0 -5
  30. package/src/locators/baseLocatorChildren/TAG.js +0 -5
  31. package/src/locators/baseLocatorChildren/TEXT.js +0 -5
  32. package/src/locators/baseLocatorChildren/XPATH.js +0 -5
@@ -1,361 +0,0 @@
1
- require('cypress-xpath');
2
- const Randomizer = require('@amanat-qa/utils-frontend/randomizer');
3
- const XPATH = require('../locators/baseLocatorChildren/XPATH');
4
-
5
- class BaseElement {
6
- #elementName;
7
-
8
- #elementLocator;
9
-
10
- constructor(elementLocator, elementName) {
11
- this.#elementLocator = elementLocator;
12
- this.#elementName = elementName;
13
- }
14
-
15
- getElement(locator) {
16
- let elementLocator = locator;
17
- if (!elementLocator) elementLocator = this.#elementLocator;
18
- return elementLocator instanceof XPATH
19
- ? cy.xpath(elementLocator.value).first()
20
- : cy.get(elementLocator.value).first();
21
- }
22
-
23
- getElements() {
24
- return this.#elementLocator instanceof XPATH
25
- ? cy.xpath(this.#elementLocator.value)
26
- : cy.get(this.#elementLocator.value);
27
- }
28
-
29
- clickElement() {
30
- cy.logger(`[inf] ▶ click ${this.#elementName}`);
31
- return this.getElement().click();
32
- }
33
-
34
- focusOnElement() {
35
- cy.logger(`[inf] ▶ focus on ${this.#elementName}`);
36
- return this.getElement().focus();
37
- }
38
-
39
- forceClickElement() {
40
- cy.logger(`[inf] ▶ force click ${this.#elementName}`);
41
- return this.getElement().click({ force: true });
42
- }
43
-
44
- doubleClickElement() {
45
- cy.logger(`[inf] ▶ double click ${this.#elementName}`);
46
- this.getElement().dblclick();
47
- }
48
-
49
- multipleClickElement(count) {
50
- cy.logger(`[inf] ▶ click ${this.#elementName} ${count} times`);
51
- this.getElement().clicks(count);
52
- }
53
-
54
- clickElementFromList(index) {
55
- cy.logger(`[inf] ▶ click element from ${this.#elementName}`);
56
- this.getElements()[index].click();
57
- }
58
-
59
- getText() {
60
- cy.logger(`[inf] ▶ get ${this.#elementName} text:`);
61
- this.getElement().then(($el) => cy.logger(`[inf] text contains: "${$el.text()}"`));
62
- return this.getElement().then(($el) => $el.text());
63
- }
64
-
65
- getValue() {
66
- cy.logger(`[inf] ▶ get ${this.#elementName} value:`);
67
- this.getElement().then(($el) => cy.logger(`[inf] value is: "${$el.val()}"`));
68
- return this.getElement().then(($el) => $el.val());
69
- }
70
-
71
- getElementsListText({ propertyName }) {
72
- return this.getElements().then(($el) => Cypress._.map($el, propertyName));
73
- }
74
-
75
- getAttributeValue({ attrName }) {
76
- cy.logger(`[inf] ▶ get ${this.#elementName} attribute "${attrName}" value:`);
77
- return this.getElement().invoke('attr', attrName).then((value) => {
78
- cy.logger(`[inf] attribute value contains: "${value}"`);
79
- return cy.wrap(value);
80
- });
81
- }
82
-
83
- scrollElementToView() {
84
- cy.logger(`[inf] ▶ scroll to ${this.#elementName}`);
85
- this.getElement().scrollIntoView({ offset: { top: -150, left: 0 } });
86
- }
87
-
88
- clearData() {
89
- cy.logger(`[inf] ▶ clear ${this.#elementName}`);
90
- this.getElement().clear();
91
- }
92
-
93
- inputData(data, options = { useCypressRealEvents: false }) {
94
- cy.logger(`[inf] ▶ input ${this.#elementName}`);
95
- if (options.useCypressRealEvents) {
96
- this.getElement().click();
97
- cy.realType(data);
98
- } else {
99
- this.getElement().type(data);
100
- }
101
- }
102
-
103
- forceInputData(data) {
104
- cy.logger(`[inf] ▶ force input ${this.#elementName}`);
105
- this.getElement().type(data, { force: true });
106
- }
107
-
108
- fillInputField(data) {
109
- cy.logger(`[inf] ▶ fill input data into ${this.#elementName}`);
110
- this.getElement().fill(data, { overwrite: false, prepend: true });
111
- }
112
-
113
- enterData(data) {
114
- cy.logger(`[inf] ▶ input ${this.#elementName} and submit`);
115
- this.getElement().type(`${data}{enter}`);
116
- }
117
-
118
- uploadFile(path) {
119
- cy.logger(`[inf] ▶ upload file with ${this.#elementName}`);
120
- this.getElement().selectFile(path, { force: true });
121
- }
122
-
123
- elementIsVisible() {
124
- return this.getElement().isVisible();
125
- }
126
-
127
- elementIsExisting() {
128
- return cy.isExisting(this.#elementLocator.value);
129
- }
130
-
131
- waitElementIsExisting() {
132
- return cy.waitIsExisting(this.#elementLocator.value);
133
- }
134
-
135
- waitElementIsNotExisting() {
136
- return cy.waitIsNotExisting(this.#elementLocator.value);
137
- }
138
-
139
- elementIsDisplayed() {
140
- cy.logger(`[inf] ▶ check ${this.#elementName} is displayed:`);
141
- return this.elementIsExisting().then((isExisting) => {
142
- const notDisplayedLog = `[inf] ${this.#elementName} is not displayed`;
143
- if (isExisting) {
144
- return this.elementIsVisible().then((isVisible) => {
145
- cy.logger(isVisible ? `[inf] ${this.#elementName} is displayed` : notDisplayedLog);
146
- return cy.wrap(isVisible);
147
- });
148
- }
149
-
150
- cy.logger(notDisplayedLog);
151
- return cy.wrap(isExisting);
152
- });
153
- }
154
-
155
- waitElementIsDisplayed() {
156
- cy.logger(`[inf] ▶ wait ${this.#elementName} is displayed:`);
157
- return this.waitElementIsExisting().then((isExisting) => {
158
- const notDisplayedLog = `[inf] ${this.#elementName} is not displayed`;
159
- if (isExisting) {
160
- return this.elementIsVisible().then((isVisible) => {
161
- cy.logger(isVisible ? `[inf] ${this.#elementName} is displayed` : notDisplayedLog);
162
- return cy.wrap(isVisible);
163
- });
164
- }
165
-
166
- cy.logger(notDisplayedLog);
167
- return cy.wrap(isExisting);
168
- });
169
- }
170
-
171
- waitElementIsNotDisplayed() {
172
- cy.logger(`[inf] ▶ wait ${this.#elementName} is not displayed:`);
173
- return this.waitElementIsNotExisting().then((isExisting) => {
174
- const displayedLog = `[inf] ${this.#elementName} is displayed`;
175
- if (!isExisting) {
176
- return this.elementIsVisible().then((isVisible) => {
177
- cy.logger(!isVisible ? `[inf] ${this.#elementName} is not displayed` : displayedLog);
178
- return cy.wrap(isVisible);
179
- });
180
- }
181
-
182
- cy.logger(displayedLog);
183
- return cy.wrap(isExisting);
184
- });
185
- }
186
-
187
- elementIsEnabled() {
188
- cy.logger(`[inf] ▶ check ${this.#elementName} is enabled:`);
189
- return this.getElement().isEnabled().then((isEnabled) => {
190
- cy.logger(
191
- isEnabled
192
- ? `[inf] ${this.#elementName} is enabled`
193
- : `[inf] ${this.#elementName} is not enabled`,
194
- );
195
- return cy.wrap(isEnabled);
196
- });
197
- }
198
-
199
- waitElementIsEnabled() {
200
- cy.logger(`[inf] ▶ wait ${this.#elementName} is enabled:`);
201
- return this.getElement().waitIsEnabled().then((isEnabled) => {
202
- cy.logger(
203
- isEnabled
204
- ? `[inf] ${this.#elementName} is enabled`
205
- : `[inf] ${this.#elementName} is not enabled`,
206
- );
207
- return cy.wrap(isEnabled);
208
- });
209
- }
210
-
211
- waitElementIsNotEnabled() {
212
- cy.logger(`[inf] ▶ wait ${this.#elementName} is not enabled:`);
213
- return this.getElement().waitIsNotEnabled().then((isEnabled) => {
214
- cy.logger(
215
- !isEnabled
216
- ? `[inf] ${this.#elementName} is not enabled`
217
- : `[inf] ${this.#elementName} is enabled`,
218
- );
219
- return cy.wrap(isEnabled);
220
- });
221
- }
222
-
223
- /**
224
- * requires one mandatory argument: dropdownElement.
225
- * options contain optional parameters:
226
- * list of values to choose from,
227
- * count of elements to choose,
228
- * boolean toggler for typing and pressing Enter key
229
- * and exceptions elements sequence:
230
- * @param {BaseElement} dropdownElement
231
- * @param {Object} options
232
- * @param {Promise} options.valuesListPromise
233
- * @param {int} options.count
234
- * @param {boolean} options.typeAndEnter
235
- * @param {BaseElement[]} options.exceptionElementsList
236
- */
237
- chooseRandomElementsFromDropdownByText(dropdownElement, options = {}) {
238
- let valuesListPromise = options.valuesListPromise ?? null;
239
- const count = options.count ?? 1;
240
- const typeAndEnter = options.typeAndEnter ?? false;
241
- const exceptionElementsList = options.exceptionElementsList ?? [];
242
-
243
- this.getElement(this.#elementLocator).click();
244
-
245
- const exceptionsTextList = [];
246
- if (exceptionElementsList.length !== 0) {
247
- exceptionElementsList.forEach((element) => this.getElement(element.#elementLocator)
248
- .then(($el) => exceptionsTextList.push($el.text())));
249
- }
250
-
251
- if (!valuesListPromise) {
252
- valuesListPromise = dropdownElement.getElementsListText({ propertyName: 'innerText' });
253
- }
254
-
255
- valuesListPromise.then((elementsTextList) => {
256
- for (let counter = 0; counter < count; counter += 1) {
257
- cy.logger(`[inf] ▶ click ${dropdownElement.#elementName}`);
258
- cy.logger(`[inf] ▶ get random element from ${this.#elementName}`);
259
- const randomElementText = Randomizer.getRandomElementByText(
260
- elementsTextList,
261
- exceptionsTextList,
262
- );
263
- exceptionsTextList.push(randomElementText);
264
- dropdownElement.chooseElementFromDropdown(randomElementText, typeAndEnter);
265
- }
266
- });
267
- }
268
-
269
- // requires two mandatory arguments:
270
- // inputElementType - is type of clickable element (checkbox/radio),
271
- // parentOfLabelTag - is a tagname of an element on the upper node that nesting input`s label text
272
- clickRandomRadiobuttonsOrCheckboxesByText(
273
- { inputElementType, parentOfLabelTag, randomCount = true },
274
- ...exceptionsElements
275
- ) {
276
- this.getElementsListText({ propertyName: 'innerText' }).then((elementsTextList) => {
277
- let count = elementsTextList.length;
278
- if (randomCount) count = Randomizer.getRandomInteger(elementsTextList.length, 1);
279
- const exceptionsTextList = [];
280
- if (exceptionsElements.length !== 0) {
281
- exceptionsElements.forEach((element) => this.getElement(element.#elementLocator)
282
- .then(($el) => exceptionsTextList.push($el.text())));
283
- }
284
-
285
- for (let counter = 0; counter < count; counter += 1) {
286
- cy.logger(`[inf] ▶ get random element from ${this.#elementName}`);
287
- const randomElementText = Randomizer.getRandomElementByText(
288
- elementsTextList,
289
- exceptionsTextList,
290
- );
291
- exceptionsTextList.push(randomElementText);
292
- cy.logger(`[inf] ▶ click ${randomElementText}`);
293
- cy.contains(parentOfLabelTag, randomElementText)
294
- .find(`input[type=${inputElementType}]`)
295
- .click({ force: true });
296
- }
297
- });
298
- }
299
-
300
- openCalendarAndFlipMonths(rightArrowElement, monthIncrement) {
301
- cy.logger(`[inf] ▶ click ${this.#elementName}`);
302
- this.getElement().clicks(4);
303
- for (let i = 0; i < monthIncrement; i += 1) {
304
- cy.logger(`[inf] ▶ click ${rightArrowElement.#elementName}`);
305
- this.getElement(rightArrowElement.#elementLocator).click({ force: true });
306
- }
307
- }
308
-
309
- clickArrowButtonRandomNumberOfTimes(direction, numberOfElements) {
310
- this.elementIsVisible();
311
- const directionLowerCase = direction.toLowerCase();
312
- const numberOfClicksOnArrowButton = Randomizer.getRandomInteger(numberOfElements - 1);
313
- cy.logger(`[inf] ▶ direction: ${directionLowerCase}, numberOfClicks: ${numberOfClicksOnArrowButton}`);
314
- for (let i = numberOfClicksOnArrowButton; i > 0; i -= 1) {
315
- cy.logger(`[inf] ▶ press ${directionLowerCase} arrow button`);
316
- cy.realPress(`{${directionLowerCase}arrow}`);
317
- }
318
- cy.logger('[inf] ▶ press Enter button');
319
- cy.realPress('Enter');
320
- }
321
-
322
- createListOfElements(dropdownElement) {
323
- const elements = [];
324
- this.getElement(dropdownElement.#elementLocator).click();
325
-
326
- return this.getElement().then((element) => {
327
- elements.push(element.text());
328
-
329
- return this.iterateOverList(elements);
330
- });
331
- }
332
-
333
- iterateOverList(elements) {
334
- this.getElement();
335
- cy.realPress('{downarrow}');
336
-
337
- return this.getElement().then((element) => {
338
- if (element.text() === elements[0]) {
339
- cy.logger(`Number of countries is ${elements.length}`);
340
-
341
- return cy.wrap(elements);
342
- }
343
- elements.push(element.text());
344
-
345
- return this.iterateOverList(elements);
346
- });
347
- }
348
-
349
- chooseElementFromDropdown(text, typeAndEnter) {
350
- if (typeAndEnter) {
351
- cy.logger(`[inf] ▶ type and enter ${text}`);
352
- this.enterData(text);
353
- cy.realPress('{esc}');
354
- } else {
355
- cy.logger(`[inf] ▶ click ${text}`);
356
- this.getElements().contains(new RegExp(`${text}`)).click({ force: true });
357
- }
358
- }
359
- }
360
-
361
- module.exports = BaseElement;
@@ -1,5 +0,0 @@
1
- const BaseElement = require('../baseElement');
2
-
3
- class Button extends BaseElement {}
4
-
5
- module.exports = Button;
@@ -1,9 +0,0 @@
1
- const BaseElement = require('../baseElement');
2
-
3
- class Checkbox extends BaseElement {
4
- isChecked() {
5
- return this.getAttributeValue({ attrName: 'checked' }).then((value) => JSON.parse(value));
6
- }
7
- }
8
-
9
- module.exports = Checkbox;
@@ -1,5 +0,0 @@
1
- const BaseElement = require('../baseElement');
2
-
3
- class Label extends BaseElement {}
4
-
5
- module.exports = Label;
@@ -1,5 +0,0 @@
1
- const BaseElement = require('../baseElement');
2
-
3
- class RadioButton extends BaseElement {}
4
-
5
- module.exports = RadioButton;
@@ -1,9 +0,0 @@
1
- const BaseElement = require('../baseElement');
2
-
3
- class Switch extends BaseElement {
4
- isChecked() {
5
- return this.getAttributeValue({ attrName: 'aria-checked' }).then((value) => JSON.parse(value));
6
- }
7
- }
8
-
9
- module.exports = Switch;
@@ -1,5 +0,0 @@
1
- const BaseElement = require('../baseElement');
2
-
3
- class Textbox extends BaseElement {}
4
-
5
- module.exports = Textbox;
@@ -1,13 +0,0 @@
1
- class BaseLocator {
2
- #value;
3
-
4
- constructor(value) {
5
- this.#value = value;
6
- }
7
-
8
- get value() {
9
- return this.#value;
10
- }
11
- }
12
-
13
- module.exports = BaseLocator;
@@ -1,5 +0,0 @@
1
- const BaseLocator = require('../baseLocator');
2
-
3
- class ATTR extends BaseLocator {}
4
-
5
- module.exports = ATTR;
@@ -1,5 +0,0 @@
1
- const BaseLocator = require('../baseLocator');
2
-
3
- class CSS extends BaseLocator {}
4
-
5
- module.exports = CSS;
@@ -1,5 +0,0 @@
1
- const BaseLocator = require('../baseLocator');
2
-
3
- class ID extends BaseLocator {}
4
-
5
- module.exports = ID;
@@ -1,5 +0,0 @@
1
- const BaseLocator = require('../baseLocator');
2
-
3
- class TAG extends BaseLocator {}
4
-
5
- module.exports = TAG;
@@ -1,5 +0,0 @@
1
- const BaseLocator = require('../baseLocator');
2
-
3
- class TEXT extends BaseLocator {}
4
-
5
- module.exports = TEXT;
@@ -1,5 +0,0 @@
1
- const BaseLocator = require('../baseLocator');
2
-
3
- class XPATH extends BaseLocator {}
4
-
5
- module.exports = XPATH;