@dev-blinq/cucumber_client 1.0.1464-dev → 1.0.1464-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 (35) hide show
  1. package/bin/assets/bundled_scripts/recorder.js +73 -73
  2. package/bin/assets/scripts/recorder.js +87 -49
  3. package/bin/assets/scripts/snapshot_capturer.js +10 -17
  4. package/bin/assets/scripts/unique_locators.js +169 -47
  5. package/bin/assets/templates/_hooks_template.txt +6 -2
  6. package/bin/assets/templates/utils_template.txt +16 -16
  7. package/bin/client/code_cleanup/utils.js +16 -7
  8. package/bin/client/code_gen/code_inversion.js +127 -2
  9. package/bin/client/code_gen/duplication_analysis.js +2 -1
  10. package/bin/client/code_gen/function_signature.js +8 -0
  11. package/bin/client/code_gen/index.js +4 -0
  12. package/bin/client/code_gen/page_reflection.js +101 -15
  13. package/bin/client/code_gen/playwright_codeget.js +173 -77
  14. package/bin/client/cucumber/feature.js +4 -17
  15. package/bin/client/cucumber/steps_definitions.js +13 -0
  16. package/bin/client/recorderv3/bvt_init.js +305 -0
  17. package/bin/client/recorderv3/bvt_recorder.js +1556 -1183
  18. package/bin/client/recorderv3/implemented_steps.js +2 -0
  19. package/bin/client/recorderv3/index.js +3 -293
  20. package/bin/client/recorderv3/services.js +838 -142
  21. package/bin/client/recorderv3/step_runner.js +36 -7
  22. package/bin/client/recorderv3/step_utils.js +171 -95
  23. package/bin/client/recorderv3/update_feature.js +87 -39
  24. package/bin/client/recorderv3/wbr_entry.js +61 -0
  25. package/bin/client/recording.js +1 -0
  26. package/bin/client/types/locators.js +2 -0
  27. package/bin/client/upload-service.js +2 -0
  28. package/bin/client/utils/app_dir.js +21 -0
  29. package/bin/client/utils/socket_logger.js +100 -125
  30. package/bin/index.js +4 -1
  31. package/package.json +11 -5
  32. package/bin/client/recorderv3/app_dir.js +0 -23
  33. package/bin/client/recorderv3/network.js +0 -299
  34. package/bin/client/recorderv3/scriptTest.js +0 -5
  35. package/bin/client/recorderv3/ws_server.js +0 -72
@@ -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,286 +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
- import socketLogger from "../utils/socket_logger.js";
8
-
9
- let port = process.env.EDITOR_PORT || 3003;
10
- const WS_URL = "http://localhost:" + port;
11
-
12
- class PromisifiedSocketServer {
13
- constructor(socket, routes) {
14
- this.socket = socket;
15
- this.routes = routes;
16
- }
17
- init() {
18
- this.socket.on("request", async (data) => {
19
- const { event, input, id, roomId, socketId } = data;
20
- if (event !== "recorderWindow.getCurrentChromiumPath") {
21
- socketLogger.info("Received request", { event, input, id, roomId, socketId });
22
- }
23
- try {
24
- const handler = this.routes[event];
25
- if (!handler) {
26
- console.error(`No handler found for event: ${event}`);
27
- return;
28
- }
29
- const response = await handler(input);
30
- if (event !== "recorderWindow.getCurrentChromiumPath") {
31
- socketLogger.info(`Sending response`, { event, id, value: response, roomId, socketId });
32
- }
33
- this.socket.emit("response", { id, value: response, roomId, socketId });
34
- } catch (error) {
35
- socketLogger.error("Error handling request", {
36
- event,
37
- input,
38
- id,
39
- roomId,
40
- socketId,
41
- error: error instanceof Error ? `${error.message}\n${error.stack}` : error,
42
- });
43
- this.socket.emit("response", {
44
- id,
45
- error: {
46
- message: error?.message,
47
- code: error?.code,
48
- info: error?.info,
49
- stack: error?.stack,
50
- },
51
- roomId,
52
- socketId,
53
- });
54
- }
55
- });
56
- }
57
- }
58
-
59
- const init = ({ envName, projectDir, roomId, TOKEN }) => {
60
- console.log("Connecting to " + WS_URL);
61
- const socket = io(WS_URL);
62
- socketLogger.init(socket, { context: "BVTRecorder", eventName: "BVTRecorder.log" });
63
- socket.on("connect", () => {
64
- socketLogger.info("Connected to BVTRecorder server");
65
- console.log("Connected to BVTRecorder server");
66
- });
67
- socket.on("disconnect", () => {
68
- socketLogger.info("Disconnected from server");
69
- console.log("Disconnected from server");
70
- });
71
- socket.emit("joinRoom", { id: roomId, window: "cucumber_client/bvt_recorder" });
72
- const recorder = new BVTRecorder({
73
- envName,
74
- projectDir,
75
- TOKEN,
76
- sendEvent: (event, data) => {
77
- socketLogger.info("Sending event", { event, data, roomId });
78
- socket.emit(event, data, roomId);
79
- },
80
- logger: socketLogger,
81
- });
82
- recorder
83
- .openBrowser()
84
- .then(() => {
85
- socketLogger.info("BVTRecorder.browserOpened");
86
- socket.emit("BVTRecorder.browserOpened", null, roomId);
87
- })
88
- .catch((e) => {
89
- socketLogger.error("BVTRecorder.browserLaunchFailed", e);
90
- socket.emit("BVTRecorder.browserLaunchFailed", e, roomId);
91
- });
92
- const timeOutForFunction = async (promise, timeout = 5000) => {
93
- const timeoutPromise = new Promise((resolve) => setTimeout(() => resolve(), timeout));
94
-
95
- try {
96
- const res = await Promise.race([promise, timeoutPromise]);
97
- return res;
98
- } catch (error) {
99
- console.error(error);
100
- socketLogger.error(error);
101
- throw error;
102
- }
103
- };
104
-
105
- const promisifiedSocketServer = new PromisifiedSocketServer(socket, {
106
- "recorderWindow.openBrowser": async (input) => {
107
- return recorder
108
- .openBrowser(input)
109
- .then(() => {
110
- socketLogger.info("BVTRecorder.browserOpened");
111
- console.info("BVTRecorder.browserOpened");
112
- socket.emit("BVTRecorder.browserOpened", { roomId, window: "cucumber_client/bvt_recorder" });
113
- })
114
- .catch((e) => {
115
- socketLogger.error("Error opening browser", e);
116
- console.error("BVTRecorder.browserLaunchFailed", e);
117
- socket.emit("BVTRecorder.browserLaunchFailed", { roomId, window: "cucumber_client/bvt_recorder" });
118
- });
119
- },
120
- "recorderWindow.closeBrowser": async (input) => {
121
- return recorder.closeBrowser(input);
122
- },
123
- "recorderWindow.reOpenBrowser": async (input) => {
124
- return recorder
125
- .reOpenBrowser(input)
126
- .then(() => {
127
- socketLogger.info("BVTRecorder.browserOpened");
128
- console.log("BVTRecorder.browserOpened");
129
- socket.emit("BVTRecorder.browserOpened", null, roomId);
130
- })
131
- .catch((e) => {
132
- socketLogger.info("BVTRecorder.browserLaunchFailed");
133
- console.error("BVTRecorder.browserLaunchFailed", e);
134
- socket.emit("BVTRecorder.browserLaunchFailed", null, roomId);
135
- });
136
- },
137
- "recorderWindow.startRecordingInput": async (input) => {
138
- return timeOutForFunction(recorder.startRecordingInput(input));
139
- },
140
- "recorderWindow.stopRecordingInput": async (input) => {
141
- return timeOutForFunction(recorder.stopRecordingInput(input));
142
- },
143
- "recorderWindow.startRecordingText": async (input) => {
144
- // console.log("--- {{ }} -- : recorderWindow.startRecordingText", input);
145
- return timeOutForFunction(recorder.startRecordingText(input));
146
- },
147
- "recorderWindow.stopRecordingText": async (input) => {
148
- return timeOutForFunction(recorder.stopRecordingText(input));
149
- },
150
- "recorderWindow.startRecordingContext": async (input) => {
151
- return timeOutForFunction(recorder.startRecordingContext(input));
152
- },
153
- "recorderWindow.stopRecordingContext": async (input) => {
154
- return timeOutForFunction(recorder.stopRecordingContext(input));
155
- },
156
- "recorderWindow.runStep": async (input) => {
157
- return recorder.runStep(input);
158
- },
159
- "recorderWindow.saveScenario": async (input) => {
160
- return recorder.saveScenario(input);
161
- },
162
- "recorderWindow.getImplementedSteps": async (input) => {
163
- // console.log("recorderWindow.getImplementedSteps", input);
164
- return (await recorder.getImplementedSteps(input)).implementedSteps;
165
- },
166
- "recorderWindow.getImplementedScenarios": async (input) => {
167
- // console.log("recorderWindow.getImplementedScenarios", input);
168
- return (await recorder.getImplementedSteps(input)).scenarios;
169
- },
170
- "recorderWindow.getCurrentChromiumPath": async () => {
171
- // console.log("recorderWindow.getCurrentChromiumPath");
172
- return await recorder.getCurrentChromiumPath();
173
- },
174
- "recorderWindow.overwriteTestData": async (input) => {
175
- // console.log("recorderWindow.overwriteTestData");
176
- return await recorder.overwriteTestData(input);
177
- },
178
- "recorderWindow.generateStepName": async (input) => {
179
- return recorder.generateStepName(input);
180
- },
181
- "recorderWindow.getFeatureAndScenario": async (input) => {
182
- return recorder.generateScenarioAndFeatureNames(input);
183
- },
184
- "recorderWindow.generateCommandName": async (input) => {
185
- return recorder.generateCommandName(input);
186
- },
187
- "recorderWindow.loadTestData": async (input) => {
188
- return recorder.loadTestData(input);
189
- },
190
- "recorderWindow.discard": async (input) => {
191
- return await recorder.discardTestData(input);
192
- },
193
- "recorderWindow.addToTestData": async (input) => {
194
- return await recorder.addToTestData(input);
195
- },
196
- "recorderWindow.getScenarios": async () => {
197
- return recorder.getScenarios();
198
- },
199
- "recorderWindow.setShouldTakeScreenshot": async (input) => {
200
- return recorder.setShouldTakeScreenshot(input);
201
- },
202
- "recorderWindow.compareWithScenario": async ({ projectDir, scenario }, roomId) => {
203
- return await compareWithScenario(getAppDataDir(projectDir), scenario);
204
- },
205
- "recorderWindow.getCommandsForImplementedStep": async (input) => {
206
- return recorder.getCommandsForImplementedStep(input);
207
- },
208
- "recorderWindow.getNumberOfOccurrences": async (input) => {
209
- return recorder.getNumberOfOccurrences(input);
210
- },
211
- "recorderWindow.abortExecution": async (input) => {
212
- return recorder.abortExecution(input);
213
- },
214
- "recorderWindow.pauseExecution": async (input) => {
215
- return recorder.pauseExecution(input);
216
- },
217
- "recorderWindow.resumeExecution": async (input) => {
218
- return recorder.resumeExecution(input);
219
- },
220
- "recorderWindow.loadExistingScenario": async (input) => {
221
- return recorder.loadExistingScenario(input);
222
- },
223
- "recorderWindow.findRelatedTextInAllFrames": async (input) => {
224
- return recorder.findRelatedTextInAllFrames(input);
225
- },
226
- "recorderWindow.getReportFolder": async (input) => {
227
- return recorder.getReportFolder();
228
- },
229
- "recorderWindow.getSnapshotFiles": async (input) => {
230
- const snapshotFolder = recorder.getSnapshotFolder();
231
- if (snapshotFolder) {
232
- const files = await readdir(snapshotFolder);
233
- const ymlFiles = files.filter((file) => file.endsWith(".yml") || file.endsWith(".yaml"));
234
- return { folder: snapshotFolder, files: ymlFiles };
235
- } else return { folder: null, files: [] };
236
- },
237
- "recorderWindow.getCurrentPageTitle": async (input) => {
238
- return await recorder.getCurrentPageTitle();
239
- },
240
- "recorderWindow.getCurrentPageUrl": async (input) => {
241
- return await recorder.getCurrentPageUrl();
242
- },
243
- "recorderWindow.sendAriaSnapshot": async (input) => {
244
- const snapshot = input?.snapshot;
245
- const deselect = input?.deselect;
246
- if (deselect === true) {
247
- return await recorder.deselectAriaElements();
248
- }
249
- if (snapshot !== null) {
250
- return await recorder.processAriaSnapshot(snapshot);
251
- }
252
- },
253
- "recorderWindow.revertMode": async (input) => {
254
- await recorder.revertMode();
255
- },
256
- "recorderWindow.setMode": async (input) => {
257
- const mode = input?.mode;
258
- return recorder.setMode(mode);
259
- },
260
- "recorderWindow.getStepsAndCommandsForScenario": async (input) => {
261
- return await recorder.getStepsAndCommandsForScenario(input);
262
- },
263
- "recorderWindow.getNetworkEvents": async (input) => {
264
- return await recorder.getNetworkEvents(input);
265
- },
266
- "recorderWindow.initExecution": async (input) => {
267
- return await recorder.initExecution(input);
268
- },
269
- "recorderWindow.cleanupExecution": async (input) => {
270
- return await recorder.cleanupExecution(input);
271
- },
272
- "recorderWindow.resetExecution": async (input) => {
273
- return await recorder.resetExecution(input);
274
- },
275
- "recorderWindow.stopRecordingNetwork": async (input) => {
276
- return recorder.stopRecordingNetwork(input);
277
- },
278
- });
279
- socket.on("targetBrowser.command.event", async (input) => {
280
- return recorder.onAction(input);
281
- });
282
- promisifiedSocketServer.init();
283
- };
2
+ import { BVTRecorderInit } from "./bvt_init.js";
284
3
 
285
4
  const usage = `Usage: node bvt_recorder.js <projectDir> <envName> <roomId>`;
286
5
  const args = loadArgs();
@@ -289,6 +8,7 @@ const envName = args[1].split("=")[1];
289
8
  const roomId = args[2];
290
9
  const shouldTakeScreenshot = args[3];
291
10
  const TOKEN = process.env.TOKEN;
11
+
292
12
  try {
293
13
  validateCLIArg(projectDir, "projectDir");
294
14
  validateCLIArg(envName, "envName");
@@ -300,14 +20,4 @@ try {
300
20
  } catch (error) {
301
21
  showUsage(error, usage);
302
22
  }
303
- try {
304
- init({
305
- envName,
306
- projectDir,
307
- roomId,
308
- TOKEN,
309
- shouldTakeScreenshot: shouldTakeScreenshot ? shouldTakeScreenshot === "true" : false,
310
- });
311
- } catch (error) {
312
- console.error(error);
313
- }
23
+ BVTRecorderInit({ envName, projectDir, roomId, TOKEN });