@checkly/playwright-core 1.42.18 → 1.47.20-alpha
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.
- package/ThirdPartyNotices.txt +144 -109
- package/browsers.json +15 -25
- package/lib/androidServerImpl.js +1 -1
- package/lib/browserServerImpl.js +1 -1
- package/lib/cli/driver.js +1 -3
- package/lib/cli/program.js +5 -10
- package/lib/client/android.js +1 -1
- package/lib/client/api.js +7 -0
- package/lib/client/browserContext.js +37 -5
- package/lib/client/browserType.js +19 -11
- package/lib/client/channelOwner.js +19 -16
- package/lib/client/clientInstrumentation.js +17 -7
- package/lib/client/clock.js +68 -0
- package/lib/client/connection.js +9 -6
- package/lib/client/electron.js +7 -5
- package/lib/client/elementHandle.js +44 -14
- package/lib/client/eventEmitter.js +314 -0
- package/lib/client/fetch.js +81 -28
- package/lib/client/frame.js +2 -4
- package/lib/client/jsHandle.js +7 -1
- package/lib/client/locator.js +9 -0
- package/lib/client/network.js +12 -9
- package/lib/client/page.js +45 -23
- package/lib/client/playwright.js +3 -0
- package/lib/client/tracing.js +7 -4
- package/lib/common/socksProxy.js +2 -2
- package/lib/generated/clockSource.js +7 -0
- package/lib/generated/injectedScriptSource.js +1 -1
- package/lib/generated/recorderSource.js +1 -1
- package/lib/generated/utilityScriptSource.js +1 -1
- package/lib/protocol/serializers.js +12 -11
- package/lib/protocol/validator.js +137 -55
- package/lib/server/bidi/bidiBrowser.js +296 -0
- package/lib/server/bidi/bidiConnection.js +206 -0
- package/lib/server/bidi/bidiExecutionContext.js +162 -0
- package/lib/server/bidi/bidiFirefox.js +110 -0
- package/lib/server/bidi/bidiInput.js +174 -0
- package/lib/server/bidi/bidiNetworkManager.js +304 -0
- package/lib/server/bidi/bidiPage.js +456 -0
- package/lib/server/bidi/third_party/bidiDeserializer.js +93 -0
- package/lib/server/bidi/third_party/bidiKeyboard.js +238 -0
- package/lib/server/bidi/third_party/bidiProtocol.js +139 -0
- package/lib/server/bidi/third_party/bidiSerializer.js +144 -0
- package/lib/server/browser.js +9 -1
- package/lib/server/browserContext.js +97 -22
- package/lib/server/browserType.js +27 -20
- package/lib/server/chromium/chromium.js +30 -15
- package/lib/server/chromium/chromiumSwitches.js +6 -3
- package/lib/server/chromium/crBrowser.js +11 -17
- package/lib/server/chromium/crConnection.js +2 -2
- package/lib/server/chromium/crDragDrop.js +28 -29
- package/lib/server/chromium/crNetworkManager.js +130 -84
- package/lib/server/chromium/crPage.js +34 -79
- package/lib/server/chromium/crProtocolHelper.js +3 -1
- package/lib/server/chromium/crServiceWorker.js +20 -23
- package/lib/server/chromium/videoRecorder.js +1 -1
- package/lib/server/clock.js +125 -0
- package/lib/server/codegen/csharp.js +299 -0
- package/lib/server/codegen/java.js +235 -0
- package/lib/server/codegen/javascript.js +223 -0
- package/lib/server/codegen/jsonl.js +47 -0
- package/lib/server/codegen/language.js +76 -0
- package/lib/server/codegen/languages.js +30 -0
- package/lib/server/codegen/python.js +265 -0
- package/lib/server/codegen/types.js +5 -0
- package/lib/server/debugController.js +3 -5
- package/lib/server/deviceDescriptors.js +9 -4
- package/lib/server/deviceDescriptorsSource.json +239 -119
- package/lib/server/dispatchers/androidDispatcher.js +1 -1
- package/lib/server/dispatchers/browserContextDispatcher.js +51 -7
- package/lib/server/dispatchers/dispatcher.js +36 -40
- package/lib/server/dispatchers/frameDispatcher.js +1 -2
- package/lib/server/dispatchers/jsHandleDispatcher.js +1 -1
- package/lib/server/dispatchers/jsonPipeDispatcher.js +4 -6
- package/lib/server/dispatchers/localUtilsDispatcher.js +19 -5
- package/lib/server/dispatchers/networkDispatchers.js +2 -2
- package/lib/server/dispatchers/pageDispatcher.js +5 -2
- package/lib/server/dispatchers/playwrightDispatcher.js +1 -0
- package/lib/server/dispatchers/writableStreamDispatcher.js +8 -5
- package/lib/server/dom.js +90 -53
- package/lib/server/electron/electron.js +21 -4
- package/lib/server/fetch.js +74 -25
- package/lib/server/fileUploadUtils.js +7 -3
- package/lib/server/firefox/ffBrowser.js +36 -25
- package/lib/server/firefox/ffConnection.js +2 -2
- package/lib/server/firefox/ffNetworkManager.js +6 -4
- package/lib/server/firefox/ffPage.js +22 -24
- package/lib/server/firefox/firefox.js +25 -6
- package/lib/server/frameSelectors.js +2 -2
- package/lib/server/frames.js +205 -159
- package/lib/server/har/harTracer.js +4 -12
- package/lib/server/helper.js +3 -3
- package/lib/server/index.js +18 -0
- package/lib/server/input.js +18 -8
- package/lib/server/instrumentation.js +0 -4
- package/lib/server/isomorphic/utilityScriptSerializers.js +19 -5
- package/lib/server/javascript.js +3 -2
- package/lib/server/launchApp.js +3 -2
- package/lib/server/network.js +14 -4
- package/lib/server/page.js +75 -46
- package/lib/server/playwright.js +5 -2
- package/lib/server/recorder/codeGenerator.js +2 -1
- package/lib/server/recorder/contextRecorder.js +316 -0
- package/lib/server/recorder/csharp.js +2 -1
- package/lib/server/recorder/java.js +2 -1
- package/lib/server/recorder/javascript.js +2 -1
- package/lib/server/recorder/jsonl.js +2 -1
- package/lib/server/recorder/language.js +2 -1
- package/lib/server/recorder/python.js +2 -1
- package/lib/server/recorder/recorderApp.js +14 -5
- package/lib/server/recorder/recorderCollection.js +127 -0
- package/lib/server/recorder/recorderRunner.js +177 -0
- package/lib/server/recorder/recorderUtils.js +23 -0
- package/lib/server/recorder/throttledFile.js +46 -0
- package/lib/server/recorder/utils.js +2 -1
- package/lib/server/recorder.js +42 -418
- package/lib/server/registry/index.js +99 -100
- package/lib/server/registry/nativeDeps.js +107 -0
- package/lib/server/screenshotter.js +6 -12
- package/lib/server/socksClientCertificatesInterceptor.js +328 -0
- package/lib/server/trace/recorder/snapshotter.js +4 -1
- package/lib/server/trace/recorder/tracing.js +27 -96
- package/lib/server/trace/viewer/traceViewer.js +54 -67
- package/lib/server/transport.js +1 -1
- package/lib/server/webkit/webkit.js +5 -5
- package/lib/server/webkit/wkBrowser.js +14 -14
- package/lib/server/webkit/wkConnection.js +3 -3
- package/lib/server/webkit/wkInterceptableRequest.js +8 -4
- package/lib/server/webkit/wkPage.js +52 -34
- package/lib/server/webkit/wkProvisionalPage.js +36 -1
- package/lib/utils/crypto.js +141 -0
- package/lib/utils/debugLogger.js +2 -0
- package/lib/utils/env.js +4 -2
- package/lib/utils/expectUtils.js +33 -0
- package/lib/utils/fileUtils.js +140 -1
- package/lib/utils/glob.js +2 -1
- package/lib/utils/happy-eyeballs.js +29 -2
- package/lib/utils/hostPlatform.js +13 -4
- package/lib/utils/httpServer.js +54 -13
- package/lib/utils/index.js +53 -31
- package/lib/utils/isomorphic/cssTokenizer.js +1 -1
- package/lib/utils/isomorphic/locatorParser.js +1 -1
- package/lib/utils/isomorphic/mimeType.js +29 -0
- package/lib/utils/isomorphic/stringUtils.js +28 -1
- package/lib/utils/isomorphic/urlMatch.js +120 -0
- package/lib/utils/mimeType.js +2 -1
- package/lib/utils/network.js +7 -35
- package/lib/utils/stackTrace.js +2 -4
- package/lib/utils/timeoutRunner.js +11 -76
- package/lib/utils/zones.js +23 -60
- package/lib/utilsBundle.js +2 -1
- package/lib/utilsBundleImpl/index.js +33 -31
- package/lib/vite/htmlReport/index.html +12 -12
- package/lib/vite/recorder/assets/codeMirrorModule-C-fQ5QZD.js +24 -0
- package/lib/vite/recorder/assets/{codicon-zGuYmc9o.ttf → codicon-DCmgc-ay.ttf} +0 -0
- package/lib/vite/recorder/assets/index-B-MT5gKo.css +1 -0
- package/lib/vite/recorder/assets/index-D-5S5PPN.js +47 -0
- package/lib/vite/recorder/index.html +2 -2
- package/lib/vite/traceViewer/assets/codeMirrorModule-5yiV-3wl.js +16831 -0
- package/lib/vite/traceViewer/assets/codeMirrorModule-B7Z3vq11.js +24 -0
- package/lib/vite/traceViewer/assets/codeMirrorModule-C6p3E9Zg.js +24 -0
- package/lib/vite/traceViewer/assets/codeMirrorModule-CqYUz5ms.js +24 -0
- package/lib/vite/traceViewer/assets/codeMirrorModule-Dx6AXgMV.js +16838 -0
- package/lib/vite/traceViewer/assets/codeMirrorModule-T_sdMrbM.js +24 -0
- package/lib/vite/traceViewer/assets/codeMirrorModule-V7N6ppkd.js +15585 -0
- package/lib/vite/traceViewer/assets/testServerConnection-D-tXL3sj.js +224 -0
- package/lib/vite/traceViewer/assets/testServerConnection-DeE2kSzz.js +1 -0
- package/lib/vite/traceViewer/assets/workbench-Bjkiwcr1.js +19119 -0
- package/lib/vite/traceViewer/assets/workbench-C43LWZEX.js +72 -0
- package/lib/vite/traceViewer/assets/workbench-C5OQh9VX.js +19119 -0
- package/lib/vite/traceViewer/assets/workbench-DrQjKdyE.js +72 -0
- package/lib/vite/traceViewer/assets/workbench-caTaZnzx.js +72 -0
- package/lib/vite/traceViewer/assets/workbench-u2lRPMOT.js +72 -0
- package/lib/vite/traceViewer/assets/wsPort-EUvw-dwH.js +18540 -0
- package/lib/vite/traceViewer/assets/xtermModule-CZ7sDYXB.js +6529 -0
- package/lib/vite/traceViewer/assets/xtermModule-_6TC5FYT.js +6529 -0
- package/lib/vite/traceViewer/codeMirrorModule.Cy8X9Wtw.css +344 -0
- package/lib/vite/traceViewer/codeMirrorModule.svF_VrcJ.css +344 -0
- package/lib/vite/traceViewer/codicon.DCmgc-ay.ttf +0 -0
- package/lib/vite/traceViewer/embedded.BQq6Psnz.js +104 -0
- package/lib/vite/traceViewer/embedded.BVDVQOzc.js +2 -0
- package/lib/vite/traceViewer/embedded.Bn8Ptzv6.js +2 -0
- package/lib/vite/traceViewer/embedded.CvhnUgIi.js +2 -0
- package/lib/vite/traceViewer/embedded.D27cnKiB.js +104 -0
- package/lib/vite/traceViewer/embedded.DPqrDeET.js +2 -0
- package/lib/vite/traceViewer/embedded.DjZq4InJ.css +68 -0
- package/lib/vite/traceViewer/embedded.html +16 -0
- package/lib/vite/traceViewer/embedded.w7WN2u1R.css +1 -0
- package/lib/vite/traceViewer/index.5mge2rY_.css +124 -0
- package/lib/vite/traceViewer/index.6KJ-JQ0L.js +180 -0
- package/lib/vite/traceViewer/index.B8dgQwuN.js +2 -0
- package/lib/vite/traceViewer/index.BGj8jY3H.js +2 -0
- package/lib/vite/traceViewer/index.C0EgJ4oW.js +195 -0
- package/lib/vite/traceViewer/index.CUpI-BFe.js +195 -0
- package/lib/vite/traceViewer/{index.-g_5lMbJ.css → index.CrbWWHbf.css} +1 -1
- package/lib/vite/traceViewer/index.QanXxRUb.css +131 -0
- package/lib/vite/traceViewer/index._cX8k4co.js +2 -0
- package/lib/vite/traceViewer/index.html +5 -4
- package/lib/vite/traceViewer/index.pMAN88y-.js +2 -0
- package/lib/vite/traceViewer/snapshot.html +1 -1
- package/lib/vite/traceViewer/sw.bundle.js +3 -4
- package/lib/vite/traceViewer/uiMode.D-tg1Oci.js +1730 -0
- package/lib/vite/traceViewer/uiMode.D3cNFP6u.css +1 -0
- package/lib/vite/traceViewer/uiMode.DKjMBMlc.js +1730 -0
- package/lib/vite/traceViewer/uiMode.DVWUEIHq.css +1424 -0
- package/lib/vite/traceViewer/uiMode.DVrL7a1K.js +10 -0
- package/lib/vite/traceViewer/uiMode.Dg9oJCQU.js +10 -0
- package/lib/vite/traceViewer/uiMode.DwZAzstF.js +10 -0
- package/lib/vite/traceViewer/uiMode.html +5 -4
- package/lib/vite/traceViewer/uiMode.iq7CyYy7.js +1490 -0
- package/lib/vite/traceViewer/uiMode.jY2s-9ps.js +10 -0
- package/lib/vite/traceViewer/uiMode.xvJHbkzl.css +1324 -0
- package/lib/vite/traceViewer/workbench.B3X2QtYa.css +3702 -0
- package/lib/vite/traceViewer/workbench.DyTpxWVb.css +1 -0
- package/lib/vite/traceViewer/wsPort.p5jUwABW.css +3450 -0
- package/lib/vite/traceViewer/xtermModule.4oRVGWQ-.css +209 -0
- package/lib/vite/traceViewer/xtermModule.OKEVRlkP.css +209 -0
- package/package.json +2 -2
- package/types/protocol.d.ts +960 -78
- package/types/structs.d.ts +1 -1
- package/types/types.d.ts +3083 -2448
- package/lib/vite/recorder/assets/codeMirrorModule-W69B4LBB.js +0 -24
- package/lib/vite/recorder/assets/index-Ly3PcVUb.js +0 -47
- package/lib/vite/recorder/assets/index-ljsTwXtJ.css +0 -1
- package/lib/vite/traceViewer/assets/codeMirrorModule-0bpaqixv.js +0 -24
- package/lib/vite/traceViewer/assets/codeMirrorModule-wLpsbIhd.js +0 -24
- package/lib/vite/traceViewer/assets/wsPort-_JBDEilC.js +0 -69
- package/lib/vite/traceViewer/assets/wsPort-f2dAQL4I.js +0 -69
- package/lib/vite/traceViewer/index.-_8-eHEE.js +0 -2
- package/lib/vite/traceViewer/index.u51inEcm.js +0 -2
- package/lib/vite/traceViewer/uiMode.9CwNsWc6.js +0 -10
- package/lib/vite/traceViewer/uiMode.Fb0bNA4H.js +0 -10
- package/lib/vite/traceViewer/uiMode.pWy0Re7G.css +0 -1
- package/lib/vite/traceViewer/wsPort.zR1WIy9-.css +0 -1
- /package/lib/vite/recorder/assets/{codeMirrorModule-Hs9-1ZG4.css → codeMirrorModule-ez37Vkbh.css} +0 -0
- /package/lib/vite/traceViewer/assets/{xtermModule-Yt6xwiJ_.js → xtermModule-BeNbaIVa.js} +0 -0
- /package/lib/vite/traceViewer/{codeMirrorModule.Hs9-1ZG4.css → codeMirrorModule.ez37Vkbh.css} +0 -0
- /package/lib/vite/traceViewer/{xtermModule.0lwXJFHT.css → xtermModule.DSXBckUd.css} +0 -0
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.CSharpLanguageGenerator = void 0;
|
|
7
|
+
var _language = require("./language");
|
|
8
|
+
var _utils = require("../../utils");
|
|
9
|
+
var _deviceDescriptors = require("../deviceDescriptors");
|
|
10
|
+
/**
|
|
11
|
+
* Copyright (c) Microsoft Corporation.
|
|
12
|
+
*
|
|
13
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
14
|
+
* you may not use this file except in compliance with the License.
|
|
15
|
+
* You may obtain a copy of the License at
|
|
16
|
+
*
|
|
17
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
18
|
+
*
|
|
19
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
20
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
21
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
22
|
+
* See the License for the specific language governing permissions and
|
|
23
|
+
* limitations under the License.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
class CSharpLanguageGenerator {
|
|
27
|
+
constructor(mode) {
|
|
28
|
+
this.id = void 0;
|
|
29
|
+
this.groupName = '.NET C#';
|
|
30
|
+
this.name = void 0;
|
|
31
|
+
this.highlighter = 'csharp';
|
|
32
|
+
this._mode = void 0;
|
|
33
|
+
if (mode === 'library') {
|
|
34
|
+
this.name = 'Library';
|
|
35
|
+
this.id = 'csharp';
|
|
36
|
+
} else if (mode === 'mstest') {
|
|
37
|
+
this.name = 'MSTest';
|
|
38
|
+
this.id = 'csharp-mstest';
|
|
39
|
+
} else if (mode === 'nunit') {
|
|
40
|
+
this.name = 'NUnit';
|
|
41
|
+
this.id = 'csharp-nunit';
|
|
42
|
+
} else {
|
|
43
|
+
throw new Error(`Unknown C# language mode: ${mode}`);
|
|
44
|
+
}
|
|
45
|
+
this._mode = mode;
|
|
46
|
+
}
|
|
47
|
+
generateAction(actionInContext) {
|
|
48
|
+
const action = this._generateActionInner(actionInContext);
|
|
49
|
+
if (action) return action;
|
|
50
|
+
return '';
|
|
51
|
+
}
|
|
52
|
+
_generateActionInner(actionInContext) {
|
|
53
|
+
const action = actionInContext.action;
|
|
54
|
+
if (this._mode !== 'library' && (action.name === 'openPage' || action.name === 'closePage')) return '';
|
|
55
|
+
let pageAlias = actionInContext.frame.pageAlias;
|
|
56
|
+
if (this._mode !== 'library') pageAlias = pageAlias.replace('page', 'Page');
|
|
57
|
+
const formatter = new CSharpFormatter(this._mode === 'library' ? 0 : 8);
|
|
58
|
+
if (action.name === 'openPage') {
|
|
59
|
+
formatter.add(`var ${pageAlias} = await context.NewPageAsync();`);
|
|
60
|
+
if (action.url && action.url !== 'about:blank' && action.url !== 'chrome://newtab/') formatter.add(`await ${pageAlias}.GotoAsync(${quote(action.url)});`);
|
|
61
|
+
return formatter.format();
|
|
62
|
+
}
|
|
63
|
+
const locators = actionInContext.frame.framePath.map(selector => `.${this._asLocator(selector)}.ContentFrame()`);
|
|
64
|
+
const subject = `${pageAlias}${locators.join('')}`;
|
|
65
|
+
const signals = (0, _language.toSignalMap)(action);
|
|
66
|
+
if (signals.dialog) {
|
|
67
|
+
formatter.add(` void ${pageAlias}_Dialog${signals.dialog.dialogAlias}_EventHandler(object sender, IDialog dialog)
|
|
68
|
+
{
|
|
69
|
+
Console.WriteLine($"Dialog message: {dialog.Message}");
|
|
70
|
+
dialog.DismissAsync();
|
|
71
|
+
${pageAlias}.Dialog -= ${pageAlias}_Dialog${signals.dialog.dialogAlias}_EventHandler;
|
|
72
|
+
}
|
|
73
|
+
${pageAlias}.Dialog += ${pageAlias}_Dialog${signals.dialog.dialogAlias}_EventHandler;`);
|
|
74
|
+
}
|
|
75
|
+
const lines = [];
|
|
76
|
+
lines.push(this._generateActionCall(subject, actionInContext));
|
|
77
|
+
if (signals.download) {
|
|
78
|
+
lines.unshift(`var download${signals.download.downloadAlias} = await ${pageAlias}.RunAndWaitForDownloadAsync(async () =>\n{`);
|
|
79
|
+
lines.push(`});`);
|
|
80
|
+
}
|
|
81
|
+
if (signals.popup) {
|
|
82
|
+
lines.unshift(`var ${signals.popup.popupAlias} = await ${pageAlias}.RunAndWaitForPopupAsync(async () =>\n{`);
|
|
83
|
+
lines.push(`});`);
|
|
84
|
+
}
|
|
85
|
+
for (const line of lines) formatter.add(line);
|
|
86
|
+
return formatter.format();
|
|
87
|
+
}
|
|
88
|
+
_generateActionCall(subject, actionInContext) {
|
|
89
|
+
const action = actionInContext.action;
|
|
90
|
+
switch (action.name) {
|
|
91
|
+
case 'openPage':
|
|
92
|
+
throw Error('Not reached');
|
|
93
|
+
case 'closePage':
|
|
94
|
+
return `await ${subject}.CloseAsync();`;
|
|
95
|
+
case 'click':
|
|
96
|
+
{
|
|
97
|
+
let method = 'Click';
|
|
98
|
+
if (action.clickCount === 2) method = 'DblClick';
|
|
99
|
+
const options = (0, _language.toClickOptions)(action);
|
|
100
|
+
if (!Object.entries(options).length) return `await ${subject}.${this._asLocator(action.selector)}.${method}Async();`;
|
|
101
|
+
const optionsString = formatObject(options, ' ', 'Locator' + method + 'Options');
|
|
102
|
+
return `await ${subject}.${this._asLocator(action.selector)}.${method}Async(${optionsString});`;
|
|
103
|
+
}
|
|
104
|
+
case 'check':
|
|
105
|
+
return `await ${subject}.${this._asLocator(action.selector)}.CheckAsync();`;
|
|
106
|
+
case 'uncheck':
|
|
107
|
+
return `await ${subject}.${this._asLocator(action.selector)}.UncheckAsync();`;
|
|
108
|
+
case 'fill':
|
|
109
|
+
return `await ${subject}.${this._asLocator(action.selector)}.FillAsync(${quote(action.text)});`;
|
|
110
|
+
case 'setInputFiles':
|
|
111
|
+
return `await ${subject}.${this._asLocator(action.selector)}.SetInputFilesAsync(${formatObject(action.files)});`;
|
|
112
|
+
case 'press':
|
|
113
|
+
{
|
|
114
|
+
const modifiers = (0, _language.toKeyboardModifiers)(action.modifiers);
|
|
115
|
+
const shortcut = [...modifiers, action.key].join('+');
|
|
116
|
+
return `await ${subject}.${this._asLocator(action.selector)}.PressAsync(${quote(shortcut)});`;
|
|
117
|
+
}
|
|
118
|
+
case 'navigate':
|
|
119
|
+
return `await ${subject}.GotoAsync(${quote(action.url)});`;
|
|
120
|
+
case 'select':
|
|
121
|
+
return `await ${subject}.${this._asLocator(action.selector)}.SelectOptionAsync(${formatObject(action.options)});`;
|
|
122
|
+
case 'assertText':
|
|
123
|
+
return `await Expect(${subject}.${this._asLocator(action.selector)}).${action.substring ? 'ToContainTextAsync' : 'ToHaveTextAsync'}(${quote(action.text)});`;
|
|
124
|
+
case 'assertChecked':
|
|
125
|
+
return `await Expect(${subject}.${this._asLocator(action.selector)})${action.checked ? '' : '.Not'}.ToBeCheckedAsync();`;
|
|
126
|
+
case 'assertVisible':
|
|
127
|
+
return `await Expect(${subject}.${this._asLocator(action.selector)}).ToBeVisibleAsync();`;
|
|
128
|
+
case 'assertValue':
|
|
129
|
+
{
|
|
130
|
+
const assertion = action.value ? `ToHaveValueAsync(${quote(action.value)})` : `ToBeEmptyAsync()`;
|
|
131
|
+
return `await Expect(${subject}.${this._asLocator(action.selector)}).${assertion};`;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
_asLocator(selector) {
|
|
136
|
+
return (0, _utils.asLocator)('csharp', selector);
|
|
137
|
+
}
|
|
138
|
+
generateHeader(options) {
|
|
139
|
+
if (this._mode === 'library') return this.generateStandaloneHeader(options);
|
|
140
|
+
return this.generateTestRunnerHeader(options);
|
|
141
|
+
}
|
|
142
|
+
generateStandaloneHeader(options) {
|
|
143
|
+
const formatter = new CSharpFormatter(0);
|
|
144
|
+
formatter.add(`
|
|
145
|
+
using Microsoft.Playwright;
|
|
146
|
+
using System;
|
|
147
|
+
using System.Threading.Tasks;
|
|
148
|
+
|
|
149
|
+
using var playwright = await Playwright.CreateAsync();
|
|
150
|
+
await using var browser = await playwright.${toPascal(options.browserName)}.LaunchAsync(${formatObject(options.launchOptions, ' ', 'BrowserTypeLaunchOptions')});
|
|
151
|
+
var context = await browser.NewContextAsync(${formatContextOptions(options.contextOptions, options.deviceName)});`);
|
|
152
|
+
formatter.newLine();
|
|
153
|
+
return formatter.format();
|
|
154
|
+
}
|
|
155
|
+
generateTestRunnerHeader(options) {
|
|
156
|
+
const formatter = new CSharpFormatter(0);
|
|
157
|
+
formatter.add(`
|
|
158
|
+
using Microsoft.Playwright.${this._mode === 'nunit' ? 'NUnit' : 'MSTest'};
|
|
159
|
+
using Microsoft.Playwright;
|
|
160
|
+
|
|
161
|
+
${this._mode === 'nunit' ? `[Parallelizable(ParallelScope.Self)]
|
|
162
|
+
[TestFixture]` : '[TestClass]'}
|
|
163
|
+
public class Tests : PageTest
|
|
164
|
+
{`);
|
|
165
|
+
const formattedContextOptions = formatContextOptions(options.contextOptions, options.deviceName);
|
|
166
|
+
if (formattedContextOptions) {
|
|
167
|
+
formatter.add(`public override BrowserNewContextOptions ContextOptions()
|
|
168
|
+
{
|
|
169
|
+
return ${formattedContextOptions};
|
|
170
|
+
}`);
|
|
171
|
+
formatter.newLine();
|
|
172
|
+
}
|
|
173
|
+
formatter.add(` [${this._mode === 'nunit' ? 'Test' : 'TestMethod'}]
|
|
174
|
+
public async Task MyTest()
|
|
175
|
+
{`);
|
|
176
|
+
return formatter.format();
|
|
177
|
+
}
|
|
178
|
+
generateFooter(saveStorage) {
|
|
179
|
+
const offset = this._mode === 'library' ? '' : ' ';
|
|
180
|
+
let storageStateLine = saveStorage ? `\n${offset}await context.StorageStateAsync(new BrowserContextStorageStateOptions\n${offset}{\n${offset} Path = ${quote(saveStorage)}\n${offset}});\n` : '';
|
|
181
|
+
if (this._mode !== 'library') storageStateLine += ` }\n}\n`;
|
|
182
|
+
return storageStateLine;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
exports.CSharpLanguageGenerator = CSharpLanguageGenerator;
|
|
186
|
+
function formatObject(value, indent = ' ', name = '') {
|
|
187
|
+
if (typeof value === 'string') {
|
|
188
|
+
if (['permissions', 'colorScheme', 'modifiers', 'button', 'recordHarContent', 'recordHarMode', 'serviceWorkers'].includes(name)) return `${getClassName(name)}.${toPascal(value)}`;
|
|
189
|
+
return quote(value);
|
|
190
|
+
}
|
|
191
|
+
if (Array.isArray(value)) return `new[] { ${value.map(o => formatObject(o, indent, name)).join(', ')} }`;
|
|
192
|
+
if (typeof value === 'object') {
|
|
193
|
+
const keys = Object.keys(value).filter(key => value[key] !== undefined).sort();
|
|
194
|
+
if (!keys.length) return name ? `new ${getClassName(name)}` : '';
|
|
195
|
+
const tokens = [];
|
|
196
|
+
for (const key of keys) {
|
|
197
|
+
const property = getPropertyName(key);
|
|
198
|
+
tokens.push(`${property} = ${formatObject(value[key], indent, key)},`);
|
|
199
|
+
}
|
|
200
|
+
if (name) return `new ${getClassName(name)}\n{\n${indent}${tokens.join(`\n${indent}`)}\n${indent}}`;
|
|
201
|
+
return `{\n${indent}${tokens.join(`\n${indent}`)}\n${indent}}`;
|
|
202
|
+
}
|
|
203
|
+
if (name === 'latitude' || name === 'longitude') return String(value) + 'm';
|
|
204
|
+
return String(value);
|
|
205
|
+
}
|
|
206
|
+
function getClassName(value) {
|
|
207
|
+
switch (value) {
|
|
208
|
+
case 'viewport':
|
|
209
|
+
return 'ViewportSize';
|
|
210
|
+
case 'proxy':
|
|
211
|
+
return 'ProxySettings';
|
|
212
|
+
case 'permissions':
|
|
213
|
+
return 'ContextPermission';
|
|
214
|
+
case 'modifiers':
|
|
215
|
+
return 'KeyboardModifier';
|
|
216
|
+
case 'button':
|
|
217
|
+
return 'MouseButton';
|
|
218
|
+
case 'recordHarMode':
|
|
219
|
+
return 'HarMode';
|
|
220
|
+
case 'recordHarContent':
|
|
221
|
+
return 'HarContentPolicy';
|
|
222
|
+
case 'serviceWorkers':
|
|
223
|
+
return 'ServiceWorkerPolicy';
|
|
224
|
+
default:
|
|
225
|
+
return toPascal(value);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
function getPropertyName(key) {
|
|
229
|
+
switch (key) {
|
|
230
|
+
case 'storageState':
|
|
231
|
+
return 'StorageStatePath';
|
|
232
|
+
case 'viewport':
|
|
233
|
+
return 'ViewportSize';
|
|
234
|
+
default:
|
|
235
|
+
return toPascal(key);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
function toPascal(value) {
|
|
239
|
+
return value[0].toUpperCase() + value.slice(1);
|
|
240
|
+
}
|
|
241
|
+
function convertContextOptions(options) {
|
|
242
|
+
const result = {
|
|
243
|
+
...options
|
|
244
|
+
};
|
|
245
|
+
if (options.recordHar) {
|
|
246
|
+
result['recordHarPath'] = options.recordHar.path;
|
|
247
|
+
result['recordHarContent'] = options.recordHar.content;
|
|
248
|
+
result['recordHarMode'] = options.recordHar.mode;
|
|
249
|
+
result['recordHarOmitContent'] = options.recordHar.omitContent;
|
|
250
|
+
result['recordHarUrlFilter'] = options.recordHar.urlFilter;
|
|
251
|
+
delete result.recordHar;
|
|
252
|
+
}
|
|
253
|
+
return result;
|
|
254
|
+
}
|
|
255
|
+
function formatContextOptions(options, deviceName) {
|
|
256
|
+
const device = deviceName && _deviceDescriptors.deviceDescriptors[deviceName];
|
|
257
|
+
if (!device) {
|
|
258
|
+
if (!Object.entries(options).length) return '';
|
|
259
|
+
return formatObject(convertContextOptions(options), ' ', 'BrowserNewContextOptions');
|
|
260
|
+
}
|
|
261
|
+
options = (0, _language.sanitizeDeviceOptions)(device, options);
|
|
262
|
+
if (!Object.entries(options).length) return `playwright.Devices[${quote(deviceName)}]`;
|
|
263
|
+
return formatObject(convertContextOptions(options), ' ', `BrowserNewContextOptions(playwright.Devices[${quote(deviceName)}])`);
|
|
264
|
+
}
|
|
265
|
+
class CSharpFormatter {
|
|
266
|
+
constructor(offset = 0) {
|
|
267
|
+
this._baseIndent = void 0;
|
|
268
|
+
this._baseOffset = void 0;
|
|
269
|
+
this._lines = [];
|
|
270
|
+
this._baseIndent = ' '.repeat(4);
|
|
271
|
+
this._baseOffset = ' '.repeat(offset);
|
|
272
|
+
}
|
|
273
|
+
prepend(text) {
|
|
274
|
+
this._lines = text.trim().split('\n').map(line => line.trim()).concat(this._lines);
|
|
275
|
+
}
|
|
276
|
+
add(text) {
|
|
277
|
+
this._lines.push(...text.trim().split('\n').map(line => line.trim()));
|
|
278
|
+
}
|
|
279
|
+
newLine() {
|
|
280
|
+
this._lines.push('');
|
|
281
|
+
}
|
|
282
|
+
format() {
|
|
283
|
+
let spaces = '';
|
|
284
|
+
let previousLine = '';
|
|
285
|
+
return this._lines.map(line => {
|
|
286
|
+
if (line === '') return line;
|
|
287
|
+
if (line.startsWith('}') || line.startsWith(']') || line.includes('});') || line === ');') spaces = spaces.substring(this._baseIndent.length);
|
|
288
|
+
const extraSpaces = /^(for|while|if).*\(.*\)$/.test(previousLine) ? this._baseIndent : '';
|
|
289
|
+
previousLine = line;
|
|
290
|
+
line = spaces + extraSpaces + line;
|
|
291
|
+
if (line.endsWith('{') || line.endsWith('[') || line.endsWith('(')) spaces += this._baseIndent;
|
|
292
|
+
if (line.endsWith('));')) spaces = spaces.substring(this._baseIndent.length);
|
|
293
|
+
return this._baseOffset + line;
|
|
294
|
+
}).join('\n');
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
function quote(text) {
|
|
298
|
+
return (0, _utils.escapeWithQuotes)(text, '\"');
|
|
299
|
+
}
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.JavaLanguageGenerator = void 0;
|
|
7
|
+
var _language = require("./language");
|
|
8
|
+
var _deviceDescriptors = require("../deviceDescriptors");
|
|
9
|
+
var _javascript = require("./javascript");
|
|
10
|
+
var _utils = require("../../utils");
|
|
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
|
+
class JavaLanguageGenerator {
|
|
28
|
+
constructor(mode) {
|
|
29
|
+
this.id = void 0;
|
|
30
|
+
this.groupName = 'Java';
|
|
31
|
+
this.name = void 0;
|
|
32
|
+
this.highlighter = 'java';
|
|
33
|
+
this._mode = void 0;
|
|
34
|
+
if (mode === 'library') {
|
|
35
|
+
this.name = 'Library';
|
|
36
|
+
this.id = 'java';
|
|
37
|
+
} else if (mode === 'junit') {
|
|
38
|
+
this.name = 'JUnit';
|
|
39
|
+
this.id = 'java-junit';
|
|
40
|
+
} else {
|
|
41
|
+
throw new Error(`Unknown Java language mode: ${mode}`);
|
|
42
|
+
}
|
|
43
|
+
this._mode = mode;
|
|
44
|
+
}
|
|
45
|
+
generateAction(actionInContext) {
|
|
46
|
+
const action = actionInContext.action;
|
|
47
|
+
const pageAlias = actionInContext.frame.pageAlias;
|
|
48
|
+
const offset = this._mode === 'junit' ? 4 : 6;
|
|
49
|
+
const formatter = new _javascript.JavaScriptFormatter(offset);
|
|
50
|
+
if (this._mode !== 'library' && (action.name === 'openPage' || action.name === 'closePage')) return '';
|
|
51
|
+
if (action.name === 'openPage') {
|
|
52
|
+
formatter.add(`Page ${pageAlias} = context.newPage();`);
|
|
53
|
+
if (action.url && action.url !== 'about:blank' && action.url !== 'chrome://newtab/') formatter.add(`${pageAlias}.navigate(${quote(action.url)});`);
|
|
54
|
+
return formatter.format();
|
|
55
|
+
}
|
|
56
|
+
const locators = actionInContext.frame.framePath.map(selector => `.${this._asLocator(selector, false)}.contentFrame()`);
|
|
57
|
+
const subject = `${pageAlias}${locators.join('')}`;
|
|
58
|
+
const signals = (0, _language.toSignalMap)(action);
|
|
59
|
+
if (signals.dialog) {
|
|
60
|
+
formatter.add(` ${pageAlias}.onceDialog(dialog -> {
|
|
61
|
+
System.out.println(String.format("Dialog message: %s", dialog.message()));
|
|
62
|
+
dialog.dismiss();
|
|
63
|
+
});`);
|
|
64
|
+
}
|
|
65
|
+
let code = this._generateActionCall(subject, actionInContext, !!actionInContext.frame.framePath.length);
|
|
66
|
+
if (signals.popup) {
|
|
67
|
+
code = `Page ${signals.popup.popupAlias} = ${pageAlias}.waitForPopup(() -> {
|
|
68
|
+
${code}
|
|
69
|
+
});`;
|
|
70
|
+
}
|
|
71
|
+
if (signals.download) {
|
|
72
|
+
code = `Download download${signals.download.downloadAlias} = ${pageAlias}.waitForDownload(() -> {
|
|
73
|
+
${code}
|
|
74
|
+
});`;
|
|
75
|
+
}
|
|
76
|
+
formatter.add(code);
|
|
77
|
+
return formatter.format();
|
|
78
|
+
}
|
|
79
|
+
_generateActionCall(subject, actionInContext, inFrameLocator) {
|
|
80
|
+
const action = actionInContext.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 options = (0, _language.toClickOptions)(action);
|
|
91
|
+
const optionsText = formatClickOptions(options);
|
|
92
|
+
return `${subject}.${this._asLocator(action.selector, inFrameLocator)}.${method}(${optionsText});`;
|
|
93
|
+
}
|
|
94
|
+
case 'check':
|
|
95
|
+
return `${subject}.${this._asLocator(action.selector, inFrameLocator)}.check();`;
|
|
96
|
+
case 'uncheck':
|
|
97
|
+
return `${subject}.${this._asLocator(action.selector, inFrameLocator)}.uncheck();`;
|
|
98
|
+
case 'fill':
|
|
99
|
+
return `${subject}.${this._asLocator(action.selector, inFrameLocator)}.fill(${quote(action.text)});`;
|
|
100
|
+
case 'setInputFiles':
|
|
101
|
+
return `${subject}.${this._asLocator(action.selector, inFrameLocator)}.setInputFiles(${formatPath(action.files.length === 1 ? action.files[0] : action.files)});`;
|
|
102
|
+
case 'press':
|
|
103
|
+
{
|
|
104
|
+
const modifiers = (0, _language.toKeyboardModifiers)(action.modifiers);
|
|
105
|
+
const shortcut = [...modifiers, action.key].join('+');
|
|
106
|
+
return `${subject}.${this._asLocator(action.selector, inFrameLocator)}.press(${quote(shortcut)});`;
|
|
107
|
+
}
|
|
108
|
+
case 'navigate':
|
|
109
|
+
return `${subject}.navigate(${quote(action.url)});`;
|
|
110
|
+
case 'select':
|
|
111
|
+
return `${subject}.${this._asLocator(action.selector, inFrameLocator)}.selectOption(${formatSelectOption(action.options.length > 1 ? action.options : action.options[0])});`;
|
|
112
|
+
case 'assertText':
|
|
113
|
+
return `assertThat(${subject}.${this._asLocator(action.selector, inFrameLocator)}).${action.substring ? 'containsText' : 'hasText'}(${quote(action.text)});`;
|
|
114
|
+
case 'assertChecked':
|
|
115
|
+
return `assertThat(${subject}.${this._asLocator(action.selector, inFrameLocator)})${action.checked ? '' : '.not()'}.isChecked();`;
|
|
116
|
+
case 'assertVisible':
|
|
117
|
+
return `assertThat(${subject}.${this._asLocator(action.selector, inFrameLocator)}).isVisible();`;
|
|
118
|
+
case 'assertValue':
|
|
119
|
+
{
|
|
120
|
+
const assertion = action.value ? `hasValue(${quote(action.value)})` : `isEmpty()`;
|
|
121
|
+
return `assertThat(${subject}.${this._asLocator(action.selector, inFrameLocator)}).${assertion};`;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
_asLocator(selector, inFrameLocator) {
|
|
126
|
+
return (0, _utils.asLocator)('java', selector, inFrameLocator);
|
|
127
|
+
}
|
|
128
|
+
generateHeader(options) {
|
|
129
|
+
const formatter = new _javascript.JavaScriptFormatter();
|
|
130
|
+
if (this._mode === 'junit') {
|
|
131
|
+
formatter.add(`
|
|
132
|
+
import com.microsoft.playwright.junit.UsePlaywright;
|
|
133
|
+
import com.microsoft.playwright.Page;
|
|
134
|
+
import com.microsoft.playwright.options.*;
|
|
135
|
+
|
|
136
|
+
import org.junit.jupiter.api.*;
|
|
137
|
+
import static com.microsoft.playwright.assertions.PlaywrightAssertions.*;
|
|
138
|
+
|
|
139
|
+
@UsePlaywright
|
|
140
|
+
public class TestExample {
|
|
141
|
+
@Test
|
|
142
|
+
void test(Page page) {`);
|
|
143
|
+
return formatter.format();
|
|
144
|
+
}
|
|
145
|
+
formatter.add(`
|
|
146
|
+
import com.microsoft.playwright.*;
|
|
147
|
+
import com.microsoft.playwright.options.*;
|
|
148
|
+
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
|
|
149
|
+
import java.util.*;
|
|
150
|
+
|
|
151
|
+
public class Example {
|
|
152
|
+
public static void main(String[] args) {
|
|
153
|
+
try (Playwright playwright = Playwright.create()) {
|
|
154
|
+
Browser browser = playwright.${options.browserName}().launch(${formatLaunchOptions(options.launchOptions)});
|
|
155
|
+
BrowserContext context = browser.newContext(${formatContextOptions(options.contextOptions, options.deviceName)});`);
|
|
156
|
+
return formatter.format();
|
|
157
|
+
}
|
|
158
|
+
generateFooter(saveStorage) {
|
|
159
|
+
const storageStateLine = saveStorage ? `\n context.storageState(new BrowserContext.StorageStateOptions().setPath(${quote(saveStorage)}));\n` : '';
|
|
160
|
+
if (this._mode === 'junit') {
|
|
161
|
+
return `${storageStateLine} }
|
|
162
|
+
}`;
|
|
163
|
+
}
|
|
164
|
+
return `${storageStateLine} }
|
|
165
|
+
}
|
|
166
|
+
}`;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
exports.JavaLanguageGenerator = JavaLanguageGenerator;
|
|
170
|
+
function formatPath(files) {
|
|
171
|
+
if (Array.isArray(files)) {
|
|
172
|
+
if (files.length === 0) return 'new Path[0]';
|
|
173
|
+
return `new Path[] {${files.map(s => 'Paths.get(' + quote(s) + ')').join(', ')}}`;
|
|
174
|
+
}
|
|
175
|
+
return `Paths.get(${quote(files)})`;
|
|
176
|
+
}
|
|
177
|
+
function formatSelectOption(options) {
|
|
178
|
+
if (Array.isArray(options)) {
|
|
179
|
+
if (options.length === 0) return 'new String[0]';
|
|
180
|
+
return `new String[] {${options.map(s => quote(s)).join(', ')}}`;
|
|
181
|
+
}
|
|
182
|
+
return quote(options);
|
|
183
|
+
}
|
|
184
|
+
function formatLaunchOptions(options) {
|
|
185
|
+
const lines = [];
|
|
186
|
+
if (!Object.keys(options).filter(key => options[key] !== undefined).length) return '';
|
|
187
|
+
lines.push('new BrowserType.LaunchOptions()');
|
|
188
|
+
if (options.channel) lines.push(` .setChannel(${quote(options.channel)})`);
|
|
189
|
+
if (typeof options.headless === 'boolean') lines.push(` .setHeadless(false)`);
|
|
190
|
+
return lines.join('\n');
|
|
191
|
+
}
|
|
192
|
+
function formatContextOptions(contextOptions, deviceName) {
|
|
193
|
+
var _options$recordHar, _options$recordHar2, _options$recordHar3, _options$recordHar4, _options$recordHar5, _options$recordHar6, _options$recordHar7;
|
|
194
|
+
const lines = [];
|
|
195
|
+
if (!Object.keys(contextOptions).length && !deviceName) return '';
|
|
196
|
+
const device = deviceName ? _deviceDescriptors.deviceDescriptors[deviceName] : {};
|
|
197
|
+
const options = {
|
|
198
|
+
...device,
|
|
199
|
+
...contextOptions
|
|
200
|
+
};
|
|
201
|
+
lines.push('new Browser.NewContextOptions()');
|
|
202
|
+
if (options.acceptDownloads) lines.push(` .setAcceptDownloads(true)`);
|
|
203
|
+
if (options.bypassCSP) lines.push(` .setBypassCSP(true)`);
|
|
204
|
+
if (options.colorScheme) lines.push(` .setColorScheme(ColorScheme.${options.colorScheme.toUpperCase()})`);
|
|
205
|
+
if (options.deviceScaleFactor) lines.push(` .setDeviceScaleFactor(${options.deviceScaleFactor})`);
|
|
206
|
+
if (options.geolocation) lines.push(` .setGeolocation(${options.geolocation.latitude}, ${options.geolocation.longitude})`);
|
|
207
|
+
if (options.hasTouch) lines.push(` .setHasTouch(${options.hasTouch})`);
|
|
208
|
+
if (options.isMobile) lines.push(` .setIsMobile(${options.isMobile})`);
|
|
209
|
+
if (options.locale) lines.push(` .setLocale(${quote(options.locale)})`);
|
|
210
|
+
if (options.proxy) lines.push(` .setProxy(new Proxy(${quote(options.proxy.server)}))`);
|
|
211
|
+
if ((_options$recordHar = options.recordHar) !== null && _options$recordHar !== void 0 && _options$recordHar.content) lines.push(` .setRecordHarContent(HarContentPolicy.${(_options$recordHar2 = options.recordHar) === null || _options$recordHar2 === void 0 ? void 0 : _options$recordHar2.content.toUpperCase()})`);
|
|
212
|
+
if ((_options$recordHar3 = options.recordHar) !== null && _options$recordHar3 !== void 0 && _options$recordHar3.mode) lines.push(` .setRecordHarMode(HarMode.${(_options$recordHar4 = options.recordHar) === null || _options$recordHar4 === void 0 ? void 0 : _options$recordHar4.mode.toUpperCase()})`);
|
|
213
|
+
if ((_options$recordHar5 = options.recordHar) !== null && _options$recordHar5 !== void 0 && _options$recordHar5.omitContent) lines.push(` .setRecordHarOmitContent(true)`);
|
|
214
|
+
if ((_options$recordHar6 = options.recordHar) !== null && _options$recordHar6 !== void 0 && _options$recordHar6.path) lines.push(` .setRecordHarPath(Paths.get(${quote(options.recordHar.path)}))`);
|
|
215
|
+
if ((_options$recordHar7 = options.recordHar) !== null && _options$recordHar7 !== void 0 && _options$recordHar7.urlFilter) lines.push(` .setRecordHarUrlFilter(${quote(options.recordHar.urlFilter)})`);
|
|
216
|
+
if (options.serviceWorkers) lines.push(` .setServiceWorkers(ServiceWorkerPolicy.${options.serviceWorkers.toUpperCase()})`);
|
|
217
|
+
if (options.storageState) lines.push(` .setStorageStatePath(Paths.get(${quote(options.storageState)}))`);
|
|
218
|
+
if (options.timezoneId) lines.push(` .setTimezoneId(${quote(options.timezoneId)})`);
|
|
219
|
+
if (options.userAgent) lines.push(` .setUserAgent(${quote(options.userAgent)})`);
|
|
220
|
+
if (options.viewport) lines.push(` .setViewportSize(${options.viewport.width}, ${options.viewport.height})`);
|
|
221
|
+
return lines.join('\n');
|
|
222
|
+
}
|
|
223
|
+
function formatClickOptions(options) {
|
|
224
|
+
const lines = [];
|
|
225
|
+
if (options.button) lines.push(` .setButton(MouseButton.${options.button.toUpperCase()})`);
|
|
226
|
+
if (options.modifiers) lines.push(` .setModifiers(Arrays.asList(${options.modifiers.map(m => `KeyboardModifier.${m.toUpperCase()}`).join(', ')}))`);
|
|
227
|
+
if (options.clickCount) lines.push(` .setClickCount(${options.clickCount})`);
|
|
228
|
+
if (options.position) lines.push(` .setPosition(${options.position.x}, ${options.position.y})`);
|
|
229
|
+
if (!lines.length) return '';
|
|
230
|
+
lines.unshift(`new Locator.ClickOptions()`);
|
|
231
|
+
return lines.join('\n');
|
|
232
|
+
}
|
|
233
|
+
function quote(text) {
|
|
234
|
+
return (0, _utils.escapeWithQuotes)(text, '\"');
|
|
235
|
+
}
|