promod 2.5.3 → 3.0.0

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 (88) hide show
  1. package/built/cjs/config.d.ts +43 -0
  2. package/built/cjs/config.js +161 -0
  3. package/built/cjs/config.js.map +1 -0
  4. package/built/cjs/helpers/execute.script.d.ts +1 -1
  5. package/built/cjs/helpers/execute.script.js +1 -3
  6. package/built/cjs/helpers/execute.script.js.map +1 -1
  7. package/built/cjs/index.d.ts +3 -1
  8. package/built/cjs/index.js +4 -1
  9. package/built/cjs/index.js.map +1 -1
  10. package/built/cjs/interface.d.ts +8 -4
  11. package/built/cjs/mappers.d.ts +1 -1
  12. package/built/cjs/mappers.js.map +1 -1
  13. package/built/cjs/pw/index.d.ts +2 -2
  14. package/built/cjs/pw/pw_client.d.ts +11 -10
  15. package/built/cjs/pw/pw_client.js +37 -56
  16. package/built/cjs/pw/pw_client.js.map +1 -1
  17. package/built/cjs/pw/pw_element.d.ts +17 -16
  18. package/built/cjs/pw/pw_element.js +19 -46
  19. package/built/cjs/pw/pw_element.js.map +1 -1
  20. package/built/cjs/shared/custom_selector_filter.d.ts +19 -0
  21. package/built/cjs/shared/custom_selector_filter.js +40 -0
  22. package/built/cjs/shared/custom_selector_filter.js.map +1 -0
  23. package/built/cjs/shared/validate_browser.d.ts +7 -0
  24. package/built/cjs/shared/validate_browser.js +29 -0
  25. package/built/cjs/shared/validate_browser.js.map +1 -0
  26. package/built/cjs/swd/swd_alignment.d.ts +1 -1
  27. package/built/cjs/swd/swd_alignment.js +2 -28
  28. package/built/cjs/swd/swd_alignment.js.map +1 -1
  29. package/built/cjs/swd/swd_client.d.ts +13 -10
  30. package/built/cjs/swd/swd_client.js +95 -31
  31. package/built/cjs/swd/swd_client.js.map +1 -1
  32. package/built/cjs/swd/swd_element.d.ts +14 -13
  33. package/built/cjs/swd/swd_element.js +13 -12
  34. package/built/cjs/swd/swd_element.js.map +1 -1
  35. package/built/esm/config.d.ts +43 -0
  36. package/built/esm/config.js +158 -0
  37. package/built/esm/config.js.map +1 -0
  38. package/built/esm/helpers/execute.script.d.ts +1 -1
  39. package/built/esm/helpers/execute.script.js +5 -9
  40. package/built/esm/helpers/execute.script.js.map +1 -1
  41. package/built/esm/index.d.ts +3 -1
  42. package/built/esm/index.js +4 -7
  43. package/built/esm/index.js.map +1 -1
  44. package/built/esm/interface.d.ts +8 -4
  45. package/built/esm/interface.js +1 -2
  46. package/built/esm/internals/index.js +1 -5
  47. package/built/esm/internals/index.js.map +1 -1
  48. package/built/esm/internals/logger.js +3 -6
  49. package/built/esm/internals/logger.js.map +1 -1
  50. package/built/esm/mappers.d.ts +1 -1
  51. package/built/esm/mappers.js +1 -7
  52. package/built/esm/mappers.js.map +1 -1
  53. package/built/esm/pw/index.d.ts +2 -2
  54. package/built/esm/pw/index.js +7 -10
  55. package/built/esm/pw/index.js.map +1 -1
  56. package/built/esm/pw/pw_client.d.ts +11 -10
  57. package/built/esm/pw/pw_client.js +93 -116
  58. package/built/esm/pw/pw_client.js.map +1 -1
  59. package/built/esm/pw/pw_element.d.ts +17 -16
  60. package/built/esm/pw/pw_element.js +84 -118
  61. package/built/esm/pw/pw_element.js.map +1 -1
  62. package/built/esm/shared/custom_selector_filter.d.ts +19 -0
  63. package/built/esm/shared/custom_selector_filter.js +38 -0
  64. package/built/esm/shared/custom_selector_filter.js.map +1 -0
  65. package/built/esm/shared/validate_browser.d.ts +7 -0
  66. package/built/esm/shared/validate_browser.js +27 -0
  67. package/built/esm/shared/validate_browser.js.map +1 -0
  68. package/built/esm/swd/index.js +7 -10
  69. package/built/esm/swd/index.js.map +1 -1
  70. package/built/esm/swd/swd_alignment.d.ts +1 -1
  71. package/built/esm/swd/swd_alignment.js +13 -42
  72. package/built/esm/swd/swd_alignment.js.map +1 -1
  73. package/built/esm/swd/swd_client.d.ts +13 -10
  74. package/built/esm/swd/swd_client.js +171 -111
  75. package/built/esm/swd/swd_client.js.map +1 -1
  76. package/built/esm/swd/swd_element.d.ts +14 -13
  77. package/built/esm/swd/swd_element.js +90 -97
  78. package/built/esm/swd/swd_element.js.map +1 -1
  79. package/docs/client.md +335 -111
  80. package/docs/config.md +176 -0
  81. package/docs/element.md +214 -141
  82. package/docs/elements.md +125 -65
  83. package/docs/init.md +66 -12
  84. package/oxlintrc.json +20 -0
  85. package/package.json +15 -18
  86. package/readme.md +114 -14
  87. package/tsconfig.esm.json +6 -2
  88. package/tsconfig.json +4 -1
package/docs/client.md CHANGED
@@ -1,212 +1,436 @@
1
1
  # Browser
2
2
 
3
- - [Key](#key)
4
- - [baseUrl](#baseUrl)
3
+ The `browser` object provides methods for page navigation, tab/window management, script execution, cookies, iframes, keyboard actions, and more.
4
+
5
+ All examples show both Playwright and Selenium WebDriver usage.
6
+
7
+ - [Key / keyboard](#key--keyboard)
8
+ - [baseUrl](#baseurl)
9
+ - [get](#get)
5
10
  - [getCurrentUrl](#getcurrenturl)
6
- - [takeScreenshot](#takescreenshot)
11
+ - [getTitle](#gettitle)
7
12
  - [refresh](#refresh)
8
- - [tabTitle](#tabtitle)
9
- - [getTabs](#gettabs)
10
- - [getCurrentTab](#getcurrenttab)
11
- - [close](#close)
12
- - [get](#get)
13
+ - [back](#back)
14
+ - [forward](#forward)
15
+ - [takeScreenshot](#takescreenshot)
13
16
  - [setWindowSize](#setwindowsize)
17
+ - [getWindomSize](#getwindomsize)
18
+ - [maximize](#maximize)
14
19
  - [sleep](#sleep)
15
- - [manage](#manage)
16
20
  - [executeScript](#executescript)
17
- - [navigate](#navigate)
18
- - [switchTo](#switchto)
19
- - [quit](#quit)
20
- - [getTitle](#gettitle)
21
+ - [getTabs](#gettabs)
22
+ - [getTabsCount](#gettabscount)
23
+ - [getCurrentTab](#getcurrenttab)
21
24
  - [switchToTab](#switchtotab)
22
25
  - [returnToInitialTab](#returntoinitialtab)
23
- - [actions](#actions)
26
+ - [openNewTab](#opennewtab)
27
+ - [makeActionAtEveryTab](#makeactionateverytab)
28
+ - [close](#close)
29
+ - [quit](#quit)
30
+ - [quitAll](#quitall)
24
31
  - [runNewBrowser](#runnewbrowser)
25
32
  - [switchToBrowser](#switchtobrowser)
33
+ - [switchToIframe](#switchtoiframe)
34
+ - [switchToDefauldIframe](#switchtodefauldiframe)
35
+ - [scrollByMouseWheel](#scrollbymousewheel)
36
+ - [scrollElementByMouseWheel](#scrollelementbymousewheel)
37
+ - [keyDownAndHold](#keydownandhold)
38
+ - [keyUp](#keyup)
39
+ - [keyDownAndUp](#keydownandup)
40
+ - [keyboardPressEsc](#keyboardpressesc)
41
+ - [keyboardPressEnter](#keyboardpressenter)
42
+ - [setCookies](#setcookies)
43
+ - [getCookies](#getcookies)
44
+ - [getCookieByName](#getcookiebyname)
45
+ - [deleteCookie](#deletecookie)
46
+ - [deleteAllCookies](#deleteallcookies)
47
+ - [getBrowserLogs](#getbrowserlogs)
48
+ - [setBasicAuth](#setbasicauth)
49
+ - [mockRequests](#mockrequests)
50
+ - [wait](#wait)
51
+
52
+ ---
53
+
54
+ ## Key / keyboard
26
55
 
27
- ## Key
28
56
  ```js
29
- const {seleniumWD} = require('promod');
30
- const {browser} = seleniumWD
31
-
32
- browser.Key // getter - returns keyboard keys
57
+ // Playwright
58
+ const { playwrightWD } = require('promod');
59
+ const { browser } = playwrightWD;
60
+ browser.Key // keyboard keys object
61
+ browser.keyboard // same as Key
62
+
63
+ // Selenium
64
+ const { seleniumWD } = require('promod');
65
+ const { browser } = seleniumWD;
66
+ browser.Key // selenium Key object
33
67
  ```
34
68
 
35
69
  ## baseUrl
70
+
36
71
  ```js
37
- const {seleniumWD} = require('promod');
38
- const {browser} = seleniumWD
72
+ browser.baseUrl = 'https://your.app.com'; // setter
73
+ const url = browser.baseUrl; // getter
39
74
 
40
- browser.baseUrl = 'https://your.app.com' // setter
41
- const currnetBaseUrl = browser.baseUrl // getter - returns current base url
42
- await browser.get('/test') // browser will open https://your.app.com/test
75
+ await browser.get('/test'); // opens https://your.app.com/test
76
+ ```
77
+
78
+ ## get
79
+
80
+ Opens a URL. If `baseUrl` is set and the argument is a relative path, the full URL is resolved.
81
+
82
+ ```js
83
+ await browser.get('https://example.com');
84
+ await browser.get('/relative/path'); // uses baseUrl
43
85
  ```
44
86
 
45
87
  ## getCurrentUrl
88
+
46
89
  ```js
47
- const {seleniumWD} = require('promod');
48
- const {browser} = seleniumWD
90
+ const url = await browser.getCurrentUrl();
91
+ ```
92
+
93
+ ## getTitle
49
94
 
50
- const url = await browser.getCurrentUrl() // current browser line url
95
+ ```js
96
+ const title = await browser.getTitle();
51
97
  ```
52
98
 
53
- ## takeScreenshot
99
+ ## refresh
100
+
54
101
  ```js
55
- const {seleniumWD} = require('promod');
56
- const {browser} = seleniumWD
102
+ await browser.refresh();
103
+ ```
57
104
 
58
- const screen = await browser.takeScreenshot()
105
+ ## back
106
+
107
+ ```js
108
+ await browser.back();
59
109
  ```
60
110
 
61
- ## refresh
111
+ ## forward
112
+
113
+ ```js
114
+ await browser.forward();
115
+ ```
116
+
117
+ ## takeScreenshot
118
+
62
119
  ```js
63
- const {seleniumWD} = require('promod');
64
- const {browser} = seleniumWD
120
+ const screenshot = await browser.takeScreenshot();
121
+ ```
122
+
123
+ ## setWindowSize
65
124
 
66
- await browser.refresh() // refresh page
125
+ ```js
126
+ await browser.setWindowSize(1280, 720);
67
127
  ```
68
128
 
69
- ## getTabs
129
+ ## getWindomSize
130
+
70
131
  ```js
71
- const {seleniumWD} = require('promod');
72
- const {browser} = seleniumWD
132
+ const { width, height } = await browser.getWindomSize();
133
+ ```
73
134
 
74
- const tabs = await browser.getTabs() // current browser opened tabs
135
+ ## maximize
136
+
137
+ ```js
138
+ await browser.maximize();
75
139
  ```
76
140
 
77
- ## get
141
+ ## sleep
142
+
78
143
  ```js
79
- const {seleniumWD} = require('promod');
80
- const {browser} = seleniumWD
144
+ await browser.sleep(2500); // sleep 2.5 seconds
145
+ ```
146
+
147
+ ## executeScript
81
148
 
82
- await browser.get('https://www.npmjs.com/package/promod') // open https://www.npmjs.com/package/promod
149
+ Executes a script in the browser context. Arguments must be passed as an array.
150
+
151
+ ```js
152
+ // No arguments
153
+ const height = await browser.executeScript(() => document.body.offsetHeight);
154
+
155
+ // With arguments
156
+ const text = await browser.executeScript(
157
+ ([el]) => el.innerText,
158
+ [$('h1').getEngineElement()],
159
+ );
83
160
  ```
84
161
 
85
- ## setWindowSize
162
+ ## getTabs
163
+
86
164
  ```js
87
- const {seleniumWD} = require('promod');
88
- const {browser} = seleniumWD
165
+ const tabs = await browser.getTabs();
166
+ ```
167
+
168
+ ## getTabsCount
89
169
 
90
- await browser.setWindowSize(200, 600) // set window size to width 200, height 600
170
+ ```js
171
+ const count = await browser.getTabsCount();
91
172
  ```
92
173
 
93
- ## sleep
174
+ ## getCurrentTab
175
+
94
176
  ```js
95
- const {seleniumWD} = require('promod');
96
- const {browser} = seleniumWD
177
+ const currentTab = await browser.getCurrentTab();
178
+ ```
97
179
 
98
- await browser.sleep(2500) // sleep 2.5 seconds
180
+ ## switchToTab
181
+
182
+ Switch to a tab by index, title, or URL.
183
+
184
+ ```js
185
+ await browser.switchToTab({ index: 2 });
186
+ await browser.switchToTab({ title: 'Some title' });
187
+ await browser.switchToTab({ url: 'some-url-part', strictEquality: false });
188
+ await browser.switchToTab({ index: 2, expectedQuantity: 3, timeout: 5000 });
99
189
  ```
100
190
 
101
- ## executeScript
191
+ | Option | Type | Description |
192
+ | --- | --- | --- |
193
+ | `index` | `number` | Tab index (0-based) |
194
+ | `title` | `string` | Tab title to match |
195
+ | `url` | `string` | URL to match |
196
+ | `expectedQuantity` | `number` | Wait until this many tabs exist |
197
+ | `timeout` | `number` | Max wait time in ms (default 5000) |
198
+ | `strictEquality` | `boolean` | Exact match vs substring (default true) |
199
+
200
+ ## returnToInitialTab
201
+
202
+ Closes all tabs except the initial one and switches back to it.
203
+
102
204
  ```js
103
- const {seleniumWD} = require('promod');
104
- const {browser} = seleniumWD
205
+ await browser.switchToTab({ index: 2 });
206
+ // ... do work ...
207
+ await browser.returnToInitialTab();
208
+ ```
209
+
210
+ ## openNewTab
105
211
 
106
- await browser.executeScript(() => document.querySelector('a').innerText) // returns result of the script
212
+ ```js
213
+ await browser.openNewTab('https://example.com');
214
+ await browser.openNewTab(); // opens blank tab
107
215
  ```
108
216
 
109
- ## executeAsyncScript
217
+ ## makeActionAtEveryTab
218
+
219
+ Runs an action in every open tab.
220
+
110
221
  ```js
111
- const {seleniumWD} = require('promod');
112
- const {browser} = seleniumWD
222
+ const titles = [];
223
+ await browser.makeActionAtEveryTab(async () => {
224
+ titles.push(await browser.getTitle());
225
+ });
226
+ ```
227
+
228
+ ## close
229
+
230
+ Closes the current tab/page.
113
231
 
114
- await browser.executeAsyncScript((done) => {
115
- setTimeout(() => {
116
- done(document.querySelector('a').innerText)
117
- }, 2500)
118
- }) // returns result of the async script
232
+ ```js
233
+ await browser.close();
119
234
  ```
120
235
 
121
236
  ## quit
237
+
238
+ Closes the current browser context/session.
239
+
122
240
  ```js
123
- const {seleniumWD} = require('promod');
124
- const {browser} = seleniumWD
241
+ await browser.quit();
242
+ ```
243
+
244
+ ## quitAll
125
245
 
126
- await browser.quit() // close session
246
+ Closes all contexts and the browser itself.
247
+
248
+ ```js
249
+ await browser.quitAll();
127
250
  ```
128
251
 
129
- ## actions
252
+ ## runNewBrowser
253
+
254
+ Creates a new browser context (Playwright) or launches a new browser instance (Selenium).
255
+
130
256
  ```js
131
- const {seleniumWD} = require('promod');
132
- const {browser} = seleniumWD
257
+ await browser.runNewBrowser();
258
+ await browser.runNewBrowser({
259
+ currentBrowserName: 'main',
260
+ newBrowserName: 'second',
261
+ });
262
+ ```
133
263
 
134
- const actionsObj = browser.actions() // returns selenium actions interface
264
+ ## switchToBrowser
265
+
266
+ Switch between multiple browser contexts/instances.
267
+
268
+ ```js
269
+ await browser.switchToBrowser({ index: 0 });
270
+ await browser.switchToBrowser({ browserName: 'main' });
271
+ await browser.switchToBrowser({ title: 'Page Title' });
135
272
  ```
136
273
 
137
- ## switchTo
274
+ ## switchToIframe
275
+
276
+ Switches the working context to an iframe.
277
+
138
278
  ```js
139
- const {seleniumWD} = require('promod');
140
- const {browser} = seleniumWD
279
+ // By CSS selector
280
+ await browser.switchToIframe('iframe.my-frame');
281
+
282
+ // By element
283
+ const frame = $('iframe.my-frame');
284
+ await browser.switchToIframe(frame);
285
+
286
+ // With options
287
+ await browser.switchToIframe('iframe.my-frame', false, {
288
+ timeout: 30000,
289
+ message: 'Custom error message',
290
+ });
291
+ ```
292
+
293
+ | Parameter | Type | Description |
294
+ | --- | --- | --- |
295
+ | `selector` | `string \| PromodElementType` | Iframe selector or element |
296
+ | `jumpToDefaultFirst` | `boolean` | Switch to top frame first (default false) |
297
+ | `opts.timeout` | `number` | Max wait time (default 30000) |
298
+ | `opts.message` | `string` | Custom error message |
299
+
300
+ ## switchToDefauldIframe
141
301
 
142
- const switchToObj = browser.switchTo() // returns selenium switchTo interface
302
+ Switches back to the top-level frame.
303
+
304
+ ```js
305
+ await browser.switchToDefauldIframe();
143
306
  ```
144
307
 
145
- ## navigate
308
+ ## scrollByMouseWheel
309
+
310
+ Scrolls the page by moving the mouse and using the wheel.
311
+
146
312
  ```js
147
- const {seleniumWD} = require('promod');
148
- const {browser} = seleniumWD
313
+ await browser.scrollByMouseWheel(x, y, deltaX, deltaY, duration);
314
+ ```
315
+
316
+ ## scrollElementByMouseWheel
317
+
318
+ Scrolls inside an element by moving the mouse to it and using the wheel.
149
319
 
150
- const navigateToObj = browser.navigate() // returns selenium navigate interface
320
+ ```js
321
+ const container = $('.scrollable');
322
+ await browser.scrollElementByMouseWheel(container, 0, 0, 0, 500, 100);
151
323
  ```
152
324
 
153
- ## getCurrentTab
325
+ ## keyDownAndHold
326
+
327
+ Presses and holds a key.
328
+
154
329
  ```js
155
- const {seleniumWD} = require('promod');
156
- const {browser} = seleniumWD
330
+ await browser.keyDownAndHold(browser.Key.PageDown);
331
+ await browser.keyDownAndHold('Shift', $('input'));
332
+ ```
333
+
334
+ ## keyUp
335
+
336
+ Releases a held key.
157
337
 
158
- const CurrentTabObj = await browser.getCurrentTab() // returns current browser tab item
338
+ ```js
339
+ await browser.keyUp(browser.Key.PageDown);
159
340
  ```
160
341
 
161
- ## getCurrentTab
342
+ ## keyDownAndUp
343
+
344
+ Presses and immediately releases a key.
345
+
162
346
  ```js
163
- const {seleniumWD} = require('promod');
164
- const {browser} = seleniumWD
347
+ await browser.keyDownAndUp(browser.Key.Escape);
348
+ ```
165
349
 
166
- await browser.close() // close current browser tab (if one close window)
350
+ ## keyboardPressEsc
351
+
352
+ ```js
353
+ await browser.keyboardPressEsc();
167
354
  ```
168
355
 
169
- ## getTitle
356
+ ## keyboardPressEnter
357
+
170
358
  ```js
171
- const {seleniumWD} = require('promod');
172
- const {browser} = seleniumWD
359
+ await browser.keyboardPressEnter();
360
+ ```
173
361
 
174
- const browserWindowTabTitle = await browser.getTitle();
362
+ ## setCookies
363
+
364
+ ```js
365
+ await browser.setCookies({ name: 'token', value: 'abc123' });
366
+ await browser.setCookies([
367
+ { name: 'a', value: '1' },
368
+ { name: 'b', value: '2' },
369
+ ]);
175
370
  ```
176
371
 
177
- ## switchToTab
372
+ ## getCookies
373
+
178
374
  ```js
179
- const {seleniumWD} = require('promod');
180
- const {browser} = seleniumWD
375
+ const cookies = await browser.getCookies();
376
+ ```
181
377
 
182
- await browser.switchToTab({index: 2}); // will switch context to third browser tab (second tab in tabs array)
183
- await browser.switchToTab({title: 'Some title'}); // will switch context to browser tab where tab title equals 'Some title'
378
+ ## getCookieByName
379
+
380
+ ```js
381
+ const cookie = await browser.getCookieByName('token');
184
382
  ```
185
383
 
186
- ## returnToInitialTab
384
+ ## deleteCookie
385
+
187
386
  ```js
188
- const {seleniumWD} = require('promod');
189
- const {browser} = seleniumWD
387
+ await browser.deleteCookie('token');
388
+ ```
190
389
 
191
- await browser.switchToTab({index: 2}); // will switch context to third browser tab (second tab in tabs array)
192
- await browser.returnToInitialTab(); // will switch first opened tab and close all other tabs
390
+ ## deleteAllCookies
391
+
392
+ ```js
393
+ await browser.deleteAllCookies();
193
394
  ```
194
395
 
195
- ## runNewBrowser
396
+ ## getBrowserLogs
397
+
398
+ Returns console log entries from the page (Playwright only captures these natively).
399
+
196
400
  ```js
197
- const {seleniumWD} = require('promod');
198
- const {browser} = seleniumWD
401
+ const logs = await browser.getBrowserLogs();
402
+ ```
403
+
404
+ ## setBasicAuth
199
405
 
200
- await browser.runNewBrowser(); // will runNewBrowser new browser
406
+ Sets Basic authentication headers on all subsequent requests (Playwright).
407
+
408
+ ```js
409
+ await browser.setBasicAuth({ username: 'user', password: 'pass' });
201
410
  ```
202
411
 
203
- ## switchToBrowser
412
+ ## mockRequests
413
+
414
+ Registers a request mock/intercept (Playwright).
204
415
 
205
416
  ```js
206
- const {seleniumWD} = require('promod');
207
- const {browser} = seleniumWD
417
+ browser.mockRequests({
418
+ url: '**/api/data',
419
+ handler: (request) => ({
420
+ status: 200,
421
+ body: JSON.stringify({ mocked: true }),
422
+ headers: { 'Content-Type': 'application/json' },
423
+ }),
424
+ });
425
+ ```
208
426
 
209
- await browser.switchToBrowser({index: 0}); // will switch to browser (not tab) which was started first
210
- await browser.switchToBrowser({title: 'Simple-Automation-Testing/promod: Library for browser manipulation'});
211
- // will switch to browser (not tab) which has "Simple-Automation-Testing/promod: Library for browser manipulation" title
212
- ```
427
+ ## wait
428
+
429
+ Built-in wait utility (`sat-wait`). Waits until a condition is met.
430
+
431
+ ```js
432
+ await browser.wait(
433
+ async () => (await browser.getTitle()) === 'Expected Title',
434
+ { timeout: 5000, message: 'Title did not match' },
435
+ );
436
+ ```