@mablhq/mabl-cli 1.12.38 → 1.13.14

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.
@@ -28,6 +28,7 @@ const httpUtil_1 = require("../util/httpUtil");
28
28
  const axios_1 = __importDefault(require("axios"));
29
29
  const os = __importStar(require("os"));
30
30
  const async_retry_1 = __importDefault(require("async-retry"));
31
+ const asyncUtil_1 = require("../util/asyncUtil");
31
32
  const MABL_ENTITY_VERSION_HEADER = 'x-mabl-entity-version';
32
33
  const DEFAULT_MAX_TOTAL_RETRY_TIME_MILLISECONDS = 300000;
33
34
  const DEFAULT_MIN_RETRY_TIMEOUT_MILLISECONDS = 100;
@@ -64,6 +65,9 @@ class BasicApiClient {
64
65
  'x-mabl-user-platform': `${os.platform()}-${os.release()}`,
65
66
  },
66
67
  };
68
+ if (options.userAgentOverride) {
69
+ config.headers[httpUtil_1.USER_AGENT_HEADER] = options.userAgentOverride;
70
+ }
67
71
  this.httpClient = axios_1.default.create(config);
68
72
  this.retryConfig = options.retryConfig;
69
73
  }
@@ -129,20 +133,26 @@ class BasicApiClient {
129
133
  maxRetryTime: (_h = (_g = this.retryConfig) === null || _g === void 0 ? void 0 : _g.maxRetryTimeMillis) !== null && _h !== void 0 ? _h : DEFAULT_MAX_TOTAL_RETRY_TIME_MILLISECONDS,
130
134
  forever: false,
131
135
  };
132
- return async_retry_1.default(async (bail) => requestFunc().catch((error) => {
136
+ return asyncUtil_1.promiseWithTimeout(async_retry_1.default(async (bail) => {
133
137
  var _a, _b;
134
- const statusCode = (_a = error.statusCode) !== null && _a !== void 0 ? _a : (_b = error.response) === null || _b === void 0 ? void 0 : _b.status;
135
- if (statusCode === 429 ||
136
- statusCode === 502 ||
137
- statusCode === 503 ||
138
- statusCode === 504) {
139
- throw error;
138
+ try {
139
+ return await requestFunc();
140
140
  }
141
- else {
142
- bail(error);
143
- return {};
141
+ catch (error) {
142
+ const axiosError = error;
143
+ const statusCode = (_a = axiosError.code) !== null && _a !== void 0 ? _a : (_b = axiosError.response) === null || _b === void 0 ? void 0 : _b.status;
144
+ if (statusCode === 429 ||
145
+ statusCode === 502 ||
146
+ statusCode === 503 ||
147
+ statusCode === 504) {
148
+ throw error;
149
+ }
150
+ else {
151
+ bail(error);
152
+ return {};
153
+ }
144
154
  }
145
- }), retryOptions);
155
+ }, retryOptions), DEFAULT_MAX_TOTAL_RETRY_TIME_MILLISECONDS + 1000, 'Retryable API request');
146
156
  }
147
157
  }
148
158
  exports.BasicApiClient = BasicApiClient;
@@ -45,6 +45,7 @@ class MablApiClientFactory {
45
45
  proxyUrl: httpConfig.proxyHost,
46
46
  sslVerify: httpConfig.sslVerify,
47
47
  retryConfig: RETRY_CONFIG,
48
+ userAgentOverride: opts.userAgentOverride,
48
49
  });
49
50
  }
50
51
  const authProvider = new authenticationProvider_1.AuthenticationProvider();
@@ -15,7 +15,7 @@ class BrowserLauncherFactory {
15
15
  var _a;
16
16
  return (_a = process.env.MABL_RUNNER) === null || _a === void 0 ? void 0 : _a.toLowerCase();
17
17
  }
18
- static createRunner(runnerType = runnerType_1.RunnerType.Puppeteer, loggerFunc) {
18
+ static createRunner(runnerType = runnerType_1.RunnerType.Playwright, loggerFunc) {
19
19
  const runnerFromEnv = BrowserLauncherFactory.getRunnerFromEnvironment();
20
20
  const runner = runnerFromEnv ? runnerFromEnv : runnerType;
21
21
  loggerFunc = loggerFunc !== null && loggerFunc !== void 0 ? loggerFunc : ((line) => logUtils_1.logCliOutput(loggingProvider_1.LogLevel.Info, line));
@@ -29,6 +29,7 @@ const browserLauncher_1 = require("../browserLauncher");
29
29
  const playwrightPage_1 = require("./playwrightPage");
30
30
  const path_1 = __importDefault(require("path"));
31
31
  const fs_extra_1 = __importDefault(require("fs-extra"));
32
+ const runnerType_1 = require("../runnerType");
32
33
  class PlaywrightBrowser extends events_1.default {
33
34
  constructor(defaultContext, downloadDirectory, browserWSEndpoint) {
34
35
  super();
@@ -49,6 +50,9 @@ class PlaywrightBrowser extends events_1.default {
49
50
  fs_extra_1.default.mkdirSync(path_1.default.join(this.downloadDirectory));
50
51
  }
51
52
  }
53
+ getRunnerType() {
54
+ return runnerType_1.RunnerType.Playwright;
55
+ }
52
56
  makeCdpCall(method, paramArgs) {
53
57
  return this.cdpSession.send(method, paramArgs);
54
58
  }
@@ -19,13 +19,14 @@ var __importStar = (this && this.__importStar) || function (mod) {
19
19
  return result;
20
20
  };
21
21
  Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.PlaywrightElementHandle = exports.PlaywrightJsHandle = exports.DEFAULT_TEXT_INPUT_TIMEOUT_MS = void 0;
22
+ exports.PlaywrightElementHandle = exports.PlaywrightJsHandle = exports.NAVIGATION_ERROR_MESSAGE = void 0;
23
23
  const playwright = __importStar(require("@playwright/test"));
24
+ const types_1 = require("../types");
24
25
  const utils_1 = require("../utils");
25
26
  const logUtils_1 = require("../../util/logUtils");
26
27
  const elementHandle_1 = require("../elementHandle");
27
28
  const testsUtil_1 = require("../../commands/tests/testsUtil");
28
- exports.DEFAULT_TEXT_INPUT_TIMEOUT_MS = 30000;
29
+ exports.NAVIGATION_ERROR_MESSAGE = 'waiting for scheduled navigations to finish';
29
30
  class PlaywrightJsHandle {
30
31
  constructor(handle, page) {
31
32
  this.handle = handle;
@@ -125,15 +126,40 @@ class PlaywrightElementHandle extends PlaywrightJsHandle {
125
126
  async boundingBox() {
126
127
  return utils_1.mapIfNotNull(await this.element.boundingBox(), (boundingBox) => boundingBox);
127
128
  }
128
- click(options) {
129
- var _a, _b;
130
- return this.element.click({
131
- clickCount: (_a = options === null || options === void 0 ? void 0 : options.clickCount) !== null && _a !== void 0 ? _a : 1,
132
- force: (_b = options === null || options === void 0 ? void 0 : options.force) !== null && _b !== void 0 ? _b : true,
133
- });
129
+ async click(options) {
130
+ var _a, _b, _c, _d;
131
+ const trial = (_a = options === null || options === void 0 ? void 0 : options.trial) !== null && _a !== void 0 ? _a : false;
132
+ try {
133
+ await this.element.click({
134
+ clickCount: (_b = options === null || options === void 0 ? void 0 : options.clickCount) !== null && _b !== void 0 ? _b : 1,
135
+ force: (_c = options === null || options === void 0 ? void 0 : options.force) !== null && _c !== void 0 ? _c : !trial,
136
+ timeout: (_d = options === null || options === void 0 ? void 0 : options.timeout) !== null && _d !== void 0 ? _d : types_1.DefaultTimeouts.quickActionTimeoutMs,
137
+ trial,
138
+ });
139
+ }
140
+ catch (error) {
141
+ if (error.message.includes(exports.NAVIGATION_ERROR_MESSAGE)) {
142
+ logUtils_1.logInternal(`Action timed out due to navigation timeout. ${error.toString()}`);
143
+ return;
144
+ }
145
+ throw error;
146
+ }
134
147
  }
135
- doubleClick() {
136
- return this.element.dblclick();
148
+ async doubleClick(options) {
149
+ var _a, _b, _c;
150
+ try {
151
+ const trial = (_a = options === null || options === void 0 ? void 0 : options.trial) !== null && _a !== void 0 ? _a : false;
152
+ return this.element.dblclick({
153
+ force: (_b = options === null || options === void 0 ? void 0 : options.force) !== null && _b !== void 0 ? _b : !trial,
154
+ timeout: (_c = options === null || options === void 0 ? void 0 : options.timeout) !== null && _c !== void 0 ? _c : types_1.DefaultTimeouts.quickActionTimeoutMs,
155
+ trial,
156
+ });
157
+ }
158
+ catch (error) {
159
+ if (error.message.includes(exports.NAVIGATION_ERROR_MESSAGE)) {
160
+ logUtils_1.logInternal(`Action timed out due to navigation timeout. ${error.toString()}`);
161
+ }
162
+ }
137
163
  }
138
164
  async clickablePoint() {
139
165
  var _a;
@@ -175,7 +201,7 @@ class PlaywrightElementHandle extends PlaywrightJsHandle {
175
201
  var _a;
176
202
  let timeout;
177
203
  const newTimeout = text.length * ((_a = options === null || options === void 0 ? void 0 : options.delay) !== null && _a !== void 0 ? _a : 1) * 2;
178
- if (newTimeout > exports.DEFAULT_TEXT_INPUT_TIMEOUT_MS) {
204
+ if (newTimeout > types_1.DefaultTimeouts.defaultTextInputTimeoutMs) {
179
205
  timeout = newTimeout;
180
206
  }
181
207
  return timeout;
@@ -239,7 +265,7 @@ class PlaywrightElementHandle extends PlaywrightJsHandle {
239
265
  }
240
266
  async makeCdpCall(method, paramArgs) {
241
267
  var _a;
242
- return ((_a = this.cdpSession) !== null && _a !== void 0 ? _a : (await this.page.getCdpSession())).send(method, paramArgs);
268
+ return ((_a = this.cdpSession) !== null && _a !== void 0 ? _a : this.page.getCdpSession()).send(method, paramArgs);
243
269
  }
244
270
  }
245
271
  exports.PlaywrightElementHandle = PlaywrightElementHandle;
@@ -69,6 +69,7 @@ class PlaywrightPage extends events_1.default {
69
69
  }
70
70
  async waitForInitialization() {
71
71
  this.openerPage = await utils_1.mapIfNotNull(await this.page.opener(), (page) => this.browser.getOrCreatePage(page));
72
+ this.fallbackCdpSession = await this.createFallbackCdpSession();
72
73
  }
73
74
  on(event, listener) {
74
75
  this.wireEvents(event);
@@ -81,56 +82,62 @@ class PlaywrightPage extends events_1.default {
81
82
  return this;
82
83
  }
83
84
  wireEvents(event) {
84
- if (event === browserLauncher_1.PageEvent.RequestWillBeSentExtraInfo &&
85
- !this.listenerCount(event)) {
86
- void this.getCdpSession().then((session) => session.on('Network.requestWillBeSentExtraInfo', (event) => {
87
- this.emit(browserLauncher_1.PageEvent.RequestWillBeSentExtraInfo, event);
88
- }));
89
- }
90
- if (event === browserLauncher_1.PageEvent.Response && !this.listenerCount(event)) {
91
- this.page.on('response', (event) => {
92
- this.emit(browserLauncher_1.PageEvent.Response, new playwrightHttpResponse_1.PlaywrightHttpResponse(this, event));
93
- });
94
- }
95
- if (event === browserLauncher_1.PageEvent.Request && !this.listenerCount(event)) {
96
- void this.page.route('**/*', (route) => {
97
- this.emit(browserLauncher_1.PageEvent.Request, new playwrightHttpRequest_1.PlaywrightHttpRequest(this, route.request(), route));
98
- });
99
- }
100
- if (event === browserLauncher_1.PageEvent.FrameNavigated && !this.listenerCount(event)) {
101
- this.page.on('framenavigated', (frame) => {
102
- this.emit(browserLauncher_1.PageEvent.FrameNavigated, this.getOrCreateFrame(frame));
103
- });
104
- }
105
- if (event === browserLauncher_1.PageEvent.FrameAttached && !this.listenerCount(event)) {
106
- this.page.on('frameattached', (frame) => {
107
- this.emit(browserLauncher_1.PageEvent.FrameAttached, this.getOrCreateFrame(frame));
108
- });
109
- }
110
- if (event === browserLauncher_1.PageEvent.Console && !this.listenerCount(event)) {
111
- this.page.on('console', (console) => {
112
- this.emit(browserLauncher_1.PageEvent.Console, new wrappers_1.PlaywrightWrappedConsoleMessage(console, this));
113
- });
114
- }
115
- if (event === browserLauncher_1.PageEvent.PageError && !this.listenerCount(event)) {
116
- this.page.on('pageerror', (error) => {
117
- this.emit(browserLauncher_1.PageEvent.PageError, error);
118
- });
119
- }
120
- if (event === browserLauncher_1.PageEvent.Error && !this.listenerCount(event)) {
121
- this.page.on('crash', (error) => {
122
- this.emit(browserLauncher_1.PageEvent.Error, error);
123
- });
124
- }
125
- if (event === browserLauncher_1.PageEvent.TracingBufferUsage && !this.listenerCount(event)) {
126
- void this.getCdpSession().then((session) => session.on('Tracing.bufferUsage', (tracing) => {
127
- this.emit(browserLauncher_1.PageEvent.TracingBufferUsage, tracing);
128
- }));
85
+ try {
86
+ if (event === browserLauncher_1.PageEvent.RequestWillBeSentExtraInfo &&
87
+ !this.listenerCount(event)) {
88
+ this.getCdpSession().on('Network.requestWillBeSentExtraInfo', (event) => {
89
+ this.emit(browserLauncher_1.PageEvent.RequestWillBeSentExtraInfo, event);
90
+ });
91
+ }
92
+ if (event === browserLauncher_1.PageEvent.Response && !this.listenerCount(event)) {
93
+ this.page.on('response', (event) => {
94
+ this.emit(browserLauncher_1.PageEvent.Response, new playwrightHttpResponse_1.PlaywrightHttpResponse(this, event));
95
+ });
96
+ }
97
+ if (event === browserLauncher_1.PageEvent.Request && !this.listenerCount(event)) {
98
+ void this.page.route('**/*', (route) => {
99
+ this.emit(browserLauncher_1.PageEvent.Request, new playwrightHttpRequest_1.PlaywrightHttpRequest(this, route.request(), route));
100
+ });
101
+ }
102
+ if (event === browserLauncher_1.PageEvent.FrameNavigated && !this.listenerCount(event)) {
103
+ this.page.on('framenavigated', (frame) => {
104
+ this.emit(browserLauncher_1.PageEvent.FrameNavigated, this.getOrCreateFrame(frame));
105
+ });
106
+ }
107
+ if (event === browserLauncher_1.PageEvent.FrameAttached && !this.listenerCount(event)) {
108
+ this.page.on('frameattached', (frame) => {
109
+ this.emit(browserLauncher_1.PageEvent.FrameAttached, this.getOrCreateFrame(frame));
110
+ });
111
+ }
112
+ if (event === browserLauncher_1.PageEvent.Console && !this.listenerCount(event)) {
113
+ this.page.on('console', (console) => {
114
+ this.emit(browserLauncher_1.PageEvent.Console, new wrappers_1.PlaywrightWrappedConsoleMessage(console, this));
115
+ });
116
+ }
117
+ if (event === browserLauncher_1.PageEvent.PageError && !this.listenerCount(event)) {
118
+ this.page.on('pageerror', (error) => {
119
+ this.emit(browserLauncher_1.PageEvent.PageError, error);
120
+ });
121
+ }
122
+ if (event === browserLauncher_1.PageEvent.Error && !this.listenerCount(event)) {
123
+ this.page.on('crash', (error) => {
124
+ this.emit(browserLauncher_1.PageEvent.Error, error);
125
+ });
126
+ }
127
+ if (event === browserLauncher_1.PageEvent.TracingBufferUsage &&
128
+ !this.listenerCount(event)) {
129
+ this.getCdpSession().on('Tracing.bufferUsage', (tracing) => {
130
+ this.emit(browserLauncher_1.PageEvent.TracingBufferUsage, tracing);
131
+ });
132
+ }
133
+ if (event === browserLauncher_1.PageEvent.TracingComplete && !this.listenerCount(event)) {
134
+ this.getCdpSession().on('Tracing.tracingComplete', (tracingComplete) => {
135
+ this.emit(browserLauncher_1.PageEvent.TracingComplete, tracingComplete);
136
+ });
137
+ }
129
138
  }
130
- if (event === browserLauncher_1.PageEvent.TracingComplete && !this.listenerCount(event)) {
131
- void this.getCdpSession().then((session) => session.on('Tracing.tracingComplete', (tracingComplete) => {
132
- this.emit(browserLauncher_1.PageEvent.TracingComplete, tracingComplete);
133
- }));
139
+ catch (error) {
140
+ logUtils_1.logInternal(`Unable to register event ${event.toString()}. Error: ${error}`);
134
141
  }
135
142
  }
136
143
  async screenshot(clip) {
@@ -329,9 +336,9 @@ class PlaywrightPage extends events_1.default {
329
336
  throw new Error('PlaywrightPage.setExtraHTTPHeaders not implemented');
330
337
  }
331
338
  makeCdpCall(method, paramArgs) {
332
- return this.getCdpSession().then((session) => session.send(method, paramArgs));
339
+ return this.getCdpSession().send(method, paramArgs);
333
340
  }
334
- async getCdpSession() {
341
+ getCdpSession() {
335
342
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
336
343
  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) {
337
344
  const undefinedField = ((_e = (_d = this.getPageImpl()) === null || _d === void 0 ? void 0 : _d._delegate) === null || _e === void 0 ? void 0 : _e._mainFrameSession) !== undefined
@@ -342,13 +349,10 @@ class PlaywrightPage extends events_1.default {
342
349
  logUtils_1.logInternal(`Unable to get the CDP Session of the page (${undefinedField} is undefined).
343
350
  Creating a fallback session. Some functionality might not work as expected.`);
344
351
  }
345
- 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.getOrCreateFallbackCdpSession());
352
+ 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);
346
353
  }
347
- async getOrCreateFallbackCdpSession() {
348
- if (this.fallbackCdpSession === undefined) {
349
- this.fallbackCdpSession = await this.browser.defaultContext.newCDPSession(this.page);
350
- }
351
- return this.fallbackCdpSession;
354
+ createFallbackCdpSession() {
355
+ return this.browser.defaultContext.newCDPSession(this.page);
352
356
  }
353
357
  async getWindowInfo() {
354
358
  return this.makeCdpCall('Browser.getWindowForTarget', { targetId: this.getPageId() });
@@ -9,6 +9,7 @@ const puppeteer_core_1 = __importDefault(require("puppeteer-core"));
9
9
  const events_1 = __importDefault(require("events"));
10
10
  const puppeteerBrowserLauncher_1 = require("./puppeteerBrowserLauncher");
11
11
  const puppeteerPage_1 = require("./puppeteerPage");
12
+ const runnerType_1 = require("../runnerType");
12
13
  class PuppeteerBrowser extends events_1.default {
13
14
  constructor(browser, downloadDirectory, credentials) {
14
15
  var _a;
@@ -38,6 +39,9 @@ class PuppeteerBrowser extends events_1.default {
38
39
  state: event.state,
39
40
  }));
40
41
  }
42
+ getRunnerType() {
43
+ return runnerType_1.RunnerType.Puppeteer;
44
+ }
41
45
  getDownloadDirectory() {
42
46
  return this.downloadDirectory;
43
47
  }
@@ -35,9 +35,15 @@ class PuppeteerElementHandle extends puppeteerJsHandle_1.PuppeteerJsHandle {
35
35
  return this.element.hover();
36
36
  }
37
37
  click(options) {
38
+ if (options === null || options === void 0 ? void 0 : options.trial) {
39
+ return Promise.resolve();
40
+ }
38
41
  return this.element.click(options);
39
42
  }
40
- async doubleClick() {
43
+ async doubleClick(options) {
44
+ if (options === null || options === void 0 ? void 0 : options.trial) {
45
+ return Promise.resolve();
46
+ }
41
47
  await this.element.click();
42
48
  await testsUtil_1.sleep(msBetweenClicks);
43
49
  return this.element.click({ clickCount: 2 });
@@ -1,6 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WaitForOptions = exports.LifecycleEvent = void 0;
3
+ exports.WaitForOptions = exports.LifecycleEvent = exports.DefaultTimeouts = void 0;
4
+ class DefaultTimeouts {
5
+ }
6
+ exports.DefaultTimeouts = DefaultTimeouts;
7
+ DefaultTimeouts.quickActionTimeoutMs = 5000;
8
+ DefaultTimeouts.defaultTextInputTimeoutMs = 30000;
4
9
  var LifecycleEvent;
5
10
  (function (LifecycleEvent) {
6
11
  LifecycleEvent["DomContentLoaded"] = "domcontentloaded";