codeceptjs 3.5.3 → 3.5.4-beta.1

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.
@@ -1,213 +0,0 @@
1
- if (!window.codeceptjs) {
2
- /**
3
- * @alias CodeceptJS.browserCodecept
4
- * @namespace
5
- */
6
- const codeceptjs = {};
7
-
8
- /**
9
- * all found elements are stored here for reuse
10
- * @inner
11
- * @type {Node[]}
12
- */
13
- codeceptjs.elements = [];
14
-
15
- /**
16
- * global context changer
17
- * @inner
18
- * @type {?Node}
19
- */
20
- codeceptjs.within = null;
21
-
22
- // save
23
- const storeElement = function (el) {
24
- if (!el) return;
25
- return codeceptjs.elements.push(el) - 1; // return index
26
- };
27
-
28
- const storeElements = function (els) {
29
- return els.map(el => storeElement(el));
30
- };
31
-
32
- /**
33
- * finders
34
- * @param {number} id
35
- * @return {Node}
36
- */
37
- codeceptjs.fetchElement = function (id) {
38
- if (!this.elements[id]) throw new Error(`Element (${id}) is not accessible`);
39
- return this.elements[id];
40
- };
41
-
42
- /**
43
- * @param {string} by
44
- * @param {CodeceptJS.ILocator} locator
45
- * @param {*} [contextEl]
46
- * @return {number[]}
47
- */
48
- codeceptjs.findAndStoreElements = function (by, locator, contextEl) {
49
- return storeElements(this.findElements(by, locator, contextEl));
50
- };
51
-
52
- /**
53
- * @param {string} by
54
- * @param {CodeceptJS.ILocator} locator
55
- * @param {*} [contextEl]
56
- * @return {number | undefined}
57
- */
58
- codeceptjs.findAndStoreElement = function (by, locator, contextEl) {
59
- return storeElement(this.findElement(by, locator, contextEl));
60
- };
61
-
62
- /**
63
- * @param {string} by
64
- * @param {CodeceptJS.ILocator} locator
65
- */
66
- codeceptjs.setWithin = function (by, locator) {
67
- this.within = this.findElement(by, locator);
68
- };
69
-
70
- /**
71
- * @param {string} by
72
- * @param {CodeceptJS.ILocator} locator
73
- * @param {*} [contextEl]
74
- * @return {Node[]}
75
- */
76
- codeceptjs.findElements = function (by, locator, contextEl) {
77
- let context;
78
- if (typeof contextEl !== 'number') {
79
- context = this.within || document;
80
- } else {
81
- context = this.fetchElement(contextEl);
82
- }
83
-
84
- if (by === 'name') {
85
- by = 'css';
86
- locator = `*[name="${locator}"]`;
87
- }
88
- if (by === 'id') {
89
- by = 'css';
90
- locator = `#${locator}`;
91
- }
92
-
93
- if (by === 'css') {
94
- const found = context.querySelectorAll(locator);
95
- const res = [];
96
- for (let i = 0; i < found.length; i++) {
97
- res.push(found[i]);
98
- }
99
- return res;
100
- }
101
-
102
- if (by === 'xpath') {
103
- const found = document.evaluate(locator, context, null, 5, null);
104
- const res = [];
105
- let current = null;
106
- while (current = found.iterateNext()) {
107
- res.push(current);
108
- }
109
- return res;
110
- }
111
-
112
- if (by === 'frame') {
113
- if (!Array.isArray(locator)) locator = [locator];
114
- return [locator.reduce((parent, child) => parent.querySelector(child).contentDocument, window.document).querySelector('body')];
115
- }
116
- return [];
117
- };
118
-
119
- /**
120
- * @param {string} by
121
- * @param {CodeceptJS.ILocator} locator
122
- * @param {*} [context]
123
- * @return {?Node}
124
- */
125
- codeceptjs.findElement = function (by, locator, context) {
126
- return this.findElements(by, locator, context)[0] || null;
127
- };
128
-
129
- // actions
130
- /**
131
- * @param {number} el
132
- * @return {boolean}
133
- */
134
- codeceptjs.clickEl = function (el) {
135
- if (document.activeElement instanceof HTMLElement) {
136
- document.activeElement.blur();
137
- }
138
- const event = document.createEvent('MouseEvent');
139
- event.initEvent('click', true, true);
140
- return this.fetchElement(el).dispatchEvent(event);
141
- };
142
-
143
- /** @param {number} el */
144
- codeceptjs.doubleClickEl = function (el) {
145
- if (document.activeElement instanceof HTMLElement) {
146
- document.activeElement.blur();
147
- }
148
- const event = document.createEvent('MouseEvent');
149
- event.initEvent('dblclick', true, true);
150
- this.fetchElement(el).dispatchEvent(event);
151
- };
152
-
153
- /**
154
- * @param {number} el
155
- * @param {number | undefined} x
156
- * @param {number | undefined} y
157
- */
158
- codeceptjs.hoverEl = function (el, x, y) {
159
- if (document.activeElement instanceof HTMLElement) {
160
- document.activeElement.blur();
161
- }
162
-
163
- const event = new MouseEvent('mouseover', {
164
- bubbles: true,
165
- cancelable: true,
166
- screenX: x,
167
- screenY: y,
168
- clientX: x,
169
- clientY: y,
170
- });
171
-
172
- this.fetchElement(el).dispatchEvent(event);
173
- };
174
-
175
- /** @param {number} el */
176
- codeceptjs.rightClickEl = function (el) {
177
- const event = new MouseEvent('contextmenu', {
178
- bubbles: true,
179
- cancelable: true,
180
- view: window,
181
- buttons: 2,
182
- });
183
-
184
- this.fetchElement(el).dispatchEvent(event);
185
- };
186
-
187
- /**
188
- * @param {number} el
189
- * @return {boolean | undefined}
190
- */
191
- codeceptjs.checkEl = function (el) {
192
- const element = this.fetchElement(el);
193
- const event = document.createEvent('HTMLEvents');
194
- if (element.checked) return;
195
- element.checked = true;
196
- event.initEvent('change', true, true);
197
- return element.dispatchEvent(event);
198
- };
199
-
200
- /**
201
- * @param {number} el
202
- * @return {boolean}
203
- */
204
- codeceptjs.unCheckEl = function (el) {
205
- const element = this.fetchElement(el);
206
- const event = document.createEvent('HTMLEvents');
207
- element.checked = false;
208
- event.initEvent('change', true, true);
209
- return element.dispatchEvent(event);
210
- };
211
-
212
- window.codeceptjs = codeceptjs;
213
- }