@dev-blinq/cucumber_client 1.0.1415-dev → 1.0.1415-stage

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 (50) hide show
  1. package/bin/assets/bundled_scripts/recorder.js +105 -105
  2. package/bin/assets/preload/css_gen.js +10 -10
  3. package/bin/assets/preload/toolbar.js +27 -29
  4. package/bin/assets/preload/unique_locators.js +1 -1
  5. package/bin/assets/preload/yaml.js +288 -275
  6. package/bin/assets/scripts/aria_snapshot.js +223 -220
  7. package/bin/assets/scripts/dom_attr.js +329 -329
  8. package/bin/assets/scripts/dom_parent.js +169 -174
  9. package/bin/assets/scripts/event_utils.js +94 -94
  10. package/bin/assets/scripts/pw.js +2050 -1949
  11. package/bin/assets/scripts/recorder.js +70 -45
  12. package/bin/assets/scripts/snapshot_capturer.js +147 -147
  13. package/bin/assets/scripts/unique_locators.js +163 -44
  14. package/bin/assets/scripts/yaml.js +796 -783
  15. package/bin/assets/templates/_hooks_template.txt +6 -2
  16. package/bin/assets/templates/utils_template.txt +16 -16
  17. package/bin/client/code_cleanup/find_step_definition_references.js +0 -1
  18. package/bin/client/code_cleanup/utils.js +5 -1
  19. package/bin/client/code_gen/api_codegen.js +2 -2
  20. package/bin/client/code_gen/code_inversion.js +63 -2
  21. package/bin/client/code_gen/function_signature.js +4 -0
  22. package/bin/client/code_gen/page_reflection.js +846 -906
  23. package/bin/client/code_gen/playwright_codeget.js +27 -3
  24. package/bin/client/cucumber/feature.js +4 -0
  25. package/bin/client/cucumber/feature_data.js +2 -2
  26. package/bin/client/cucumber/project_to_document.js +8 -2
  27. package/bin/client/cucumber/steps_definitions.js +19 -3
  28. package/bin/client/cucumber_selector.js +4 -0
  29. package/bin/client/local_agent.js +3 -2
  30. package/bin/client/parse_feature_file.js +23 -26
  31. package/bin/client/playground/projects/env.json +2 -2
  32. package/bin/client/project.js +186 -202
  33. package/bin/client/recorderv3/bvt_init.js +363 -0
  34. package/bin/client/recorderv3/bvt_recorder.js +1056 -93
  35. package/bin/client/recorderv3/implemented_steps.js +2 -0
  36. package/bin/client/recorderv3/index.js +4 -311
  37. package/bin/client/recorderv3/scriptTest.js +1 -1
  38. package/bin/client/recorderv3/services.js +810 -154
  39. package/bin/client/recorderv3/step_runner.js +37 -11
  40. package/bin/client/recorderv3/step_utils.js +495 -39
  41. package/bin/client/recorderv3/update_feature.js +9 -5
  42. package/bin/client/recorderv3/wbr_entry.js +61 -0
  43. package/bin/client/recording.js +1 -0
  44. package/bin/client/upload-service.js +3 -2
  45. package/bin/client/utils/socket_logger.js +132 -0
  46. package/bin/index.js +4 -1
  47. package/bin/logger.js +3 -2
  48. package/bin/min/consoleApi.min.cjs +2 -3
  49. package/bin/min/injectedScript.min.cjs +16 -16
  50. package/package.json +19 -9
@@ -235,6 +235,7 @@ export const getImplementedSteps = async (projectDir) => {
235
235
  pattern: template.pattern,
236
236
  paths: template.paths,
237
237
  routeItems: step.routeItems,
238
+ isApiStep: template.source === "api",
238
239
  };
239
240
 
240
241
  implementedSteps.push(implementedStep);
@@ -260,6 +261,7 @@ export const getImplementedSteps = async (projectDir) => {
260
261
  mjsFile: template.mjsFile,
261
262
  pattern: template.pattern,
262
263
  paths: template.paths,
264
+ isApiStep: template.source === "api",
263
265
  };
264
266
  // reconstruct the parameters
265
267
  const parameters = [];
@@ -1,303 +1,5 @@
1
1
  import { loadArgs, showUsage, validateCLIArg } from "../cli_helpers.js";
2
- import { io } from "socket.io-client";
3
- import { BVTRecorder } from "./bvt_recorder.js";
4
- import { compareWithScenario } from "../code_gen/duplication_analysis.js";
5
- import { getAppDataDir } from "./app_dir.js";
6
- import { readdir } from "fs/promises";
7
-
8
- let port = process.env.EDITOR_PORT || 3003;
9
- const WS_URL = "http://localhost:" + port;
10
-
11
- class PromisifiedSocketServer {
12
- constructor(socket, routes) {
13
- this.socket = socket;
14
- this.routes = routes;
15
- }
16
- init() {
17
- this.socket.on("request", async (data) => {
18
- const { event, input, id, roomId, socketId } = data;
19
- console.log("request", { event, input, id, roomId, socketId });
20
- try {
21
- const handler = this.routes[event];
22
- if (!handler) {
23
- console.error(`No handler found for event: ${event}`);
24
- return;
25
- }
26
- const response = await handler(input);
27
- // console.log("response", { id, value: response, roomId, socketId });
28
- this.socket.emit("response", { id, value: response, roomId, socketId });
29
- } catch (error) {
30
- console.log("request", JSON.stringify({ event, input, id, roomId, socketId }));
31
- console.error("response", { id, error, roomId, socketId });
32
- // console.error({
33
- // message: error?.message,
34
- // code: error?.code,
35
- // info: error?.info,
36
- // stack: error?.stack,
37
- // })
38
- this.socket.emit("response", {
39
- id,
40
- error: {
41
- message: error?.message,
42
- code: error?.code,
43
- info: error?.info,
44
- stack: error?.stack,
45
- },
46
- roomId,
47
- socketId,
48
- });
49
- }
50
- });
51
- }
52
- }
53
-
54
- function memorySizeOf(obj) {
55
- var bytes = 0;
56
-
57
- function sizeOf(obj) {
58
- if (obj !== null && obj !== undefined) {
59
- switch (typeof obj) {
60
- case "number":
61
- bytes += 8;
62
- break;
63
- case "string":
64
- bytes += obj.length * 2;
65
- break;
66
- case "boolean":
67
- bytes += 4;
68
- break;
69
- case "object":
70
- var objClass = Object.prototype.toString.call(obj).slice(8, -1);
71
- if (objClass === "Object" || objClass === "Array") {
72
- for (var key in obj) {
73
- if (!obj.hasOwnProperty(key)) continue;
74
- sizeOf(obj[key]);
75
- }
76
- } else bytes += obj.toString().length * 2;
77
- break;
78
- }
79
- }
80
- return bytes;
81
- }
82
- return sizeOf(obj);
83
- }
84
-
85
- const init = ({ envName, projectDir, roomId, TOKEN }) => {
86
- console.log("connecting to " + WS_URL);
87
- const socket = io(WS_URL);
88
- socket.on("connect", () => {
89
- console.log("connected to server");
90
- });
91
- socket.on("disconnect", () => {
92
- console.log("disconnected from server");
93
- });
94
- socket.emit("joinRoom", { id: roomId, window: "cucumber_client/bvt_recorder" });
95
- const recorder = new BVTRecorder({
96
- envName,
97
- projectDir,
98
- TOKEN,
99
- sendEvent: (event, data) => {
100
- console.log("Size of data", memorySizeOf(data), "bytes");
101
- console.log("----", event, data, "roomId", roomId);
102
- socket.emit(event, data, roomId);
103
- console.log("Successfully sent event", event, "to room", roomId);
104
- },
105
- });
106
- recorder
107
- .openBrowser()
108
- .then(() => {
109
- // console.log("BVTRecorder.browserOpened");
110
- socket.emit("BVTRecorder.browserOpened", null, roomId);
111
- })
112
- .catch((e) => {
113
- console.error("BVTRecorder.browserLaunchFailed", e);
114
- socket.emit("BVTRecorder.browserLaunchFailed", e, roomId);
115
- });
116
- const timeOutForFunction = async (promise, timeout = 5000) => {
117
- const timeoutPromise = new Promise((resolve) => setTimeout(() => resolve(), timeout));
118
-
119
- try {
120
- const res = await Promise.race([promise, timeoutPromise]);
121
- return res;
122
- } catch (error) {
123
- console.error(error);
124
- throw error;
125
- }
126
- };
127
-
128
- const promisifiedSocketServer = new PromisifiedSocketServer(socket, {
129
- "recorderWindow.openBrowser": async (input) => {
130
- return recorder
131
- .openBrowser(input)
132
- .then(() => {
133
- socket.emit("BVTRecorder.browserOpened", { roomId, window: "cucumber_client/bvt_recorder" });
134
- })
135
- .catch((e) => {
136
- console.error(e);
137
- socket.emit("BVTRecorder.browserLaunchFailed", { roomId, window: "cucumber_client/bvt_recorder" });
138
- });
139
- },
140
- "recorderWindow.closeBrowser": async (input) => {
141
- return recorder.closeBrowser(input);
142
- },
143
- "recorderWindow.reOpenBrowser": async (input) => {
144
- return recorder
145
- .reOpenBrowser(input)
146
- .then(() => {
147
- // console.log("BVTRecorder.browserOpened");
148
- socket.emit("BVTRecorder.browserOpened", null, roomId);
149
- })
150
- .catch((e) => {
151
- console.error("BVTRecorder.browserLaunchFailed", e);
152
- socket.emit("BVTRecorder.browserLaunchFailed", null, roomId);
153
- });
154
- },
155
- "recorderWindow.startRecordingInput": async (input) => {
156
- return timeOutForFunction(recorder.startRecordingInput(input));
157
- },
158
- "recorderWindow.stopRecordingInput": async (input) => {
159
- return timeOutForFunction(recorder.stopRecordingInput(input));
160
- },
161
- "recorderWindow.startRecordingText": async (input) => {
162
- // console.log("--- {{ }} -- : recorderWindow.startRecordingText", input);
163
- return timeOutForFunction(recorder.startRecordingText(input));
164
- },
165
- "recorderWindow.stopRecordingText": async (input) => {
166
- return timeOutForFunction(recorder.stopRecordingText(input));
167
- },
168
- "recorderWindow.startRecordingContext": async (input) => {
169
- return timeOutForFunction(recorder.startRecordingContext(input));
170
- },
171
- "recorderWindow.stopRecordingContext": async (input) => {
172
- return timeOutForFunction(recorder.stopRecordingContext(input));
173
- },
174
- "recorderWindow.runStep": async (input) => {
175
- return recorder.runStep(input);
176
- },
177
- "recorderWindow.saveScenario": async (input) => {
178
- return recorder.saveScenario(input);
179
- },
180
- "recorderWindow.getImplementedSteps": async (input) => {
181
- // console.log("recorderWindow.getImplementedSteps", input);
182
- return (await recorder.getImplementedSteps(input)).implementedSteps;
183
- },
184
- "recorderWindow.getImplementedScenarios": async (input) => {
185
- // console.log("recorderWindow.getImplementedScenarios", input);
186
- return (await recorder.getImplementedSteps(input)).scenarios;
187
- },
188
- "recorderWindow.getCurrentChromiumPath": async () => {
189
- // console.log("recorderWindow.getCurrentChromiumPath");
190
- return await recorder.getCurrentChromiumPath();
191
- },
192
- "recorderWindow.overwriteTestData": async (input) => {
193
- // console.log("recorderWindow.overwriteTestData");
194
- return await recorder.overwriteTestData(input);
195
- },
196
- "recorderWindow.generateStepName": async (input) => {
197
- return recorder.generateStepName(input);
198
- },
199
- "recorderWindow.getFeatureAndScenario": async (input) => {
200
- return recorder.generateScenarioAndFeatureNames(input);
201
- },
202
- "recorderWindow.generateCommandName": async (input) => {
203
- return recorder.generateCommandName(input);
204
- },
205
- "recorderWindow.loadTestData": async (input) => {
206
- return recorder.loadTestData(input);
207
- },
208
- "recorderWindow.discard": async (input) => {
209
- return await recorder.discardTestData(input);
210
- },
211
- "recorderWindow.addToTestData": async (input) => {
212
- return await recorder.addToTestData(input);
213
- },
214
- "recorderWindow.getScenarios": async () => {
215
- return recorder.getScenarios();
216
- },
217
- "recorderWindow.setShouldTakeScreenshot": async (input) => {
218
- return recorder.setShouldTakeScreenshot(input);
219
- },
220
- "recorderWindow.compareWithScenario": async ({ projectDir, scenario }, roomId) => {
221
- return await compareWithScenario(getAppDataDir(projectDir), scenario);
222
- },
223
- "recorderWindow.getCommandsForImplementedStep": async (input) => {
224
- return recorder.getCommandsForImplementedStep(input);
225
- },
226
- "recorderWindow.getNumberOfOccurrences": async (input) => {
227
- return recorder.getNumberOfOccurrences(input);
228
- },
229
- "recorderWindow.abortExecution": async (input) => {
230
- return recorder.abortExecution(input);
231
- },
232
- "recorderWindow.pauseExecution": async (input) => {
233
- return recorder.pauseExecution(input);
234
- },
235
- "recorderWindow.resumeExecution": async (input) => {
236
- return recorder.resumeExecution(input);
237
- },
238
- "recorderWindow.loadExistingScenario": async (input) => {
239
- return recorder.loadExistingScenario(input);
240
- },
241
- "recorderWindow.findRelatedTextInAllFrames": async (input) => {
242
- return recorder.findRelatedTextInAllFrames(input);
243
- },
244
- "recorderWindow.getReportFolder": async (input) => {
245
- return recorder.getReportFolder();
246
- },
247
- "recorderWindow.getSnapshotFiles": async (input) => {
248
- const snapshotFolder = recorder.getSnapshotFolder();
249
- if (snapshotFolder) {
250
- // Get the list of filenames in the snapshot folder
251
- const files = await readdir(snapshotFolder);
252
- // Filter the files to only include .png files
253
- const ymlFiles = files.filter((file) => file.endsWith(".yml") || file.endsWith(".yaml"));
254
- return { folder: snapshotFolder, files: ymlFiles };
255
- } else return { folder: null, files: [] };
256
- },
257
- "recorderWindow.getCurrentPageTitle": async (input) => {
258
- return await recorder.getCurrentPageTitle();
259
- },
260
- "recorderWindow.getCurrentPageUrl": async (input) => {
261
- return await recorder.getCurrentPageUrl();
262
- },
263
- "recorderWindow.sendAriaSnapshot": async (input) => {
264
- const snapshot = input?.snapshot;
265
- const deselect = input?.deselect;
266
- if (deselect === true) {
267
- return await recorder.deselectAriaElements();
268
- }
269
- if (snapshot !== null) {
270
- return await recorder.processAriaSnapshot(snapshot);
271
- }
272
- },
273
- "recorderWindow.revertMode": async (input) => {
274
- await recorder.revertMode();
275
- },
276
- "recorderWindow.setMode": async (input) => {
277
- const mode = input?.mode;
278
- return recorder.setMode(mode);
279
- },
280
- "recorderWindow.getStepsAndCommandsForScenario": async (input) => {
281
- return await recorder.getStepsAndCommandsForScenario(input);
282
- },
283
- "recorderWindow.getNetworkEvents": async (input) => {
284
- return await recorder.getNetworkEvents(input);
285
- },
286
- "recorderWindow.initExecution": async (input) => {
287
- return await recorder.initExecution(input);
288
- },
289
- "recorderWindow.cleanupExecution": async (input) => {
290
- return await recorder.cleanupExecution(input);
291
- },
292
- "recorderWindow.resetExecution": async (input) => {
293
- return await recorder.resetExecution(input);
294
- },
295
- });
296
- socket.on("targetBrowser.command.event", async (input) => {
297
- return recorder.onAction(input);
298
- });
299
- promisifiedSocketServer.init();
300
- };
2
+ import { BVTRecorderInit } from "./bvt_init.js";
301
3
 
302
4
  const usage = `Usage: node bvt_recorder.js <projectDir> <envName> <roomId>`;
303
5
  const args = loadArgs();
@@ -306,6 +8,7 @@ const envName = args[1].split("=")[1];
306
8
  const roomId = args[2];
307
9
  const shouldTakeScreenshot = args[3];
308
10
  const TOKEN = process.env.TOKEN;
11
+
309
12
  try {
310
13
  validateCLIArg(projectDir, "projectDir");
311
14
  validateCLIArg(envName, "envName");
@@ -317,15 +20,5 @@ try {
317
20
  } catch (error) {
318
21
  showUsage(error, usage);
319
22
  }
320
- try {
321
- // console.log({ envName, projectDir, featureName, scenarioName, stepIndex, roomId })
322
- init({
323
- envName,
324
- projectDir,
325
- roomId,
326
- TOKEN,
327
- shouldTakeScreenshot: shouldTakeScreenshot ? shouldTakeScreenshot === "true" : false,
328
- });
329
- } catch (error) {
330
- console.error(error);
331
- }
23
+
24
+ BVTRecorderInit({ envName, projectDir, roomId, TOKEN });
@@ -2,4 +2,4 @@
2
2
 
3
3
  // getImplementedSteps('/Users/yash/Library/Application Support/blinq.io/67d7c7ffb099a8da65d7e204').then((implementedSteps) => {
4
4
  // console.log(JSON.stringify(implementedSteps, null, 2));
5
- // });
5
+ // });