@mablhq/mabl-cli 1.45.8 → 1.47.20

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 (59) hide show
  1. package/api/basicApiClient.js +6 -0
  2. package/api/featureSet.js +0 -4
  3. package/api/mablApiClient.js +8 -0
  4. package/browserEngines/browserEngine.js +40 -0
  5. package/browserEngines/browserEngines.js +14 -0
  6. package/browserEngines/chromiumBrowserEngine.js +175 -0
  7. package/browserEngines/firefoxBrowserEngine.js +117 -0
  8. package/browserEngines/unsupportedBrowserEngine.js +26 -0
  9. package/browserLauncher/frameBase.js +5 -1
  10. package/browserLauncher/pageEvent.js +1 -0
  11. package/{api/entities/Plan.js → browserLauncher/playwrightBrowserLauncher/browserDelegate.js} +0 -0
  12. package/browserLauncher/playwrightBrowserLauncher/chromium/chromiumBrowserDelegate.js +58 -0
  13. package/browserLauncher/playwrightBrowserLauncher/chromium/chromiumElementHandleDelegate.js +65 -0
  14. package/browserLauncher/playwrightBrowserLauncher/chromium/chromiumFrameDelegate.js +12 -0
  15. package/browserLauncher/playwrightBrowserLauncher/chromium/chromiumPageDelegate.js +117 -0
  16. package/browserLauncher/playwrightBrowserLauncher/elementHandleDelegate.js +2 -0
  17. package/browserLauncher/playwrightBrowserLauncher/firefox/firefoxBrowserDelegate.js +54 -0
  18. package/browserLauncher/playwrightBrowserLauncher/firefox/firefoxElementHandleDelegate.js +61 -0
  19. package/browserLauncher/playwrightBrowserLauncher/firefox/firefoxFrameDelegate.js +23 -0
  20. package/browserLauncher/playwrightBrowserLauncher/firefox/firefoxPageDelegate.js +83 -0
  21. package/browserLauncher/playwrightBrowserLauncher/frameDelegate.js +2 -0
  22. package/browserLauncher/playwrightBrowserLauncher/pageDelegate.js +2 -0
  23. package/browserLauncher/playwrightBrowserLauncher/playwrightBrowser.js +44 -35
  24. package/browserLauncher/playwrightBrowserLauncher/playwrightBrowserLauncher.js +30 -5
  25. package/browserLauncher/playwrightBrowserLauncher/playwrightDom.js +33 -64
  26. package/browserLauncher/playwrightBrowserLauncher/playwrightFrame.js +35 -11
  27. package/browserLauncher/playwrightBrowserLauncher/playwrightHttpRequest.js +9 -1
  28. package/browserLauncher/playwrightBrowserLauncher/playwrightPage.js +28 -50
  29. package/commands/constants.js +6 -1
  30. package/commands/tests/testsUtil.js +27 -182
  31. package/commands/tests/tests_cmds/import.js +2 -2
  32. package/commands/tests/tests_cmds/run.js +9 -9
  33. package/commands/workspaces/workspace_cmds/copy.js +1 -2
  34. package/domUtil/index.js +1 -1
  35. package/execution/index.js +1 -1
  36. package/functions/apiTest/utils.js +47 -0
  37. package/functions/types.js +2 -0
  38. package/functions/utils.js +12 -0
  39. package/mablApi/index.js +1 -1
  40. package/mablscript/importer.js +3 -0
  41. package/mablscript/types/VariableNamespace.js +3 -3
  42. package/mablscriptFind/index.js +1 -1
  43. package/package.json +5 -4
  44. package/popupDismissal/index.js +7 -20
  45. package/proxy/index.js +1 -1
  46. package/resources/mablFind.js +1 -1
  47. package/resources/pdf-viewer/index.js +1 -1
  48. package/resources/pdf-viewer/libmablPdfViewer.js +117 -113
  49. package/resources/pdf-viewer/pdf.worker.0ceac9378bfc3bfcb634.js +81 -0
  50. package/resources/pdf-viewer/pdf.worker.df20a5600902b0735d4b.js +2 -0
  51. package/resources/popupDismissal.js +1 -1
  52. package/util/actionabilityUtil.js +4 -4
  53. package/util/browserTestUtils.js +18 -0
  54. package/util/clickUtil.js +7 -2
  55. package/util/fileUploadUtil.js +1 -1
  56. package/util/jestUtil.js +21 -0
  57. package/mablscript/types/VariableDataType.js +0 -28
  58. package/resources/pdf-viewer/pdf.worker.5953c23fa7251d236190.js +0 -2
  59. package/resources/pdf-viewer/pdf.worker.5f2736435a8b46d97859.js +0 -81
@@ -1,30 +1,6 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  Object.defineProperty(exports, "__esModule", { value: true });
26
3
  exports.PlaywrightElementHandle = exports.PlaywrightJsHandle = exports.NAVIGATION_ERROR_MESSAGE = void 0;
27
- const playwright = __importStar(require("@playwright/test"));
28
4
  const types_1 = require("../types");
29
5
  const utils_1 = require("../utils");
30
6
  const logUtils_1 = require("../../util/logUtils");
@@ -49,7 +25,7 @@ class PlaywrightJsHandle {
49
25
  async evaluateHandle(code, arg) {
50
26
  const handle = await this.handle.evaluateHandle(code, PlaywrightJsHandle.unwrapProperties(arg));
51
27
  return (0, utils_1.mapIfNotNull)(handle, (handle) => handle.asElement()
52
- ? new PlaywrightElementHandle(handle.asElement(), this.page)
28
+ ? new PlaywrightElementHandle(handle.asElement(), this.page, this.page.delegate.createElementHandleDelegate(handle.asElement()))
53
29
  : new PlaywrightJsHandle(handle, this.page));
54
30
  }
55
31
  async getProperty(propertyName) {
@@ -92,41 +68,26 @@ class PlaywrightJsHandle {
92
68
  }
93
69
  exports.PlaywrightJsHandle = PlaywrightJsHandle;
94
70
  class PlaywrightElementHandle extends PlaywrightJsHandle {
95
- constructor(element, page) {
96
- var _a, _b, _c, _d, _e, _f;
71
+ constructor(element, page, delegate) {
97
72
  super(element, page);
98
73
  this.element = element;
99
74
  this.page = page;
75
+ this.delegate = delegate;
100
76
  try {
101
- this.elementImpl = playwright._toImpl(this.element);
102
- this.cdpSession = (_c = (_b = (_a = this.elementImpl) === null || _a === void 0 ? void 0 : _a._context) === null || _b === void 0 ? void 0 : _b._delegate) === null || _c === void 0 ? void 0 : _c._client;
103
- if (this.elementImpl === undefined) {
104
- (0, logUtils_1.logInternal)(`Unable to get the Element's internal implementation.
105
- Some functionality, such as getting the clickable point or element highlighting might not work.`);
106
- }
107
- else if (this.cdpSession === undefined) {
108
- const undefinedField = ((_e = (_d = this.elementImpl) === null || _d === void 0 ? void 0 : _d._context) === null || _e === void 0 ? void 0 : _e._delegate) !== undefined
109
- ? '_client'
110
- : ((_f = this.elementImpl) === null || _f === void 0 ? void 0 : _f._context) !== undefined
111
- ? '_delegate'
112
- : '_context';
113
- (0, logUtils_1.logInternal)(`Unable to get the CDP Session of the element handle.
114
- ${undefinedField} is undefined.
115
- Some functionality, such as element highlighting will not work.`);
116
- }
77
+ this.cdpSession = delegate.getCDPSession();
117
78
  }
118
79
  catch (e) {
119
- (0, logUtils_1.logInternal)(`Unable to get the element handle's implementation. Error: ${e}`);
80
+ (0, logUtils_1.logInternal)(`Unable to get a CDP session for the element handle. Error: ${e}`);
120
81
  }
121
82
  }
122
83
  uploadFile(filePath) {
123
84
  return this.element.setInputFiles(filePath);
124
85
  }
125
86
  async $x(xpathQuery) {
126
- return (await this.element.$$(`xpath=${xpathQuery}`)).map((element) => new PlaywrightElementHandle(element, this.page));
87
+ return (await this.element.$$(`xpath=${xpathQuery}`)).map((element) => new PlaywrightElementHandle(element, this.page, this.page.delegate.createElementHandleDelegate(element)));
127
88
  }
128
89
  asElement() {
129
- return (0, utils_1.mapIfNotNull)(this.handle.asElement(), (handle) => new PlaywrightElementHandle(handle, this.page));
90
+ return (0, utils_1.mapIfNotNull)(this.handle.asElement(), (handle) => new PlaywrightElementHandle(handle, this.page, this.page.delegate.createElementHandleDelegate(handle)));
130
91
  }
131
92
  async boundingBox() {
132
93
  return (0, utils_1.mapIfNotNull)(await this.element.boundingBox(), (boundingBox) => boundingBox);
@@ -192,7 +153,8 @@ class PlaywrightElementHandle extends PlaywrightJsHandle {
192
153
  }
193
154
  async clickablePoint() {
194
155
  var _a;
195
- const clickablePoint = await ((_a = this.elementImpl) === null || _a === void 0 ? void 0 : _a._clickablePoint());
156
+ const clickablePoint = await ((_a = this.delegate
157
+ .getElementImpl()) === null || _a === void 0 ? void 0 : _a._clickablePoint());
196
158
  if (clickablePoint === 'error:notvisible' ||
197
159
  clickablePoint === 'error:notinviewport') {
198
160
  return undefined;
@@ -241,15 +203,15 @@ class PlaywrightElementHandle extends PlaywrightJsHandle {
241
203
  }
242
204
  getRemoteObjectId() {
243
205
  var _a, _b, _c;
244
- if (((_a = this.elementImpl) === null || _a === void 0 ? void 0 : _a._objectId) === undefined) {
206
+ if (((_a = this.delegate.getElementImpl()) === null || _a === void 0 ? void 0 : _a._objectId) === undefined) {
245
207
  (0, logUtils_1.logInternal)('ObjectId of an element handle was not found.');
246
208
  }
247
- return (_c = (_b = this.elementImpl) === null || _b === void 0 ? void 0 : _b._objectId) !== null && _c !== void 0 ? _c : '';
209
+ return (_c = (_b = this.delegate.getElementImpl()) === null || _b === void 0 ? void 0 : _b._objectId) !== null && _c !== void 0 ? _c : '';
248
210
  }
249
211
  async highlight(highlightDurationMillis, highlightPhases) {
250
212
  await this.enableDom();
251
213
  await this.enableOverlay();
252
- const nodeInfo = await this.makeCdpCall('DOM.describeNode', {
214
+ const nodeInfo = await this.makeCDPCall('DOM.describeNode', {
253
215
  objectId: this.getRemoteObjectId(),
254
216
  depth: -1,
255
217
  pierce: true,
@@ -280,22 +242,22 @@ class PlaywrightElementHandle extends PlaywrightJsHandle {
280
242
  highlightConfig.highlightConfig.contentColor.a =
281
243
  x * (1 - x) * 4 * elementHandle_1.MAX_HIGHLIGHT_OPACITY;
282
244
  }
283
- await this.makeCdpCall('Overlay.highlightNode', highlightConfig);
245
+ await this.makeCDPCall('Overlay.highlightNode', highlightConfig);
284
246
  await (0, testsUtil_1.sleep)(phaseIntervalMilliseconds);
285
247
  }
286
248
  }
287
249
  async enableDom() {
288
- await this.makeCdpCall('DOM.enable');
250
+ await this.makeCDPCall('DOM.enable');
289
251
  }
290
252
  async enableOverlay() {
291
- await this.makeCdpCall('Overlay.enable');
253
+ await this.makeCDPCall('Overlay.enable');
292
254
  }
293
255
  async hideHighlight() {
294
- await this.makeCdpCall('Overlay.hideHighlight');
256
+ await this.makeCDPCall('Overlay.hideHighlight');
295
257
  }
296
- async makeCdpCall(method, paramArgs) {
258
+ async makeCDPCall(method, paramArgs) {
297
259
  var _a;
298
- return ((_a = this.cdpSession) !== null && _a !== void 0 ? _a : this.page.getCdpSession()).send(method, paramArgs);
260
+ return ((_a = this.cdpSession) !== null && _a !== void 0 ? _a : this.page.getCDPSession()).send(method, paramArgs);
299
261
  }
300
262
  getTagName() {
301
263
  return this.element.evaluate((el) => el.tagName.toLowerCase());
@@ -338,7 +300,8 @@ class PlaywrightElementHandle extends PlaywrightJsHandle {
338
300
  }
339
301
  async overwriteScrollIntoViewFunction() {
340
302
  var _a;
341
- await ((_a = this.elementImpl) === null || _a === void 0 ? void 0 : _a.evaluateInUtility(([, node]) => {
303
+ await ((_a = this.delegate
304
+ .getElementImpl()) === null || _a === void 0 ? void 0 : _a.evaluateInUtility(([, node]) => {
342
305
  const element = node;
343
306
  if (!element.__mablOriginalScrollIntoView) {
344
307
  element.__mablOriginalScrollIntoView = element.scrollIntoView;
@@ -348,13 +311,19 @@ class PlaywrightElementHandle extends PlaywrightJsHandle {
348
311
  }
349
312
  async resetScrollIntoViewFunction() {
350
313
  var _a;
351
- await ((_a = this.elementImpl) === null || _a === void 0 ? void 0 : _a.evaluateInUtility(([, node]) => {
352
- const element = node;
353
- const originalFunction = element.__mablOriginalScrollIntoView;
354
- if (originalFunction) {
355
- element.scrollIntoView = originalFunction;
356
- }
357
- }, []));
314
+ try {
315
+ await ((_a = this.delegate
316
+ .getElementImpl()) === null || _a === void 0 ? void 0 : _a.evaluateInUtility(([, node]) => {
317
+ const element = node;
318
+ const originalFunction = element.__mablOriginalScrollIntoView;
319
+ if (originalFunction) {
320
+ element.scrollIntoView = originalFunction;
321
+ }
322
+ }, []));
323
+ }
324
+ catch (error) {
325
+ (0, logUtils_1.logInternal)(`Error while resetting scrollIntoView function: ${error}`);
326
+ }
358
327
  }
359
328
  }
360
329
  exports.PlaywrightElementHandle = PlaywrightElementHandle;
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.PlaywrightFrame = void 0;
26
+ exports.PlaywrightFrame = exports.UTILITY_CONTEXT_NAME = void 0;
27
27
  const browserLauncher_1 = require("../browserLauncher");
28
28
  const playwright = __importStar(require("@playwright/test"));
29
29
  const types_1 = require("../types");
@@ -34,18 +34,28 @@ const testsUtil_1 = require("../../commands/tests/testsUtil");
34
34
  const WAIT_FOR_CONTEXT_TIMEOUT = 1000;
35
35
  const MAIN_CONTEXT = 'main';
36
36
  const UTILITY_CONTEXT = 'utility';
37
+ exports.UTILITY_CONTEXT_NAME = '__playwright_utility_world__';
37
38
  class PlaywrightFrame extends browserLauncher_1.Frame {
38
- constructor(frame, parentPage) {
39
+ constructor(frame, parentPage, delegate) {
39
40
  super();
40
41
  this.frame = frame;
41
42
  this.parentPage = parentPage;
43
+ this.delegate = delegate;
42
44
  this.injectSecondaryWorld();
43
45
  }
44
46
  injectSecondaryWorld() {
47
+ const playwrightFrame = this;
45
48
  const serverFrame = this.getFrameImpl();
46
49
  if (serverFrame === undefined) {
47
50
  return;
48
51
  }
52
+ const originalSetContext = serverFrame._setContext.bind(serverFrame);
53
+ serverFrame._setContext = function (world, context) {
54
+ originalSetContext(world, context);
55
+ if (world === UTILITY_CONTEXT) {
56
+ playwrightFrame.emit(browserLauncher_1.PageEvent.SecondaryWorldCreated);
57
+ }
58
+ };
49
59
  serverFrame.checkWorldFunction = async function (arg) {
50
60
  let forcedWorld = MAIN_CONTEXT;
51
61
  if (this.utilityWorldAvailable === undefined) {
@@ -82,14 +92,14 @@ class PlaywrightFrame extends browserLauncher_1.Frame {
82
92
  functionHandleOverride.bind(serverFrame);
83
93
  }
84
94
  async $(selector) {
85
- return (0, utils_1.mapIfNotNull)(await this.frame.$(selector), (handle) => new playwrightDom_1.PlaywrightElementHandle(handle, this.parentPage));
95
+ return (0, utils_1.mapIfNotNull)(await this.frame.$(selector), (handle) => new playwrightDom_1.PlaywrightElementHandle(handle, this.parentPage, this.parentPage.delegate.createElementHandleDelegate(handle)));
86
96
  }
87
97
  async $$(selector) {
88
98
  const maybePlaywrightHandles = await this.frame.$$(selector);
89
99
  if (!maybePlaywrightHandles.length) {
90
100
  return [];
91
101
  }
92
- return maybePlaywrightHandles.map((handle) => new playwrightDom_1.PlaywrightElementHandle(handle, this.parentPage));
102
+ return maybePlaywrightHandles.map((handle) => new playwrightDom_1.PlaywrightElementHandle(handle, this.parentPage, this.parentPage.delegate.createElementHandleDelegate(handle)));
93
103
  }
94
104
  async $$eval(selector, pageFunction, ...args) {
95
105
  const result = await this.frame.$$eval(selector, pageFunction, ...args === null || args === void 0 ? void 0 : args.map((argument) => argument instanceof playwrightDom_1.PlaywrightJsHandle
@@ -104,7 +114,7 @@ class PlaywrightFrame extends browserLauncher_1.Frame {
104
114
  return result;
105
115
  }
106
116
  async $x(xpathQuery) {
107
- return (await this.frame.$$(`xpath=${xpathQuery}`)).map((element) => new playwrightDom_1.PlaywrightElementHandle(element, this.parentPage));
117
+ return (await this.frame.$$(`xpath=${xpathQuery}`)).map((element) => new playwrightDom_1.PlaywrightElementHandle(element, this.parentPage, this.parentPage.delegate.createElementHandleDelegate(element)));
108
118
  }
109
119
  childFrames() {
110
120
  return this.frame
@@ -121,7 +131,8 @@ class PlaywrightFrame extends browserLauncher_1.Frame {
121
131
  return new playwrightDom_1.PlaywrightJsHandle(await this.frame.evaluateHandle(code, playwrightDom_1.PlaywrightJsHandle.unwrapProperties(arg, true)), this.parentPage);
122
132
  }
123
133
  async getFrameOwnerElement() {
124
- return new playwrightDom_1.PlaywrightElementHandle(await this.frame.frameElement(), this.parentPage);
134
+ const frameElement = await this.frame.frameElement();
135
+ return new playwrightDom_1.PlaywrightElementHandle(frameElement, this.parentPage, this.parentPage.delegate.createElementHandleDelegate(frameElement));
125
136
  }
126
137
  async goto(url, options) {
127
138
  try {
@@ -157,7 +168,7 @@ class PlaywrightFrame extends browserLauncher_1.Frame {
157
168
  return this.frame.url();
158
169
  }
159
170
  async waitForSelector(selector, options) {
160
- return (0, utils_1.mapIfNotNull)(await this.frame.waitForSelector(selector, options), (handle) => new playwrightDom_1.PlaywrightElementHandle(handle, this.parentPage));
171
+ return (0, utils_1.mapIfNotNull)(await this.frame.waitForSelector(selector, options), (handle) => new playwrightDom_1.PlaywrightElementHandle(handle, this.parentPage, this.parentPage.delegate.createElementHandleDelegate(handle)));
161
172
  }
162
173
  page() {
163
174
  return this.parentPage;
@@ -165,7 +176,7 @@ class PlaywrightFrame extends browserLauncher_1.Frame {
165
176
  title() {
166
177
  return this.frame.title();
167
178
  }
168
- makeCdpCall(method, paramArgs) {
179
+ makeCDPCall(method, paramArgs) {
169
180
  const pageImpl = this.page().getPageImpl();
170
181
  const frameSession = pageImpl._sessionForFrame(this.frame);
171
182
  const client = frameSession._client;
@@ -181,17 +192,26 @@ class PlaywrightFrame extends browserLauncher_1.Frame {
181
192
  }
182
193
  return this.frameImpl;
183
194
  }
184
- async initializeExposedFunctionInSecondaryWorld(functionName) {
195
+ getExposedFunctionBindingInfo(functionName) {
185
196
  var _a;
186
197
  try {
187
198
  const pageImpl = this.parentPage.getPageImpl();
188
199
  if (!pageImpl) {
189
- return false;
200
+ return;
190
201
  }
191
- const binding = (_a = pageImpl._pageBindings.get(functionName)) !== null && _a !== void 0 ? _a : pageImpl._browserContext._pageBindings.get(functionName);
202
+ return ((_a = pageImpl._pageBindings.get(functionName)) !== null && _a !== void 0 ? _a : pageImpl._browserContext._pageBindings.get(functionName));
203
+ }
204
+ catch (e) {
205
+ return;
206
+ }
207
+ }
208
+ async initializeExposedFunctionInSecondaryWorld(functionName) {
209
+ try {
210
+ const binding = this.getExposedFunctionBindingInfo(functionName);
192
211
  if (!binding) {
193
212
  return false;
194
213
  }
214
+ await this.delegate.addBindingToSecondaryWorld(binding);
195
215
  await this.evaluateCodeInSecondaryWorld(binding.source, {});
196
216
  }
197
217
  catch (e) {
@@ -203,6 +223,10 @@ class PlaywrightFrame extends browserLauncher_1.Frame {
203
223
  const context = await this.getFrameImpl()._utilityContext();
204
224
  return new playwrightDom_1.PlaywrightJsHandle(await context.injectedScript(), this.page());
205
225
  }
226
+ async getInjectedScriptInMainWorld() {
227
+ const context = await this.getFrameImpl()._mainContext();
228
+ return new playwrightDom_1.PlaywrightJsHandle(await context.injectedScript(), this.page());
229
+ }
206
230
  isDetached() {
207
231
  return this.frame.isDetached();
208
232
  }
@@ -25,12 +25,20 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.PlaywrightHttpRequest = void 0;
27
27
  const playwright = __importStar(require("@playwright/test"));
28
+ const logUtils_1 = require("../../util/logUtils");
28
29
  class PlaywrightHttpRequest {
29
30
  constructor(page, request, route) {
31
+ var _a;
30
32
  this.page = page;
31
33
  this.request = request;
32
34
  this.route = route;
33
- this.documentId = playwright._toImpl(this.request)._documentId;
35
+ try {
36
+ this.documentId = playwright._toImpl(this.request)._documentId;
37
+ }
38
+ catch (e) {
39
+ (0, logUtils_1.logInternal)(`Unable to get documentId from request: ${e.message}`);
40
+ }
41
+ (_a = this.documentId) !== null && _a !== void 0 ? _a : (this.documentId = this.request._guid);
34
42
  }
35
43
  abort() {
36
44
  var _a;
@@ -38,15 +38,17 @@ const utils_1 = require("../utils");
38
38
  const wrappers_1 = require("./wrappers");
39
39
  const logUtils_1 = require("../../util/logUtils");
40
40
  const uuid = __importStar(require("uuid"));
41
+ const path = require("path");
41
42
  class PlaywrightPage extends events_1.default {
42
- constructor(page, browser) {
43
- var _a, _b, _c;
43
+ constructor(page, browser, delegate) {
44
+ var _a;
44
45
  super();
45
46
  this.page = page;
46
47
  this.browser = browser;
48
+ this.delegate = delegate;
47
49
  this.playwrightFrames = new Map();
48
50
  const guid = page._guid;
49
- this.pageId = (_c = (_b = (_a = this.getPageImpl()) === null || _a === void 0 ? void 0 : _a._delegate) === null || _b === void 0 ? void 0 : _b._targetId) !== null && _c !== void 0 ? _c : guid;
51
+ this.pageId = (_a = delegate.getTargetId()) !== null && _a !== void 0 ? _a : guid;
50
52
  page.off('dialog', this.acceptDialogs);
51
53
  page.on('dialog', this.acceptDialogs);
52
54
  page.on('close', () => {
@@ -67,15 +69,19 @@ class PlaywrightPage extends events_1.default {
67
69
  receivedBytes: downloadSize,
68
70
  state: 'completed',
69
71
  });
72
+ if (this.browser.browserDelegate.downloadsUsingGuids()) {
73
+ await download.saveAs(path.join(this.browser.getDownloadDirectory(), download.suggestedFilename()));
74
+ }
70
75
  });
71
76
  }
77
+ createCDPSession() {
78
+ return this.delegate.createCDPSession();
79
+ }
72
80
  async waitForInitialization() {
81
+ await this.delegate.waitForInitialization();
73
82
  this.openerPage = await (0, utils_1.mapIfNotNull)(await this.page.opener(), (page) => this.browser.getOrCreatePage(page));
74
- this.fallbackCdpSession = await this.createFallbackCdpSession();
75
83
  if (this.browser.disableFocusEmulation) {
76
- await this.makeCdpCall('Emulation.setFocusEmulationEnabled', {
77
- enabled: false,
78
- });
84
+ await this.delegate.setFocusEmulationEnabled(false);
79
85
  }
80
86
  }
81
87
  on(event, listener) {
@@ -92,7 +98,7 @@ class PlaywrightPage extends events_1.default {
92
98
  try {
93
99
  if (event === browserLauncher_1.PageEvent.RequestWillBeSentExtraInfo &&
94
100
  !this.listenerCount(event)) {
95
- this.getCdpSession().on('Network.requestWillBeSentExtraInfo', (event) => {
101
+ this.getCDPSession().on('Network.requestWillBeSentExtraInfo', (event) => {
96
102
  this.emit(browserLauncher_1.PageEvent.RequestWillBeSentExtraInfo, event);
97
103
  });
98
104
  }
@@ -133,18 +139,18 @@ class PlaywrightPage extends events_1.default {
133
139
  }
134
140
  if (event === browserLauncher_1.PageEvent.TracingBufferUsage &&
135
141
  !this.listenerCount(event)) {
136
- this.getCdpSession().on('Tracing.bufferUsage', (tracing) => {
142
+ this.getCDPSession().on('Tracing.bufferUsage', (tracing) => {
137
143
  this.emit(browserLauncher_1.PageEvent.TracingBufferUsage, tracing);
138
144
  });
139
145
  }
140
146
  if (event === browserLauncher_1.PageEvent.TracingDataCollected &&
141
147
  !this.listenerCount(event)) {
142
- this.getCdpSession().on('Tracing.dataCollected', (data) => {
148
+ this.getCDPSession().on('Tracing.dataCollected', (data) => {
143
149
  this.emit(browserLauncher_1.PageEvent.TracingDataCollected, data);
144
150
  });
145
151
  }
146
152
  if (event === browserLauncher_1.PageEvent.TracingComplete && !this.listenerCount(event)) {
147
- this.getCdpSession().on('Tracing.tracingComplete', (tracingComplete) => {
153
+ this.getCDPSession().on('Tracing.tracingComplete', (tracingComplete) => {
148
154
  this.emit(browserLauncher_1.PageEvent.TracingComplete, tracingComplete);
149
155
  });
150
156
  }
@@ -202,7 +208,7 @@ class PlaywrightPage extends events_1.default {
202
208
  return result;
203
209
  }
204
210
  async $x(xpathQuery) {
205
- return (await this.page.$$(`xpath=${xpathQuery}`)).map((element) => new playwrightDom_1.PlaywrightElementHandle(element, this));
211
+ return (await this.page.$$(`xpath=${xpathQuery}`)).map((element) => new playwrightDom_1.PlaywrightElementHandle(element, this, this.delegate.createElementHandleDelegate(element)));
206
212
  }
207
213
  authenticate(_credentials) {
208
214
  throw new Error('PlaywrightPage.authenticate not implemented');
@@ -227,9 +233,8 @@ class PlaywrightPage extends events_1.default {
227
233
  frames() {
228
234
  return this.page.frames().map((frame) => this.getOrCreateFrame(frame));
229
235
  }
230
- async getBrowserBounds() {
231
- const windowInfo = await this.getWindowInfo();
232
- return windowInfo.bounds;
236
+ getBrowserBounds() {
237
+ return this.delegate.getBrowserBounds();
233
238
  }
234
239
  async goto(url, options) {
235
240
  try {
@@ -279,18 +284,7 @@ class PlaywrightPage extends events_1.default {
279
284
  }
280
285
  }
281
286
  async resizeViewport() {
282
- await this.makeCdpCall('Emulation.clearDeviceMetricsOverride');
283
- }
284
- async setBrowserBounds(width, height) {
285
- const windowInfo = await this.makeCdpCall('Browser.getWindowForTarget');
286
- const setWindowBoundsRequest = {
287
- windowId: windowInfo.windowId,
288
- bounds: {
289
- width,
290
- height,
291
- },
292
- };
293
- await this.makeCdpCall('Browser.setWindowBounds', setWindowBoundsRequest);
287
+ await this.makeCDPCall('Emulation.clearDeviceMetricsOverride');
294
288
  }
295
289
  async setCookie(...cookies) {
296
290
  const pageUrl = this.url();
@@ -309,7 +303,7 @@ class PlaywrightPage extends events_1.default {
309
303
  async setViewport(viewport) {
310
304
  try {
311
305
  await this.page.setViewportSize(viewport);
312
- await this.setBrowserBounds(viewport.width, viewport.height);
306
+ await this.delegate.setBrowserBounds(viewport.width, viewport.height);
313
307
  }
314
308
  catch (error) {
315
309
  (0, logUtils_1.logInternal)(`Set Browser Bounds during setViewport step failed: ${error}`);
@@ -338,7 +332,7 @@ class PlaywrightPage extends events_1.default {
338
332
  }
339
333
  }
340
334
  async waitForSelector(selector, options) {
341
- return (0, utils_1.mapIfNotNull)(await this.page.waitForSelector(selector, options), (handle) => new playwrightDom_1.PlaywrightElementHandle(handle, this));
335
+ return (0, utils_1.mapIfNotNull)(await this.page.waitForSelector(selector, options), (handle) => new playwrightDom_1.PlaywrightElementHandle(handle, this, this.delegate.createElementHandleDelegate(handle)));
342
336
  }
343
337
  acceptDialogs(dialog) {
344
338
  return dialog.accept();
@@ -349,32 +343,16 @@ class PlaywrightPage extends events_1.default {
349
343
  setExtraHTTPHeaders(_headers) {
350
344
  throw new Error('PlaywrightPage.setExtraHTTPHeaders not implemented');
351
345
  }
352
- makeCdpCall(method, paramArgs) {
353
- return this.getCdpSession().send(method, paramArgs);
354
- }
355
- getCdpSession() {
356
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
357
- if (((_c = (_b = (_a = this.getPageImpl()) === null || _a === void 0 ? void 0 : _a._delegate) === null || _b === void 0 ? void 0 : _b._mainFrameSession) === null || _c === void 0 ? void 0 : _c._client) === undefined) {
358
- const undefinedField = ((_e = (_d = this.getPageImpl()) === null || _d === void 0 ? void 0 : _d._delegate) === null || _e === void 0 ? void 0 : _e._mainFrameSession) !== undefined
359
- ? '_client'
360
- : ((_f = this.getPageImpl()) === null || _f === void 0 ? void 0 : _f._delegate) !== undefined
361
- ? '_mainFrameSession'
362
- : 'pageImpl';
363
- (0, logUtils_1.logInternal)(`Unable to get the CDP Session of the page (${undefinedField} is undefined).
364
- Creating a fallback session. Some functionality might not work as expected.`);
365
- }
366
- return ((_k = (_j = (_h = (_g = this.getPageImpl()) === null || _g === void 0 ? void 0 : _g._delegate) === null || _h === void 0 ? void 0 : _h._mainFrameSession) === null || _j === void 0 ? void 0 : _j._client) !== null && _k !== void 0 ? _k : this.fallbackCdpSession);
367
- }
368
- createFallbackCdpSession() {
369
- return this.browser.defaultContext.newCDPSession(this.page);
346
+ makeCDPCall(method, paramArgs) {
347
+ return this.delegate.makeCDPCall(method, paramArgs);
370
348
  }
371
- async getWindowInfo() {
372
- return this.makeCdpCall('Browser.getWindowForTarget', { targetId: this.getPageId() });
349
+ getCDPSession() {
350
+ return this.delegate.getCDPSession();
373
351
  }
374
352
  getOrCreateFrame(frame) {
375
353
  const frameId = frame._guid;
376
354
  if (!this.playwrightFrames.has(frameId)) {
377
- const newFrame = new playwrightFrame_1.PlaywrightFrame(frame, this);
355
+ const newFrame = new playwrightFrame_1.PlaywrightFrame(frame, this, this.delegate.createFrameDelegate(frame));
378
356
  this.playwrightFrames.set(frameId, newFrame);
379
357
  }
380
358
  return this.playwrightFrames.get(frameId);
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CommandArgUrl = exports.CommandArgTrainerVersion = exports.CommandArgTo = exports.CommandArgSilent = exports.CommandArgRevision = exports.CommandArgMaxHeartbeatAge = exports.CommandArgPlanId = exports.CommandArgContentTypes = exports.CommandArgPreview = exports.CommandArgOutputFilePath = exports.CommandArgOutput = exports.CommandArgNoPrompt = exports.CommandArgPrompt = exports.CommandArgPortNumber = exports.CommandArgName = exports.CommandArgMablBranchChangesOnly = exports.CommandArgMablBranch = exports.CommandArgMablAutoLogin = exports.CommandArgMablAutoBranch = exports.CommandArgLinkBypass = exports.CommandArgLinkLabel = exports.CommandArgLimitOutput = exports.CommandArgLabels = exports.CommandArgLabelsInclude = exports.CommandArgLabelsExclude = exports.CommandArgTestInteractionSpeed = exports.CommandArgTestRunId = exports.CommandArgTestFile = exports.CommandArgId = exports.CommandArgUserAgent = exports.CommandArgHttpHeaders = exports.CommandArgHelp = exports.CommandArgFromPlanId = exports.CommandArgFrom = exports.CommandArgFormat = exports.CommandArgFastFailure = exports.CommandArgOverrideEnvironmentId = exports.CommandArgEnvironmentId = exports.CommandArgEnableLink = exports.CommandArgDetailLevel = exports.CommandArgDescription = exports.CommandArgDeploymentId = exports.CommandArgDecrypt = exports.CommandArgDataTables = exports.CommandArgCredentials = exports.CommandArgBasicAuthCredentials = exports.CommandArgBrowsers = exports.CommandArgBrowser = exports.CommandArgApplicationId = exports.CommandArgApiKey = void 0;
4
- exports.BrowserTypeSelections = exports.DefaultBrowserType = exports.DefaultBranchName = exports.DefaultOutputFormatChoices = exports.DetailLevelFormats = exports.ReporterOptions = exports.OutputFormats = exports.CommandArgAliases = exports.CommandArgBrowserEnableExtensions = exports.CommandArgBrowserIgnoreCertificateErrors = exports.CommandArgBrowserDisableIsolation = exports.ListTimeFormat = exports.CommandArgReporterOptions = exports.CommandArgReporter = exports.CommandArgWorkspaceId = exports.CommandArgVersion = exports.CommandArgVariables = exports.CommandArgUrlApi = exports.CommandArgUrlApp = void 0;
4
+ exports.ValidBrowserTypesForLocalRuns = exports.BrowserTypeSelections = exports.DefaultBrowserType = exports.DefaultBranchName = exports.DefaultOutputFormatChoices = exports.DetailLevelFormats = exports.ReporterOptions = exports.OutputFormats = exports.CommandArgAliases = exports.CommandArgBrowserEnableExtensions = exports.CommandArgBrowserIgnoreCertificateErrors = exports.CommandArgBrowserDisableIsolation = exports.ListTimeFormat = exports.CommandArgReporterOptions = exports.CommandArgReporter = exports.CommandArgWorkspaceId = exports.CommandArgVersion = exports.CommandArgVariables = exports.CommandArgUrlApi = exports.CommandArgUrlApp = void 0;
5
5
  const browserTypes_1 = require("./browserTypes");
6
6
  exports.CommandArgApiKey = 'api-key';
7
7
  exports.CommandArgApplicationId = 'application-id';
@@ -116,3 +116,8 @@ exports.BrowserTypeSelections = [
116
116
  browserTypes_1.BrowserType.InternetExplorer,
117
117
  browserTypes_1.BrowserType.Safari,
118
118
  ].map((browser) => browser.toString());
119
+ exports.ValidBrowserTypesForLocalRuns = [
120
+ browserTypes_1.BrowserType.Chrome,
121
+ browserTypes_1.BrowserType.Edge,
122
+ browserTypes_1.BrowserType.Firefox,
123
+ ];