@amanat-qa/ui-core 1.0.5 → 1.0.6

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.
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+
3
+ function _classPrivateFieldLooseBase(e, t) { if (!{}.hasOwnProperty.call(e, t)) throw new TypeError("attempted to use private field on non-instance"); return e; }
4
+ var id = 0;
5
+ function _classPrivateFieldLooseKey(e) { return "__private_" + id++ + "_" + e; }
6
+ require('cypress-xpath');
7
+ const XPATH = require('./locators/baseLocatorChildren/XPATH');
8
+ var _pageName = /*#__PURE__*/_classPrivateFieldLooseKey("pageName");
9
+ var _pageLocator = /*#__PURE__*/_classPrivateFieldLooseKey("pageLocator");
10
+ class BaseForm {
11
+ constructor(pageLocator, pageName) {
12
+ Object.defineProperty(this, _pageName, {
13
+ writable: true,
14
+ value: void 0
15
+ });
16
+ Object.defineProperty(this, _pageLocator, {
17
+ writable: true,
18
+ value: void 0
19
+ });
20
+ _classPrivateFieldLooseBase(this, _pageLocator)[_pageLocator] = pageLocator;
21
+ _classPrivateFieldLooseBase(this, _pageName)[_pageName] = pageName;
22
+ }
23
+ getUniqueElement() {
24
+ return _classPrivateFieldLooseBase(this, _pageLocator)[_pageLocator] instanceof XPATH ? cy.xpath(_classPrivateFieldLooseBase(this, _pageLocator)[_pageLocator].value).first() : cy.get(_classPrivateFieldLooseBase(this, _pageLocator)[_pageLocator].value).first();
25
+ }
26
+ pageIsVisible() {
27
+ return this.getUniqueElement().isVisible();
28
+ }
29
+ waitPageIsExisting() {
30
+ return cy.waitIsExisting(_classPrivateFieldLooseBase(this, _pageLocator)[_pageLocator].value);
31
+ }
32
+ pageIsDisplayed() {
33
+ cy.logger(`[inf] ▶ check ${_classPrivateFieldLooseBase(this, _pageName)[_pageName]} is displayed:`);
34
+ return this.waitPageIsExisting().then(isExisting => {
35
+ const notDisplayedLog = `[inf] ${_classPrivateFieldLooseBase(this, _pageName)[_pageName]} is not displayed`;
36
+ if (isExisting) {
37
+ return this.pageIsVisible().then(isVisible => {
38
+ cy.logger(isVisible ? `[inf] ${_classPrivateFieldLooseBase(this, _pageName)[_pageName]} is displayed` : notDisplayedLog);
39
+ return cy.wrap(isVisible);
40
+ });
41
+ }
42
+ cy.logger(notDisplayedLog);
43
+ return cy.wrap(isExisting);
44
+ });
45
+ }
46
+ pageIsEnabled() {
47
+ cy.logger(`[inf] ▶ check ${_classPrivateFieldLooseBase(this, _pageName)[_pageName]} is enabled:`);
48
+ return this.getUniqueElement().waitIsEnabled().then(isEnabled => {
49
+ cy.logger(isEnabled ? `[inf] ${_classPrivateFieldLooseBase(this, _pageName)[_pageName]} is enabled` : `[inf] ${_classPrivateFieldLooseBase(this, _pageName)[_pageName]} is not enabled`);
50
+ return cy.wrap(isEnabled);
51
+ });
52
+ }
53
+ }
54
+ module.exports = BaseForm;
@@ -0,0 +1,328 @@
1
+ "use strict";
2
+
3
+ function _classPrivateFieldLooseBase(e, t) { if (!{}.hasOwnProperty.call(e, t)) throw new TypeError("attempted to use private field on non-instance"); return e; }
4
+ var id = 0;
5
+ function _classPrivateFieldLooseKey(e) { return "__private_" + id++ + "_" + e; }
6
+ require('cypress-xpath');
7
+ const Randomizer = require('@amanat-qa/utils-frontend/randomizer');
8
+ const XPATH = require('../locators/baseLocatorChildren/XPATH');
9
+ var _elementName = /*#__PURE__*/_classPrivateFieldLooseKey("elementName");
10
+ var _elementLocator = /*#__PURE__*/_classPrivateFieldLooseKey("elementLocator");
11
+ class BaseElement {
12
+ constructor(elementLocator, elementName) {
13
+ Object.defineProperty(this, _elementName, {
14
+ writable: true,
15
+ value: void 0
16
+ });
17
+ Object.defineProperty(this, _elementLocator, {
18
+ writable: true,
19
+ value: void 0
20
+ });
21
+ _classPrivateFieldLooseBase(this, _elementLocator)[_elementLocator] = elementLocator;
22
+ _classPrivateFieldLooseBase(this, _elementName)[_elementName] = elementName;
23
+ }
24
+ getElement(locator) {
25
+ let elementLocator = locator;
26
+ if (!elementLocator) elementLocator = _classPrivateFieldLooseBase(this, _elementLocator)[_elementLocator];
27
+ return elementLocator instanceof XPATH ? cy.xpath(elementLocator.value).first() : cy.get(elementLocator.value).first();
28
+ }
29
+ getElements() {
30
+ return _classPrivateFieldLooseBase(this, _elementLocator)[_elementLocator] instanceof XPATH ? cy.xpath(_classPrivateFieldLooseBase(this, _elementLocator)[_elementLocator].value) : cy.get(_classPrivateFieldLooseBase(this, _elementLocator)[_elementLocator].value);
31
+ }
32
+ clickElement() {
33
+ cy.logger(`[inf] ▶ click ${_classPrivateFieldLooseBase(this, _elementName)[_elementName]}`);
34
+ return this.getElement().click();
35
+ }
36
+ focusOnElement() {
37
+ cy.logger(`[inf] ▶ focus on ${_classPrivateFieldLooseBase(this, _elementName)[_elementName]}`);
38
+ return this.getElement().focus();
39
+ }
40
+ forceClickElement() {
41
+ cy.logger(`[inf] ▶ force click ${_classPrivateFieldLooseBase(this, _elementName)[_elementName]}`);
42
+ return this.getElement().click({
43
+ force: true
44
+ });
45
+ }
46
+ doubleClickElement() {
47
+ cy.logger(`[inf] ▶ double click ${_classPrivateFieldLooseBase(this, _elementName)[_elementName]}`);
48
+ this.getElement().dblclick();
49
+ }
50
+ multipleClickElement(count) {
51
+ cy.logger(`[inf] ▶ click ${_classPrivateFieldLooseBase(this, _elementName)[_elementName]} ${count} times`);
52
+ this.getElement().clicks(count);
53
+ }
54
+ clickElementFromList(index) {
55
+ cy.logger(`[inf] ▶ click element from ${_classPrivateFieldLooseBase(this, _elementName)[_elementName]}`);
56
+ this.getElements()[index].click();
57
+ }
58
+ getText() {
59
+ cy.logger(`[inf] ▶ get ${_classPrivateFieldLooseBase(this, _elementName)[_elementName]} text:`);
60
+ this.getElement().then($el => cy.logger(`[inf] text contains: "${$el.text()}"`));
61
+ return this.getElement().then($el => $el.text());
62
+ }
63
+ getValue() {
64
+ cy.logger(`[inf] ▶ get ${_classPrivateFieldLooseBase(this, _elementName)[_elementName]} value:`);
65
+ this.getElement().then($el => cy.logger(`[inf] value is: "${$el.val()}"`));
66
+ return this.getElement().then($el => $el.val());
67
+ }
68
+ getElementsListText({
69
+ propertyName
70
+ }) {
71
+ return this.getElements().then($el => Cypress._.map($el, propertyName));
72
+ }
73
+ getAttributeValue({
74
+ attrName
75
+ }) {
76
+ cy.logger(`[inf] ▶ get ${_classPrivateFieldLooseBase(this, _elementName)[_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
+ scrollElementToView() {
83
+ cy.logger(`[inf] ▶ scroll to ${_classPrivateFieldLooseBase(this, _elementName)[_elementName]}`);
84
+ this.getElement().scrollIntoView({
85
+ offset: {
86
+ top: -150,
87
+ left: 0
88
+ }
89
+ });
90
+ }
91
+ clearData() {
92
+ cy.logger(`[inf] ▶ clear ${_classPrivateFieldLooseBase(this, _elementName)[_elementName]}`);
93
+ this.getElement().clear();
94
+ }
95
+ inputData(data, options = {
96
+ useCypressRealEvents: false
97
+ }) {
98
+ cy.logger(`[inf] ▶ input ${_classPrivateFieldLooseBase(this, _elementName)[_elementName]}`);
99
+ if (options.useCypressRealEvents) {
100
+ this.getElement().click();
101
+ cy.realType(data);
102
+ } else {
103
+ this.getElement().type(data);
104
+ }
105
+ }
106
+ forceInputData(data) {
107
+ cy.logger(`[inf] ▶ force input ${_classPrivateFieldLooseBase(this, _elementName)[_elementName]}`);
108
+ this.getElement().type(data, {
109
+ force: true
110
+ });
111
+ }
112
+ fillInputField(data) {
113
+ cy.logger(`[inf] ▶ fill input data into ${_classPrivateFieldLooseBase(this, _elementName)[_elementName]}`);
114
+ this.getElement().fill(data, {
115
+ overwrite: false,
116
+ prepend: true
117
+ });
118
+ }
119
+ enterData(data) {
120
+ cy.logger(`[inf] ▶ input ${_classPrivateFieldLooseBase(this, _elementName)[_elementName]} and submit`);
121
+ this.getElement().type(`${data}{enter}`);
122
+ }
123
+ uploadFile(path) {
124
+ cy.logger(`[inf] ▶ upload file with ${_classPrivateFieldLooseBase(this, _elementName)[_elementName]}`);
125
+ this.getElement().selectFile(path, {
126
+ force: true
127
+ });
128
+ }
129
+ elementIsVisible() {
130
+ return this.getElement().isVisible();
131
+ }
132
+ elementIsExisting() {
133
+ return cy.isExisting(_classPrivateFieldLooseBase(this, _elementLocator)[_elementLocator].value);
134
+ }
135
+ waitElementIsExisting() {
136
+ return cy.waitIsExisting(_classPrivateFieldLooseBase(this, _elementLocator)[_elementLocator].value);
137
+ }
138
+ waitElementIsNotExisting() {
139
+ return cy.waitIsNotExisting(_classPrivateFieldLooseBase(this, _elementLocator)[_elementLocator].value);
140
+ }
141
+ elementIsDisplayed() {
142
+ cy.logger(`[inf] ▶ check ${_classPrivateFieldLooseBase(this, _elementName)[_elementName]} is displayed:`);
143
+ return this.elementIsExisting().then(isExisting => {
144
+ const notDisplayedLog = `[inf] ${_classPrivateFieldLooseBase(this, _elementName)[_elementName]} is not displayed`;
145
+ if (isExisting) {
146
+ return this.elementIsVisible().then(isVisible => {
147
+ cy.logger(isVisible ? `[inf] ${_classPrivateFieldLooseBase(this, _elementName)[_elementName]} is displayed` : notDisplayedLog);
148
+ return cy.wrap(isVisible);
149
+ });
150
+ }
151
+ cy.logger(notDisplayedLog);
152
+ return cy.wrap(isExisting);
153
+ });
154
+ }
155
+ waitElementIsDisplayed() {
156
+ cy.logger(`[inf] ▶ wait ${_classPrivateFieldLooseBase(this, _elementName)[_elementName]} is displayed:`);
157
+ return this.waitElementIsExisting().then(isExisting => {
158
+ const notDisplayedLog = `[inf] ${_classPrivateFieldLooseBase(this, _elementName)[_elementName]} is not displayed`;
159
+ if (isExisting) {
160
+ return this.elementIsVisible().then(isVisible => {
161
+ cy.logger(isVisible ? `[inf] ${_classPrivateFieldLooseBase(this, _elementName)[_elementName]} is displayed` : notDisplayedLog);
162
+ return cy.wrap(isVisible);
163
+ });
164
+ }
165
+ cy.logger(notDisplayedLog);
166
+ return cy.wrap(isExisting);
167
+ });
168
+ }
169
+ waitElementIsNotDisplayed() {
170
+ cy.logger(`[inf] ▶ wait ${_classPrivateFieldLooseBase(this, _elementName)[_elementName]} is not displayed:`);
171
+ return this.waitElementIsNotExisting().then(isExisting => {
172
+ const displayedLog = `[inf] ${_classPrivateFieldLooseBase(this, _elementName)[_elementName]} is displayed`;
173
+ if (!isExisting) {
174
+ return this.elementIsVisible().then(isVisible => {
175
+ cy.logger(!isVisible ? `[inf] ${_classPrivateFieldLooseBase(this, _elementName)[_elementName]} is not displayed` : displayedLog);
176
+ return cy.wrap(isVisible);
177
+ });
178
+ }
179
+ cy.logger(displayedLog);
180
+ return cy.wrap(isExisting);
181
+ });
182
+ }
183
+ elementIsEnabled() {
184
+ cy.logger(`[inf] ▶ check ${_classPrivateFieldLooseBase(this, _elementName)[_elementName]} is enabled:`);
185
+ return this.getElement().isEnabled().then(isEnabled => {
186
+ cy.logger(isEnabled ? `[inf] ${_classPrivateFieldLooseBase(this, _elementName)[_elementName]} is enabled` : `[inf] ${_classPrivateFieldLooseBase(this, _elementName)[_elementName]} is not enabled`);
187
+ return cy.wrap(isEnabled);
188
+ });
189
+ }
190
+ waitElementIsEnabled() {
191
+ cy.logger(`[inf] ▶ wait ${_classPrivateFieldLooseBase(this, _elementName)[_elementName]} is enabled:`);
192
+ return this.getElement().waitIsEnabled().then(isEnabled => {
193
+ cy.logger(isEnabled ? `[inf] ${_classPrivateFieldLooseBase(this, _elementName)[_elementName]} is enabled` : `[inf] ${_classPrivateFieldLooseBase(this, _elementName)[_elementName]} is not enabled`);
194
+ return cy.wrap(isEnabled);
195
+ });
196
+ }
197
+ waitElementIsNotEnabled() {
198
+ cy.logger(`[inf] ▶ wait ${_classPrivateFieldLooseBase(this, _elementName)[_elementName]} is not enabled:`);
199
+ return this.getElement().waitIsNotEnabled().then(isEnabled => {
200
+ cy.logger(!isEnabled ? `[inf] ${_classPrivateFieldLooseBase(this, _elementName)[_elementName]} is not enabled` : `[inf] ${_classPrivateFieldLooseBase(this, _elementName)[_elementName]} is enabled`);
201
+ return cy.wrap(isEnabled);
202
+ });
203
+ }
204
+
205
+ /**
206
+ * requires one mandatory argument: dropdownElement.
207
+ * options contain optional parameters:
208
+ * list of values to choose from,
209
+ * count of elements to choose,
210
+ * boolean toggler for typing and pressing Enter key
211
+ * and exceptions elements sequence:
212
+ * @param {BaseElement} dropdownElement
213
+ * @param {Object} options
214
+ * @param {Promise} options.valuesListPromise
215
+ * @param {int} options.count
216
+ * @param {boolean} options.typeAndEnter
217
+ * @param {BaseElement[]} options.exceptionElementsList
218
+ */
219
+ chooseRandomElementsFromDropdownByText(dropdownElement, options = {}) {
220
+ let valuesListPromise = options.valuesListPromise ?? null;
221
+ const count = options.count ?? 1;
222
+ const typeAndEnter = options.typeAndEnter ?? false;
223
+ const exceptionElementsList = options.exceptionElementsList ?? [];
224
+ this.getElement(_classPrivateFieldLooseBase(this, _elementLocator)[_elementLocator]).click();
225
+ const exceptionsTextList = [];
226
+ if (exceptionElementsList.length !== 0) {
227
+ exceptionElementsList.forEach(element => this.getElement(_classPrivateFieldLooseBase(element, _elementLocator)[_elementLocator]).then($el => exceptionsTextList.push($el.text())));
228
+ }
229
+ if (!valuesListPromise) {
230
+ valuesListPromise = dropdownElement.getElementsListText({
231
+ propertyName: 'innerText'
232
+ });
233
+ }
234
+ valuesListPromise.then(elementsTextList => {
235
+ for (let counter = 0; counter < count; counter += 1) {
236
+ cy.logger(`[inf] ▶ click ${_classPrivateFieldLooseBase(dropdownElement, _elementName)[_elementName]}`);
237
+ cy.logger(`[inf] ▶ get random element from ${_classPrivateFieldLooseBase(this, _elementName)[_elementName]}`);
238
+ const randomElementText = Randomizer.getRandomElementByText(elementsTextList, exceptionsTextList);
239
+ exceptionsTextList.push(randomElementText);
240
+ dropdownElement.chooseElementFromDropdown(randomElementText, typeAndEnter);
241
+ }
242
+ });
243
+ }
244
+
245
+ // requires two mandatory arguments:
246
+ // inputElementType - is type of clickable element (checkbox/radio),
247
+ // parentOfLabelTag - is a tagname of an element on the upper node that nesting input`s label text
248
+ clickRandomRadiobuttonsOrCheckboxesByText({
249
+ inputElementType,
250
+ parentOfLabelTag,
251
+ randomCount = true
252
+ }, ...exceptionsElements) {
253
+ this.getElementsListText({
254
+ propertyName: 'innerText'
255
+ }).then(elementsTextList => {
256
+ let count = elementsTextList.length;
257
+ if (randomCount) count = Randomizer.getRandomInteger(elementsTextList.length, 1);
258
+ const exceptionsTextList = [];
259
+ if (exceptionsElements.length !== 0) {
260
+ exceptionsElements.forEach(element => this.getElement(_classPrivateFieldLooseBase(element, _elementLocator)[_elementLocator]).then($el => exceptionsTextList.push($el.text())));
261
+ }
262
+ for (let counter = 0; counter < count; counter += 1) {
263
+ cy.logger(`[inf] ▶ get random element from ${_classPrivateFieldLooseBase(this, _elementName)[_elementName]}`);
264
+ const randomElementText = Randomizer.getRandomElementByText(elementsTextList, exceptionsTextList);
265
+ exceptionsTextList.push(randomElementText);
266
+ cy.logger(`[inf] ▶ click ${randomElementText}`);
267
+ cy.contains(parentOfLabelTag, randomElementText).find(`input[type=${inputElementType}]`).click({
268
+ force: true
269
+ });
270
+ }
271
+ });
272
+ }
273
+ openCalendarAndFlipMonths(rightArrowElement, monthIncrement) {
274
+ cy.logger(`[inf] ▶ click ${_classPrivateFieldLooseBase(this, _elementName)[_elementName]}`);
275
+ this.getElement().clicks(4);
276
+ for (let i = 0; i < monthIncrement; i += 1) {
277
+ cy.logger(`[inf] ▶ click ${_classPrivateFieldLooseBase(rightArrowElement, _elementName)[_elementName]}`);
278
+ this.getElement(_classPrivateFieldLooseBase(rightArrowElement, _elementLocator)[_elementLocator]).click({
279
+ force: true
280
+ });
281
+ }
282
+ }
283
+ clickArrowButtonRandomNumberOfTimes(direction, numberOfElements) {
284
+ this.elementIsVisible();
285
+ const directionLowerCase = direction.toLowerCase();
286
+ const numberOfClicksOnArrowButton = Randomizer.getRandomInteger(numberOfElements - 1);
287
+ cy.logger(`[inf] ▶ direction: ${directionLowerCase}, numberOfClicks: ${numberOfClicksOnArrowButton}`);
288
+ for (let i = numberOfClicksOnArrowButton; i > 0; i -= 1) {
289
+ cy.logger(`[inf] ▶ press ${directionLowerCase} arrow button`);
290
+ cy.realPress(`{${directionLowerCase}arrow}`);
291
+ }
292
+ cy.logger('[inf] ▶ press Enter button');
293
+ cy.realPress('Enter');
294
+ }
295
+ createListOfElements(dropdownElement) {
296
+ const elements = [];
297
+ this.getElement(_classPrivateFieldLooseBase(dropdownElement, _elementLocator)[_elementLocator]).click();
298
+ return this.getElement().then(element => {
299
+ elements.push(element.text());
300
+ return this.iterateOverList(elements);
301
+ });
302
+ }
303
+ iterateOverList(elements) {
304
+ this.getElement();
305
+ cy.realPress('{downarrow}');
306
+ return this.getElement().then(element => {
307
+ if (element.text() === elements[0]) {
308
+ cy.logger(`Number of countries is ${elements.length}`);
309
+ return cy.wrap(elements);
310
+ }
311
+ elements.push(element.text());
312
+ return this.iterateOverList(elements);
313
+ });
314
+ }
315
+ chooseElementFromDropdown(text, typeAndEnter) {
316
+ if (typeAndEnter) {
317
+ cy.logger(`[inf] ▶ type and enter ${text}`);
318
+ this.enterData(text);
319
+ cy.realPress('{esc}');
320
+ } else {
321
+ cy.logger(`[inf] ▶ click ${text}`);
322
+ this.getElements().contains(new RegExp(`${text}`)).click({
323
+ force: true
324
+ });
325
+ }
326
+ }
327
+ }
328
+ module.exports = BaseElement;
@@ -1,5 +1,5 @@
1
- const BaseElement = require('../baseElement');
1
+ "use strict";
2
2
 
3
+ const BaseElement = require('../baseElement');
3
4
  class Button extends BaseElement {}
4
-
5
- module.exports = Button;
5
+ module.exports = Button;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ const BaseElement = require('../baseElement');
4
+ class Checkbox extends BaseElement {
5
+ isChecked() {
6
+ return this.getAttributeValue({
7
+ attrName: 'checked'
8
+ }).then(value => JSON.parse(value));
9
+ }
10
+ }
11
+ module.exports = Checkbox;
@@ -1,5 +1,5 @@
1
- const BaseElement = require('../baseElement');
1
+ "use strict";
2
2
 
3
+ const BaseElement = require('../baseElement');
3
4
  class Label extends BaseElement {}
4
-
5
- module.exports = Label;
5
+ module.exports = Label;
@@ -1,5 +1,5 @@
1
- const BaseElement = require('../baseElement');
1
+ "use strict";
2
2
 
3
+ const BaseElement = require('../baseElement');
3
4
  class RadioButton extends BaseElement {}
4
-
5
- module.exports = RadioButton;
5
+ module.exports = RadioButton;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ const BaseElement = require('../baseElement');
4
+ class Switch extends BaseElement {
5
+ isChecked() {
6
+ return this.getAttributeValue({
7
+ attrName: 'aria-checked'
8
+ }).then(value => JSON.parse(value));
9
+ }
10
+ }
11
+ module.exports = Switch;
@@ -1,5 +1,5 @@
1
- const BaseElement = require('../baseElement');
1
+ "use strict";
2
2
 
3
+ const BaseElement = require('../baseElement');
3
4
  class Textbox extends BaseElement {}
4
-
5
- module.exports = Textbox;
5
+ module.exports = Textbox;
@@ -1,3 +1,5 @@
1
+ "use strict";
2
+
1
3
  // Auto-generated file
2
4
 
3
5
  exports.BaseForm = require('./baseForm');
@@ -14,4 +16,4 @@ exports.CSS = require('./locators/baseLocatorChildren/CSS');
14
16
  exports.ID = require('./locators/baseLocatorChildren/ID');
15
17
  exports.TAG = require('./locators/baseLocatorChildren/TAG');
16
18
  exports.TEXT = require('./locators/baseLocatorChildren/TEXT');
17
- exports.XPATH = require('./locators/baseLocatorChildren/XPATH');
19
+ exports.XPATH = require('./locators/baseLocatorChildren/XPATH');
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ function _classPrivateFieldLooseBase(e, t) { if (!{}.hasOwnProperty.call(e, t)) throw new TypeError("attempted to use private field on non-instance"); return e; }
4
+ var id = 0;
5
+ function _classPrivateFieldLooseKey(e) { return "__private_" + id++ + "_" + e; }
6
+ var _value = /*#__PURE__*/_classPrivateFieldLooseKey("value");
7
+ class BaseLocator {
8
+ constructor(value) {
9
+ Object.defineProperty(this, _value, {
10
+ writable: true,
11
+ value: void 0
12
+ });
13
+ _classPrivateFieldLooseBase(this, _value)[_value] = value;
14
+ }
15
+ get value() {
16
+ return _classPrivateFieldLooseBase(this, _value)[_value];
17
+ }
18
+ }
19
+ module.exports = BaseLocator;
@@ -1,5 +1,5 @@
1
- const BaseLocator = require('../baseLocator');
1
+ "use strict";
2
2
 
3
+ const BaseLocator = require('../baseLocator');
3
4
  class ATTR extends BaseLocator {}
4
-
5
- module.exports = ATTR;
5
+ module.exports = ATTR;
@@ -1,5 +1,5 @@
1
- const BaseLocator = require('../baseLocator');
1
+ "use strict";
2
2
 
3
+ const BaseLocator = require('../baseLocator');
3
4
  class CSS extends BaseLocator {}
4
-
5
- module.exports = CSS;
5
+ module.exports = CSS;
@@ -1,5 +1,5 @@
1
- const BaseLocator = require('../baseLocator');
1
+ "use strict";
2
2
 
3
+ const BaseLocator = require('../baseLocator');
3
4
  class ID extends BaseLocator {}
4
-
5
- module.exports = ID;
5
+ module.exports = ID;
@@ -1,5 +1,5 @@
1
- const BaseLocator = require('../baseLocator');
1
+ "use strict";
2
2
 
3
+ const BaseLocator = require('../baseLocator');
3
4
  class TAG extends BaseLocator {}
4
-
5
- module.exports = TAG;
5
+ module.exports = TAG;
@@ -1,5 +1,5 @@
1
- const BaseLocator = require('../baseLocator');
1
+ "use strict";
2
2
 
3
+ const BaseLocator = require('../baseLocator');
3
4
  class TEXT extends BaseLocator {}
4
-
5
- module.exports = TEXT;
5
+ module.exports = TEXT;
@@ -1,5 +1,5 @@
1
- const BaseLocator = require('../baseLocator');
1
+ "use strict";
2
2
 
3
+ const BaseLocator = require('../baseLocator');
3
4
  class XPATH extends BaseLocator {}
4
-
5
- module.exports = XPATH;
5
+ module.exports = XPATH;
package/package.json CHANGED
@@ -1,36 +1,45 @@
1
1
  {
2
2
  "name": "@amanat-qa/ui-core",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
7
  "type": "commonjs",
8
8
  "files": [
9
- "src"
9
+ "dist"
10
10
  ],
11
11
  "keywords": [],
12
12
  "license": "MIT",
13
- "main": "./src/index.js",
13
+ "main": "./dist/index.js",
14
14
  "exports": {
15
- ".": "./src/index.js",
16
- "./baseForm": "./src/baseForm.js",
17
- "./baseElement": "./src/elements/baseElement.js",
18
- "./button": "./src/elements/baseElementChildren/button.js",
19
- "./checkbox": "./src/elements/baseElementChildren/checkbox.js",
20
- "./label": "./src/elements/baseElementChildren/label.js",
21
- "./radioButton": "./src/elements/baseElementChildren/radioButton.js",
22
- "./switch": "./src/elements/baseElementChildren/switch.js",
23
- "./textbox": "./src/elements/baseElementChildren/textbox.js",
24
- "./baseLocator": "./src/locators/baseLocator.js",
25
- "./ATTR": "./src/locators/baseLocatorChildren/ATTR.js",
26
- "./CSS": "./src/locators/baseLocatorChildren/CSS.js",
27
- "./ID": "./src/locators/baseLocatorChildren/ID.js",
28
- "./TAG": "./src/locators/baseLocatorChildren/TAG.js",
29
- "./TEXT": "./src/locators/baseLocatorChildren/TEXT.js",
30
- "./XPATH": "./src/locators/baseLocatorChildren/XPATH.js"
15
+ ".": "./dist/index.js",
16
+ "./baseForm": "./dist/baseForm.js",
17
+ "./baseElement": "./dist/elements/baseElement.js",
18
+ "./button": "./dist/elements/baseElementChildren/button.js",
19
+ "./checkbox": "./dist/elements/baseElementChildren/checkbox.js",
20
+ "./label": "./dist/elements/baseElementChildren/label.js",
21
+ "./radioButton": "./dist/elements/baseElementChildren/radioButton.js",
22
+ "./switch": "./dist/elements/baseElementChildren/switch.js",
23
+ "./textbox": "./dist/elements/baseElementChildren/textbox.js",
24
+ "./baseLocator": "./dist/locators/baseLocator.js",
25
+ "./ATTR": "./dist/locators/baseLocatorChildren/ATTR.js",
26
+ "./CSS": "./dist/locators/baseLocatorChildren/CSS.js",
27
+ "./ID": "./dist/locators/baseLocatorChildren/ID.js",
28
+ "./TAG": "./dist/locators/baseLocatorChildren/TAG.js",
29
+ "./TEXT": "./dist/locators/baseLocatorChildren/TEXT.js",
30
+ "./XPATH": "./dist/locators/baseLocatorChildren/XPATH.js"
31
+ },
32
+ "scripts": {
33
+ "build": "babel src --out-dir dist --extensions .js",
34
+ "prepare": "npm run build"
31
35
  },
32
36
  "dependencies": {
33
- "@amanat-qa/utils-frontend": "1.0.2",
37
+ "@amanat-qa/utils-frontend": "1.0.7",
34
38
  "cypress-xpath": "*"
39
+ },
40
+ "devDependencies": {
41
+ "@babel/plugin-transform-class-properties": "^7.27.1",
42
+ "@babel/plugin-transform-private-methods": "^7.27.1",
43
+ "@babel/plugin-transform-private-property-in-object": "^7.27.1"
35
44
  }
36
45
  }
package/src/baseForm.js DELETED
@@ -1,57 +0,0 @@
1
- require('cypress-xpath');
2
- const XPATH = require('./locators/baseLocatorChildren/XPATH');
3
-
4
- class BaseForm {
5
- #pageName;
6
-
7
- #pageLocator;
8
-
9
- constructor(pageLocator, pageName) {
10
- this.#pageLocator = pageLocator;
11
- this.#pageName = pageName;
12
- }
13
-
14
- getUniqueElement() {
15
- return this.#pageLocator instanceof XPATH
16
- ? cy.xpath(this.#pageLocator.value).first()
17
- : cy.get(this.#pageLocator.value).first();
18
- }
19
-
20
- pageIsVisible() {
21
- return this.getUniqueElement().isVisible();
22
- }
23
-
24
- waitPageIsExisting() {
25
- return cy.waitIsExisting(this.#pageLocator.value);
26
- }
27
-
28
- pageIsDisplayed() {
29
- cy.logger(`[inf] ▶ check ${this.#pageName} is displayed:`);
30
- return this.waitPageIsExisting().then((isExisting) => {
31
- const notDisplayedLog = `[inf] ${this.#pageName} is not displayed`;
32
- if (isExisting) {
33
- return this.pageIsVisible().then((isVisible) => {
34
- cy.logger(isVisible ? `[inf] ${this.#pageName} is displayed` : notDisplayedLog);
35
- return cy.wrap(isVisible);
36
- });
37
- }
38
-
39
- cy.logger(notDisplayedLog);
40
- return cy.wrap(isExisting);
41
- });
42
- }
43
-
44
- pageIsEnabled() {
45
- cy.logger(`[inf] ▶ check ${this.#pageName} is enabled:`);
46
- return this.getUniqueElement().waitIsEnabled().then((isEnabled) => {
47
- cy.logger(
48
- isEnabled
49
- ? `[inf] ${this.#pageName} is enabled`
50
- : `[inf] ${this.#pageName} is not enabled`,
51
- );
52
- return cy.wrap(isEnabled);
53
- });
54
- }
55
- }
56
-
57
- module.exports = BaseForm;
@@ -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,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,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,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;