@checkly/playwright-core 1.48.24-maxi → 1.48.24

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 (109) hide show
  1. package/lib/vite/traceViewer/assets/{codeMirrorModule-tzBrK1V4.js → codeMirrorModule-Bh1rfd2w.js} +10 -10
  2. package/lib/vite/traceViewer/assets/codeMirrorModule-lDjkI8Ax.js +24 -0
  3. package/lib/vite/traceViewer/assets/codeMirrorModule-xvopPhZ4.js +24 -0
  4. package/lib/vite/traceViewer/assets/{inspectorTab-BuJ3wAX_.js → inspectorTab-7GHnKvSD.js} +2 -2
  5. package/lib/vite/traceViewer/assets/inspectorTab-BPzhNk9r.js +64 -0
  6. package/lib/vite/traceViewer/assets/inspectorTab-wfvwpMHs.js +64 -0
  7. package/lib/vite/traceViewer/assets/{workbench-DdmJ9AJV.js → workbench-C6nMfKVy.js} +1 -1
  8. package/lib/vite/traceViewer/assets/workbench-DLv_q9ji.js +9 -0
  9. package/lib/vite/traceViewer/assets/workbench-LKskf2Iy.js +9 -0
  10. package/lib/vite/traceViewer/{embedded.DInvAijy.js → embedded.BIubxTi3.js} +1 -1
  11. package/lib/vite/traceViewer/embedded.BXYl5zRv.js +2 -0
  12. package/lib/vite/traceViewer/embedded.CShPz96b.js +2 -0
  13. package/lib/vite/traceViewer/embedded.html +3 -3
  14. package/lib/vite/traceViewer/{index.Dha3cgqs.js → index.BZ9CE8t3.js} +1 -1
  15. package/lib/vite/traceViewer/index.DPD22sZn.js +2 -0
  16. package/lib/vite/traceViewer/index.DZkJsFod.js +2 -0
  17. package/lib/vite/traceViewer/index.html +3 -3
  18. package/lib/vite/traceViewer/{recorder.DNMfnSiu.js → recorder.BVExlUUk.js} +1 -1
  19. package/lib/vite/traceViewer/recorder.BaRuS6Pc.js +2 -0
  20. package/lib/vite/traceViewer/recorder.C4zxcvd2.js +2 -0
  21. package/lib/vite/traceViewer/recorder.html +2 -2
  22. package/lib/vite/traceViewer/{uiMode.Cr1tvTWS.js → uiMode.B11wexdJ.js} +1 -1
  23. package/lib/vite/traceViewer/uiMode.DXa41vt9.js +5 -0
  24. package/lib/vite/traceViewer/uiMode.DjTS7tqC.js +5 -0
  25. package/lib/vite/traceViewer/uiMode.html +3 -3
  26. package/package.json +1 -1
  27. package/lib/client/clientStackTrace.js +0 -66
  28. package/lib/client/fileUtils.js +0 -33
  29. package/lib/client/platform.js +0 -72
  30. package/lib/client/timeoutSettings.js +0 -66
  31. package/lib/client/webSocket.js +0 -107
  32. package/lib/generated/recorderSource.js +0 -7
  33. package/lib/server/callLog.js +0 -80
  34. package/lib/server/harBackend.js +0 -158
  35. package/lib/server/localUtils.js +0 -204
  36. package/lib/server/recorder/chat.js +0 -178
  37. package/lib/server/recorder/codeGenerator.js +0 -154
  38. package/lib/server/recorder/csharp.js +0 -311
  39. package/lib/server/recorder/java.js +0 -249
  40. package/lib/server/recorder/javascript.js +0 -230
  41. package/lib/server/recorder/jsonl.js +0 -48
  42. package/lib/server/recorder/language.js +0 -45
  43. package/lib/server/recorder/python.js +0 -276
  44. package/lib/server/recorder/recorderActions.js +0 -6
  45. package/lib/server/recorder/utils.js +0 -46
  46. package/lib/server/storageScript.js +0 -161
  47. package/lib/server/timeoutSettings.js +0 -75
  48. package/lib/server/utils/ascii.js +0 -32
  49. package/lib/server/utils/comparators.js +0 -160
  50. package/lib/server/utils/crypto.js +0 -172
  51. package/lib/server/utils/debug.js +0 -39
  52. package/lib/server/utils/debugLogger.js +0 -94
  53. package/lib/server/utils/env.js +0 -54
  54. package/lib/server/utils/eventsHelper.js +0 -39
  55. package/lib/server/utils/expectUtils.js +0 -34
  56. package/lib/server/utils/fileUtils.js +0 -205
  57. package/lib/server/utils/happyEyeballs.js +0 -210
  58. package/lib/server/utils/hostPlatform.js +0 -146
  59. package/lib/server/utils/httpServer.js +0 -234
  60. package/lib/server/utils/image_tools/colorUtils.js +0 -99
  61. package/lib/server/utils/image_tools/compare.js +0 -109
  62. package/lib/server/utils/image_tools/imageChannel.js +0 -71
  63. package/lib/server/utils/image_tools/stats.js +0 -103
  64. package/lib/server/utils/linuxUtils.js +0 -59
  65. package/lib/server/utils/network.js +0 -161
  66. package/lib/server/utils/nodePlatform.js +0 -141
  67. package/lib/server/utils/pipeTransport.js +0 -83
  68. package/lib/server/utils/processLauncher.js +0 -249
  69. package/lib/server/utils/profiler.js +0 -53
  70. package/lib/server/utils/socksProxy.js +0 -571
  71. package/lib/server/utils/spawnAsync.js +0 -46
  72. package/lib/server/utils/task.js +0 -59
  73. package/lib/server/utils/userAgent.js +0 -92
  74. package/lib/server/utils/wsServer.js +0 -129
  75. package/lib/server/utils/zipFile.js +0 -76
  76. package/lib/server/utils/zones.js +0 -55
  77. package/lib/utils/glob.js +0 -84
  78. package/lib/utils/isomorphic/ariaSnapshot.js +0 -393
  79. package/lib/utils/isomorphic/assert.js +0 -26
  80. package/lib/utils/isomorphic/colors.js +0 -66
  81. package/lib/utils/isomorphic/headers.js +0 -53
  82. package/lib/utils/isomorphic/manualPromise.js +0 -108
  83. package/lib/utils/isomorphic/multimap.js +0 -74
  84. package/lib/utils/isomorphic/rtti.js +0 -42
  85. package/lib/utils/isomorphic/semaphore.js +0 -52
  86. package/lib/utils/isomorphic/stackTrace.js +0 -170
  87. package/lib/utils/isomorphic/time.js +0 -26
  88. package/lib/utils/isomorphic/timeoutRunner.js +0 -67
  89. package/lib/utils/isomorphic/types.js +0 -6
  90. package/lib/utils/mimeType.js +0 -30
  91. package/lib/utils.js +0 -448
  92. package/lib/vite/traceViewer/assets/codeMirrorModule-CB-2okZ8.js +0 -16684
  93. package/lib/vite/traceViewer/assets/defaultSettingsView-CBiB4avC.js +0 -217
  94. package/lib/vite/traceViewer/assets/inspectorTab-CwgfffWb.js +0 -25143
  95. package/lib/vite/traceViewer/assets/workbench-CWZselvp.js +0 -2470
  96. package/lib/vite/traceViewer/assets/xtermModule-Es_gt_u7.js +0 -5994
  97. package/lib/vite/traceViewer/codeMirrorModule.DuST8d_k.css +0 -344
  98. package/lib/vite/traceViewer/defaultSettingsView.Dp3b_92q.css +0 -41
  99. package/lib/vite/traceViewer/embedded.BeldSa2G.css +0 -68
  100. package/lib/vite/traceViewer/embedded.gzudoghF.js +0 -106
  101. package/lib/vite/traceViewer/index.DilotR1h.js +0 -314
  102. package/lib/vite/traceViewer/index.QewjJ85u.css +0 -131
  103. package/lib/vite/traceViewer/inspectorTab.DnGm18kV.css +0 -3178
  104. package/lib/vite/traceViewer/recorder.DLgqV9db.css +0 -15
  105. package/lib/vite/traceViewer/recorder.DVrkq3Um.js +0 -551
  106. package/lib/vite/traceViewer/uiMode.C9_OcpPU.js +0 -1756
  107. package/lib/vite/traceViewer/uiMode.c5ORgcrX.css +0 -1424
  108. package/lib/vite/traceViewer/workbench.xUZSA8PY.css +0 -787
  109. package/lib/vite/traceViewer/xtermModule.EsaqrrTX.css +0 -209
@@ -1,230 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.JavaScriptLanguageGenerator = exports.JavaScriptFormatter = void 0;
7
- var _language = require("./language");
8
- var _utils = require("./utils");
9
- var _stringUtils = require("../../utils/isomorphic/stringUtils");
10
- var _locatorGenerators = require("../../utils/isomorphic/locatorGenerators");
11
- /**
12
- * Copyright (c) Microsoft Corporation.
13
- *
14
- * Licensed under the Apache License, Version 2.0 (the "License");
15
- * you may not use this file except in compliance with the License.
16
- * You may obtain a copy of the License at
17
- *
18
- * http://www.apache.org/licenses/LICENSE-2.0
19
- *
20
- * Unless required by applicable law or agreed to in writing, software
21
- * distributed under the License is distributed on an "AS IS" BASIS,
22
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23
- * See the License for the specific language governing permissions and
24
- * limitations under the License.
25
- */
26
-
27
- const deviceDescriptors = require('../deviceDescriptorsSource.json');
28
- class JavaScriptLanguageGenerator {
29
- constructor(isTest) {
30
- this.id = void 0;
31
- this.groupName = 'Node.js';
32
- this.name = void 0;
33
- this.highlighter = 'javascript';
34
- this._isTest = void 0;
35
- this.id = isTest ? 'playwright-test' : 'javascript';
36
- this.name = isTest ? 'Test Runner' : 'Library';
37
- this._isTest = isTest;
38
- }
39
- generateAction(actionInContext) {
40
- const action = actionInContext.action;
41
- if (this._isTest && (action.name === 'openPage' || action.name === 'closePage')) return '';
42
- const pageAlias = actionInContext.frame.pageAlias;
43
- const formatter = new JavaScriptFormatter(2);
44
- if (action.name === 'openPage') {
45
- formatter.add(`const ${pageAlias} = await context.newPage();`);
46
- if (action.url && action.url !== 'about:blank' && action.url !== 'chrome://newtab/') formatter.add(`await ${pageAlias}.goto(${quote(action.url)});`);
47
- return formatter.format();
48
- }
49
- let subject;
50
- if (actionInContext.frame.isMainFrame) {
51
- subject = pageAlias;
52
- } else {
53
- const locators = actionInContext.frame.selectorsChain.map(selector => `.frameLocator(${quote(selector)})`);
54
- subject = `${pageAlias}${locators.join('')}`;
55
- }
56
- const signals = (0, _language.toSignalMap)(action);
57
- if (signals.dialog) {
58
- formatter.add(` ${pageAlias}.once('dialog', dialog => {
59
- console.log(\`Dialog message: $\{dialog.message()}\`);
60
- dialog.dismiss().catch(() => {});
61
- });`);
62
- }
63
- if (signals.popup) formatter.add(`const ${signals.popup.popupAlias}Promise = ${pageAlias}.waitForEvent('popup');`);
64
- if (signals.download) formatter.add(`const download${signals.download.downloadAlias}Promise = ${pageAlias}.waitForEvent('download');`);
65
- formatter.add(this._generateActionCall(subject, action));
66
- if (signals.popup) formatter.add(`const ${signals.popup.popupAlias} = await ${signals.popup.popupAlias}Promise;`);
67
- if (signals.download) formatter.add(`const download${signals.download.downloadAlias} = await download${signals.download.downloadAlias}Promise;`);
68
- return formatter.format();
69
- }
70
- _generateActionCall(subject, action) {
71
- switch (action.name) {
72
- case 'openPage':
73
- throw Error('Not reached');
74
- case 'closePage':
75
- return `await ${subject}.close();`;
76
- case 'click':
77
- {
78
- let method = 'click';
79
- if (action.clickCount === 2) method = 'dblclick';
80
- const modifiers = (0, _utils.toModifiers)(action.modifiers);
81
- const options = {};
82
- if (action.button !== 'left') options.button = action.button;
83
- if (modifiers.length) options.modifiers = modifiers;
84
- if (action.clickCount > 2) options.clickCount = action.clickCount;
85
- if (action.position) options.position = action.position;
86
- const optionsString = formatOptions(options, false);
87
- return `await ${subject}.${this._asLocator(action.selector)}.${method}(${optionsString});`;
88
- }
89
- case 'check':
90
- return `await ${subject}.${this._asLocator(action.selector)}.check();`;
91
- case 'uncheck':
92
- return `await ${subject}.${this._asLocator(action.selector)}.uncheck();`;
93
- case 'fill':
94
- return `await ${subject}.${this._asLocator(action.selector)}.fill(${quote(action.text)});`;
95
- case 'setInputFiles':
96
- return `await ${subject}.${this._asLocator(action.selector)}.setInputFiles(${formatObject(action.files.length === 1 ? action.files[0] : action.files)});`;
97
- case 'press':
98
- {
99
- const modifiers = (0, _utils.toModifiers)(action.modifiers);
100
- const shortcut = [...modifiers, action.key].join('+');
101
- return `await ${subject}.${this._asLocator(action.selector)}.press(${quote(shortcut)});`;
102
- }
103
- case 'navigate':
104
- return `await ${subject}.goto(${quote(action.url)});`;
105
- case 'select':
106
- return `await ${subject}.${this._asLocator(action.selector)}.selectOption(${formatObject(action.options.length > 1 ? action.options : action.options[0])});`;
107
- case 'assertText':
108
- return `${this._isTest ? '' : '// '}await expect(${subject}.${this._asLocator(action.selector)}).${action.substring ? 'toContainText' : 'toHaveText'}(${quote(action.text)});`;
109
- case 'assertChecked':
110
- return `${this._isTest ? '' : '// '}await expect(${subject}.${this._asLocator(action.selector)})${action.checked ? '' : '.not'}.toBeChecked();`;
111
- case 'assertVisible':
112
- return `${this._isTest ? '' : '// '}await expect(${subject}.${this._asLocator(action.selector)}).toBeVisible();`;
113
- case 'assertValue':
114
- {
115
- const assertion = action.value ? `toHaveValue(${quote(action.value)})` : `toBeEmpty()`;
116
- return `${this._isTest ? '' : '// '}await expect(${subject}.${this._asLocator(action.selector)}).${assertion};`;
117
- }
118
- }
119
- }
120
- _asLocator(selector) {
121
- return (0, _locatorGenerators.asLocator)('javascript', selector);
122
- }
123
- generateHeader(options) {
124
- if (this._isTest) return this.generateTestHeader(options);
125
- return this.generateStandaloneHeader(options);
126
- }
127
- generateFooter(saveStorage) {
128
- if (this._isTest) return this.generateTestFooter(saveStorage);
129
- return this.generateStandaloneFooter(saveStorage);
130
- }
131
- generateTestHeader(options) {
132
- const formatter = new JavaScriptFormatter();
133
- const useText = formatContextOptions(options.contextOptions, options.deviceName);
134
- formatter.add(`
135
- import { test, expect${options.deviceName ? ', devices' : ''} } from '@playwright/test';
136
- ${useText ? '\ntest.use(' + useText + ');\n' : ''}
137
- test('test', async ({ page }) => {`);
138
- return formatter.format();
139
- }
140
- generateTestFooter(saveStorage) {
141
- return `});`;
142
- }
143
- generateStandaloneHeader(options) {
144
- const formatter = new JavaScriptFormatter();
145
- formatter.add(`
146
- const { ${options.browserName}${options.deviceName ? ', devices' : ''} } = require('playwright');
147
-
148
- (async () => {
149
- const browser = await ${options.browserName}.launch(${formatObjectOrVoid(options.launchOptions)});
150
- const context = await browser.newContext(${formatContextOptions(options.contextOptions, options.deviceName)});`);
151
- return formatter.format();
152
- }
153
- generateStandaloneFooter(saveStorage) {
154
- const storageStateLine = saveStorage ? `\n await context.storageState({ path: ${quote(saveStorage)} });` : '';
155
- return `\n // ---------------------${storageStateLine}
156
- await context.close();
157
- await browser.close();
158
- })();`;
159
- }
160
- }
161
- exports.JavaScriptLanguageGenerator = JavaScriptLanguageGenerator;
162
- function formatOptions(value, hasArguments) {
163
- const keys = Object.keys(value);
164
- if (!keys.length) return '';
165
- return (hasArguments ? ', ' : '') + formatObject(value);
166
- }
167
- function formatObject(value, indent = ' ') {
168
- if (typeof value === 'string') return quote(value);
169
- if (Array.isArray(value)) return `[${value.map(o => formatObject(o)).join(', ')}]`;
170
- if (typeof value === 'object') {
171
- const keys = Object.keys(value).filter(key => value[key] !== undefined).sort();
172
- if (!keys.length) return '{}';
173
- const tokens = [];
174
- for (const key of keys) tokens.push(`${key}: ${formatObject(value[key])}`);
175
- return `{\n${indent}${tokens.join(`,\n${indent}`)}\n}`;
176
- }
177
- return String(value);
178
- }
179
- function formatObjectOrVoid(value, indent = ' ') {
180
- const result = formatObject(value, indent);
181
- return result === '{}' ? '' : result;
182
- }
183
- function formatContextOptions(options, deviceName) {
184
- const device = deviceName && deviceDescriptors[deviceName];
185
- if (!device) return formatObjectOrVoid(options);
186
- // Filter out all the properties from the device descriptor.
187
- let serializedObject = formatObjectOrVoid((0, _language.sanitizeDeviceOptions)(device, options));
188
- // When there are no additional context options, we still want to spread the device inside.
189
- if (!serializedObject) serializedObject = '{\n}';
190
- const lines = serializedObject.split('\n');
191
- lines.splice(1, 0, `...devices[${quote(deviceName)}],`);
192
- return lines.join('\n');
193
- }
194
- class JavaScriptFormatter {
195
- constructor(offset = 0) {
196
- this._baseIndent = void 0;
197
- this._baseOffset = void 0;
198
- this._lines = [];
199
- this._baseIndent = ' '.repeat(2);
200
- this._baseOffset = ' '.repeat(offset);
201
- }
202
- prepend(text) {
203
- this._lines = text.trim().split('\n').map(line => line.trim()).concat(this._lines);
204
- }
205
- add(text) {
206
- this._lines.push(...text.trim().split('\n').map(line => line.trim()));
207
- }
208
- newLine() {
209
- this._lines.push('');
210
- }
211
- format() {
212
- let spaces = '';
213
- let previousLine = '';
214
- return this._lines.map(line => {
215
- if (line === '') return line;
216
- if (line.startsWith('}') || line.startsWith(']')) spaces = spaces.substring(this._baseIndent.length);
217
- const extraSpaces = /^(for|while|if|try).*\(.*\)$/.test(previousLine) ? this._baseIndent : '';
218
- previousLine = line;
219
- const callCarryOver = line.startsWith('.set');
220
- line = spaces + extraSpaces + (callCarryOver ? this._baseIndent : '') + line;
221
- if (line.endsWith('{') || line.endsWith('[')) spaces += this._baseIndent;
222
- return this._baseOffset + line;
223
- }).join('\n');
224
- }
225
- }
226
- exports.JavaScriptFormatter = JavaScriptFormatter;
227
- function quote(text) {
228
- return (0, _stringUtils.escapeWithQuotes)(text, '\'');
229
- }
230
- //# sourceMappingURL=javascript.js.map
@@ -1,48 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.JsonlLanguageGenerator = void 0;
7
- var _locatorGenerators = require("../../utils/isomorphic/locatorGenerators");
8
- /**
9
- * Copyright (c) Microsoft Corporation.
10
- *
11
- * Licensed under the Apache License, Version 2.0 (the "License");
12
- * you may not use this file except in compliance with the License.
13
- * You may obtain a copy of the License at
14
- *
15
- * http://www.apache.org/licenses/LICENSE-2.0
16
- *
17
- * Unless required by applicable law or agreed to in writing, software
18
- * distributed under the License is distributed on an "AS IS" BASIS,
19
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
- * See the License for the specific language governing permissions and
21
- * limitations under the License.
22
- */
23
-
24
- class JsonlLanguageGenerator {
25
- constructor() {
26
- this.id = 'jsonl';
27
- this.groupName = '';
28
- this.name = 'JSONL';
29
- this.highlighter = 'javascript';
30
- }
31
- generateAction(actionInContext) {
32
- const locator = actionInContext.action.selector ? JSON.parse((0, _locatorGenerators.asLocator)('jsonl', actionInContext.action.selector)) : undefined;
33
- const entry = {
34
- ...actionInContext.action,
35
- pageAlias: actionInContext.frame.pageAlias,
36
- locator
37
- };
38
- return JSON.stringify(entry);
39
- }
40
- generateHeader(options) {
41
- return JSON.stringify(options);
42
- }
43
- generateFooter(saveStorage) {
44
- return '';
45
- }
46
- }
47
- exports.JsonlLanguageGenerator = JsonlLanguageGenerator;
48
- //# sourceMappingURL=jsonl.js.map
@@ -1,45 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.sanitizeDeviceOptions = sanitizeDeviceOptions;
7
- exports.toSignalMap = toSignalMap;
8
- /**
9
- * Copyright (c) Microsoft Corporation.
10
- *
11
- * Licensed under the Apache License, Version 2.0 (the "License");
12
- * you may not use this file except in compliance with the License.
13
- * You may obtain a copy of the License at
14
- *
15
- * http://www.apache.org/licenses/LICENSE-2.0
16
- *
17
- * Unless required by applicable law or agreed to in writing, software
18
- * distributed under the License is distributed on an "AS IS" BASIS,
19
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
- * See the License for the specific language governing permissions and
21
- * limitations under the License.
22
- */
23
-
24
- function sanitizeDeviceOptions(device, options) {
25
- // Filter out all the properties from the device descriptor.
26
- const cleanedOptions = {};
27
- for (const property in options) {
28
- if (JSON.stringify(device[property]) !== JSON.stringify(options[property])) cleanedOptions[property] = options[property];
29
- }
30
- return cleanedOptions;
31
- }
32
- function toSignalMap(action) {
33
- let popup;
34
- let download;
35
- let dialog;
36
- for (const signal of action.signals) {
37
- if (signal.name === 'popup') popup = signal;else if (signal.name === 'download') download = signal;else if (signal.name === 'dialog') dialog = signal;
38
- }
39
- return {
40
- popup,
41
- download,
42
- dialog
43
- };
44
- }
45
- //# sourceMappingURL=language.js.map
@@ -1,276 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.PythonLanguageGenerator = void 0;
7
- var _language = require("./language");
8
- var _utils = require("./utils");
9
- var _stringUtils = require("../../utils/isomorphic/stringUtils");
10
- var _locatorGenerators = require("../../utils/isomorphic/locatorGenerators");
11
- /**
12
- * Copyright (c) Microsoft Corporation.
13
- *
14
- * Licensed under the Apache License, Version 2.0 (the "License");
15
- * you may not use this file except in compliance with the License.
16
- * You may obtain a copy of the License at
17
- *
18
- * http://www.apache.org/licenses/LICENSE-2.0
19
- *
20
- * Unless required by applicable law or agreed to in writing, software
21
- * distributed under the License is distributed on an "AS IS" BASIS,
22
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23
- * See the License for the specific language governing permissions and
24
- * limitations under the License.
25
- */
26
-
27
- const deviceDescriptors = require('../deviceDescriptorsSource.json');
28
- class PythonLanguageGenerator {
29
- constructor(isAsync, isPyTest) {
30
- this.id = void 0;
31
- this.groupName = 'Python';
32
- this.name = void 0;
33
- this.highlighter = 'python';
34
- this._awaitPrefix = void 0;
35
- this._asyncPrefix = void 0;
36
- this._isAsync = void 0;
37
- this._isPyTest = void 0;
38
- this.id = isPyTest ? 'python-pytest' : isAsync ? 'python-async' : 'python';
39
- this.name = isPyTest ? 'Pytest' : isAsync ? 'Library Async' : 'Library';
40
- this._isAsync = isAsync;
41
- this._isPyTest = isPyTest;
42
- this._awaitPrefix = isAsync ? 'await ' : '';
43
- this._asyncPrefix = isAsync ? 'async ' : '';
44
- }
45
- generateAction(actionInContext) {
46
- const action = actionInContext.action;
47
- if (this._isPyTest && (action.name === 'openPage' || action.name === 'closePage')) return '';
48
- const pageAlias = actionInContext.frame.pageAlias;
49
- const formatter = new PythonFormatter(4);
50
- if (action.name === 'openPage') {
51
- formatter.add(`${pageAlias} = ${this._awaitPrefix}context.new_page()`);
52
- if (action.url && action.url !== 'about:blank' && action.url !== 'chrome://newtab/') formatter.add(`${this._awaitPrefix}${pageAlias}.goto(${quote(action.url)})`);
53
- return formatter.format();
54
- }
55
- let subject;
56
- if (actionInContext.frame.isMainFrame) {
57
- subject = pageAlias;
58
- } else {
59
- const locators = actionInContext.frame.selectorsChain.map(selector => `.frame_locator(${quote(selector)})`);
60
- subject = `${pageAlias}${locators.join('')}`;
61
- }
62
- const signals = (0, _language.toSignalMap)(action);
63
- if (signals.dialog) formatter.add(` ${pageAlias}.once("dialog", lambda dialog: dialog.dismiss())`);
64
- let code = `${this._awaitPrefix}${this._generateActionCall(subject, action)}`;
65
- if (signals.popup) {
66
- code = `${this._asyncPrefix}with ${pageAlias}.expect_popup() as ${signals.popup.popupAlias}_info {
67
- ${code}
68
- }
69
- ${signals.popup.popupAlias} = ${this._awaitPrefix}${signals.popup.popupAlias}_info.value`;
70
- }
71
- if (signals.download) {
72
- code = `${this._asyncPrefix}with ${pageAlias}.expect_download() as download${signals.download.downloadAlias}_info {
73
- ${code}
74
- }
75
- download${signals.download.downloadAlias} = ${this._awaitPrefix}download${signals.download.downloadAlias}_info.value`;
76
- }
77
- formatter.add(code);
78
- return formatter.format();
79
- }
80
- _generateActionCall(subject, action) {
81
- switch (action.name) {
82
- case 'openPage':
83
- throw Error('Not reached');
84
- case 'closePage':
85
- return `${subject}.close()`;
86
- case 'click':
87
- {
88
- let method = 'click';
89
- if (action.clickCount === 2) method = 'dblclick';
90
- const modifiers = (0, _utils.toModifiers)(action.modifiers);
91
- const options = {};
92
- if (action.button !== 'left') options.button = action.button;
93
- if (modifiers.length) options.modifiers = modifiers;
94
- if (action.clickCount > 2) options.clickCount = action.clickCount;
95
- if (action.position) options.position = action.position;
96
- const optionsString = formatOptions(options, false);
97
- return `${subject}.${this._asLocator(action.selector)}.${method}(${optionsString})`;
98
- }
99
- case 'check':
100
- return `${subject}.${this._asLocator(action.selector)}.check()`;
101
- case 'uncheck':
102
- return `${subject}.${this._asLocator(action.selector)}.uncheck()`;
103
- case 'fill':
104
- return `${subject}.${this._asLocator(action.selector)}.fill(${quote(action.text)})`;
105
- case 'setInputFiles':
106
- return `${subject}.${this._asLocator(action.selector)}.set_input_files(${formatValue(action.files.length === 1 ? action.files[0] : action.files)})`;
107
- case 'press':
108
- {
109
- const modifiers = (0, _utils.toModifiers)(action.modifiers);
110
- const shortcut = [...modifiers, action.key].join('+');
111
- return `${subject}.${this._asLocator(action.selector)}.press(${quote(shortcut)})`;
112
- }
113
- case 'navigate':
114
- return `${subject}.goto(${quote(action.url)})`;
115
- case 'select':
116
- return `${subject}.${this._asLocator(action.selector)}.select_option(${formatValue(action.options.length === 1 ? action.options[0] : action.options)})`;
117
- case 'assertText':
118
- return `expect(${subject}.${this._asLocator(action.selector)}).${action.substring ? 'to_contain_text' : 'to_have_text'}(${quote(action.text)})`;
119
- case 'assertChecked':
120
- return `expect(${subject}.${this._asLocator(action.selector)}).${action.checked ? 'to_be_checked()' : 'not_to_be_checked()'}`;
121
- case 'assertVisible':
122
- return `expect(${subject}.${this._asLocator(action.selector)}).to_be_visible()`;
123
- case 'assertValue':
124
- {
125
- const assertion = action.value ? `to_have_value(${quote(action.value)})` : `to_be_empty()`;
126
- return `expect(${subject}.${this._asLocator(action.selector)}).${assertion};`;
127
- }
128
- }
129
- }
130
- _asLocator(selector) {
131
- return (0, _locatorGenerators.asLocator)('python', selector);
132
- }
133
- generateHeader(options) {
134
- const formatter = new PythonFormatter();
135
- if (this._isPyTest) {
136
- const contextOptions = formatContextOptions(options.contextOptions, options.deviceName, true /* asDict */);
137
- const fixture = contextOptions ? `
138
-
139
- @pytest.fixture(scope="session")
140
- def browser_context_args(browser_context_args, playwright) {
141
- return {${contextOptions}}
142
- }
143
- ` : '';
144
- formatter.add(`${options.deviceName ? 'import pytest\n' : ''}
145
- from playwright.sync_api import Page, expect
146
- ${fixture}
147
-
148
- def test_example(page: Page) -> None {`);
149
- } else if (this._isAsync) {
150
- formatter.add(`
151
- import asyncio
152
-
153
- from playwright.async_api import Playwright, async_playwright, expect
154
-
155
-
156
- async def run(playwright: Playwright) -> None {
157
- browser = await playwright.${options.browserName}.launch(${formatOptions(options.launchOptions, false)})
158
- context = await browser.new_context(${formatContextOptions(options.contextOptions, options.deviceName)})`);
159
- } else {
160
- formatter.add(`
161
- from playwright.sync_api import Playwright, sync_playwright, expect
162
-
163
-
164
- def run(playwright: Playwright) -> None {
165
- browser = playwright.${options.browserName}.launch(${formatOptions(options.launchOptions, false)})
166
- context = browser.new_context(${formatContextOptions(options.contextOptions, options.deviceName)})`);
167
- }
168
- return formatter.format();
169
- }
170
- generateFooter(saveStorage) {
171
- if (this._isPyTest) {
172
- return '';
173
- } else if (this._isAsync) {
174
- const storageStateLine = saveStorage ? `\n await context.storage_state(path=${quote(saveStorage)})` : '';
175
- return `\n # ---------------------${storageStateLine}
176
- await context.close()
177
- await browser.close()
178
-
179
-
180
- async def main() -> None:
181
- async with async_playwright() as playwright:
182
- await run(playwright)
183
-
184
-
185
- asyncio.run(main())
186
- `;
187
- } else {
188
- const storageStateLine = saveStorage ? `\n context.storage_state(path=${quote(saveStorage)})` : '';
189
- return `\n # ---------------------${storageStateLine}
190
- context.close()
191
- browser.close()
192
-
193
-
194
- with sync_playwright() as playwright:
195
- run(playwright)
196
- `;
197
- }
198
- }
199
- }
200
- exports.PythonLanguageGenerator = PythonLanguageGenerator;
201
- function formatValue(value) {
202
- if (value === false) return 'False';
203
- if (value === true) return 'True';
204
- if (value === undefined) return 'None';
205
- if (Array.isArray(value)) return `[${value.map(formatValue).join(', ')}]`;
206
- if (typeof value === 'string') return quote(value);
207
- if (typeof value === 'object') return JSON.stringify(value);
208
- return String(value);
209
- }
210
- function formatOptions(value, hasArguments, asDict) {
211
- const keys = Object.keys(value).filter(key => value[key] !== undefined).sort();
212
- if (!keys.length) return '';
213
- return (hasArguments ? ', ' : '') + keys.map(key => {
214
- if (asDict) return `"${(0, _stringUtils.toSnakeCase)(key)}": ${formatValue(value[key])}`;
215
- return `${(0, _stringUtils.toSnakeCase)(key)}=${formatValue(value[key])}`;
216
- }).join(', ');
217
- }
218
- function convertContextOptions(options) {
219
- const result = {
220
- ...options
221
- };
222
- if (options.recordHar) {
223
- result['record_har_path'] = options.recordHar.path;
224
- result['record_har_content'] = options.recordHar.content;
225
- result['record_har_mode'] = options.recordHar.mode;
226
- result['record_har_omit_content'] = options.recordHar.omitContent;
227
- result['record_har_url_filter'] = options.recordHar.urlFilter;
228
- delete result.recordHar;
229
- }
230
- return result;
231
- }
232
- function formatContextOptions(options, deviceName, asDict) {
233
- const device = deviceName && deviceDescriptors[deviceName];
234
- if (!device) return formatOptions(convertContextOptions(options), false, asDict);
235
- return `**playwright.devices[${quote(deviceName)}]` + formatOptions(convertContextOptions((0, _language.sanitizeDeviceOptions)(device, options)), true, asDict);
236
- }
237
- class PythonFormatter {
238
- constructor(offset = 0) {
239
- this._baseIndent = void 0;
240
- this._baseOffset = void 0;
241
- this._lines = [];
242
- this._baseIndent = ' '.repeat(4);
243
- this._baseOffset = ' '.repeat(offset);
244
- }
245
- prepend(text) {
246
- this._lines = text.trim().split('\n').map(line => line.trim()).concat(this._lines);
247
- }
248
- add(text) {
249
- this._lines.push(...text.trim().split('\n').map(line => line.trim()));
250
- }
251
- newLine() {
252
- this._lines.push('');
253
- }
254
- format() {
255
- let spaces = '';
256
- const lines = [];
257
- this._lines.forEach(line => {
258
- if (line === '') return lines.push(line);
259
- if (line === '}') {
260
- spaces = spaces.substring(this._baseIndent.length);
261
- return;
262
- }
263
- line = spaces + line;
264
- if (line.endsWith('{')) {
265
- spaces += this._baseIndent;
266
- line = line.substring(0, line.length - 1).trimEnd() + ':';
267
- }
268
- return lines.push(this._baseOffset + line);
269
- });
270
- return lines.join('\n');
271
- }
272
- }
273
- function quote(text) {
274
- return (0, _stringUtils.escapeWithQuotes)(text, '\"');
275
- }
276
- //# sourceMappingURL=python.js.map
@@ -1,6 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- //# sourceMappingURL=recorderActions.js.map
@@ -1,46 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.toClickOptions = toClickOptions;
7
- exports.toModifiers = toModifiers;
8
- /**
9
- * Copyright (c) Microsoft Corporation.
10
- *
11
- * Licensed under the Apache License, Version 2.0 (the "License");
12
- * you may not use this file except in compliance with the License.
13
- * You may obtain a copy of the License at
14
- *
15
- * http://www.apache.org/licenses/LICENSE-2.0
16
- *
17
- * Unless required by applicable law or agreed to in writing, software
18
- * distributed under the License is distributed on an "AS IS" BASIS,
19
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
- * See the License for the specific language governing permissions and
21
- * limitations under the License.
22
- */
23
-
24
- function toClickOptions(action) {
25
- let method = 'click';
26
- if (action.clickCount === 2) method = 'dblclick';
27
- const modifiers = toModifiers(action.modifiers);
28
- const options = {};
29
- if (action.button !== 'left') options.button = action.button;
30
- if (modifiers.length) options.modifiers = modifiers;
31
- if (action.clickCount > 2) options.clickCount = action.clickCount;
32
- if (action.position) options.position = action.position;
33
- return {
34
- method,
35
- options
36
- };
37
- }
38
- function toModifiers(modifiers) {
39
- const result = [];
40
- if (modifiers & 1) result.push('Alt');
41
- if (modifiers & 2) result.push('Control');
42
- if (modifiers & 4) result.push('Meta');
43
- if (modifiers & 8) result.push('Shift');
44
- return result;
45
- }
46
- //# sourceMappingURL=utils.js.map