@dev-blinq/cucumber_client 1.0.1476-dev → 1.0.1476-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 (47) hide show
  1. package/bin/assets/bundled_scripts/recorder.js +49 -49
  2. package/bin/assets/scripts/recorder.js +87 -34
  3. package/bin/assets/scripts/snapshot_capturer.js +10 -17
  4. package/bin/assets/scripts/unique_locators.js +78 -28
  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/codemod/find_harcoded_locators.js +173 -0
  8. package/bin/client/code_cleanup/codemod/fix_hardcoded_locators.js +247 -0
  9. package/bin/client/code_cleanup/utils.js +16 -7
  10. package/bin/client/code_gen/code_inversion.js +125 -1
  11. package/bin/client/code_gen/duplication_analysis.js +2 -1
  12. package/bin/client/code_gen/function_signature.js +8 -0
  13. package/bin/client/code_gen/index.js +4 -0
  14. package/bin/client/code_gen/page_reflection.js +90 -9
  15. package/bin/client/code_gen/playwright_codeget.js +173 -77
  16. package/bin/client/codemod/find_harcoded_locators.js +173 -0
  17. package/bin/client/codemod/fix_hardcoded_locators.js +247 -0
  18. package/bin/client/codemod/index.js +8 -0
  19. package/bin/client/codemod/locators_array/find_misstructured_elements.js +148 -0
  20. package/bin/client/codemod/locators_array/fix_misstructured_elements.js +144 -0
  21. package/bin/client/codemod/locators_array/index.js +114 -0
  22. package/bin/client/codemod/types.js +1 -0
  23. package/bin/client/cucumber/feature.js +4 -17
  24. package/bin/client/cucumber/steps_definitions.js +17 -12
  25. package/bin/client/recorderv3/bvt_init.js +310 -0
  26. package/bin/client/recorderv3/bvt_recorder.js +1559 -1182
  27. package/bin/client/recorderv3/constants.js +45 -0
  28. package/bin/client/recorderv3/implemented_steps.js +2 -0
  29. package/bin/client/recorderv3/index.js +3 -305
  30. package/bin/client/recorderv3/mixpanel.js +39 -0
  31. package/bin/client/recorderv3/services.js +839 -142
  32. package/bin/client/recorderv3/step_runner.js +36 -7
  33. package/bin/client/recorderv3/step_utils.js +316 -98
  34. package/bin/client/recorderv3/update_feature.js +85 -37
  35. package/bin/client/recorderv3/utils.js +80 -0
  36. package/bin/client/recorderv3/wbr_entry.js +61 -0
  37. package/bin/client/recording.js +1 -0
  38. package/bin/client/types/locators.js +2 -0
  39. package/bin/client/upload-service.js +2 -0
  40. package/bin/client/utils/app_dir.js +21 -0
  41. package/bin/client/utils/socket_logger.js +100 -125
  42. package/bin/index.js +5 -0
  43. package/package.json +21 -6
  44. package/bin/client/recorderv3/app_dir.js +0 -23
  45. package/bin/client/recorderv3/network.js +0 -299
  46. package/bin/client/recorderv3/scriptTest.js +0 -5
  47. package/bin/client/recorderv3/ws_server.js +0 -72
@@ -0,0 +1,45 @@
1
+ export const FIXED_FOLDER_NAMES = {
2
+ STEP_DEFINITIONS: "step_definitions",
3
+ FEATURES: "features",
4
+ ASSETS: "assets",
5
+ TEMPLATES: "templates",
6
+ BLINQ_TEMP_ROUTES: "blinq_temp_routes",
7
+ DATA: "data",
8
+ ROUTES: "routes",
9
+ };
10
+
11
+ export const FIXED_FILE_NAMES = {
12
+ UTILS: "utils.mjs",
13
+ UTILS_TEMPLATE: "utils_template.txt",
14
+ HOOKS_TEMPLATE: "_hooks_template.txt",
15
+ HOOKS: "_hooks.mjs",
16
+ };
17
+
18
+ export const UTF8_ENCODING = "utf8";
19
+
20
+ export class UpdateStepDefinitionsError extends Error {
21
+ constructor({ type, message, statusCode = 500, meta } = {}) {
22
+ super(message);
23
+
24
+ this.name = "UpdateStepDefinitionsError";
25
+ this.type = type;
26
+ this.statusCode = statusCode;
27
+ this.meta = meta;
28
+
29
+ if (typeof Object.setPrototypeOf === "function") {
30
+ Object.setPrototypeOf(this, new.target.prototype);
31
+ }
32
+ }
33
+ }
34
+ export const SaveJobErrorType = {
35
+ VALIDATION_ERROR: "VALIDATION_ERROR",
36
+ STEP_ERROR: "STEP_ERROR",
37
+ GIT_ERROR: "GIT_ERROR",
38
+ UNKNOWN: "UNKNOWN",
39
+ INTERNAL_ERROR: "INTERNAL_ERROR",
40
+ STEP_DEFINITION_UPDATE_FAILED: "STEP_DEFINITION_UPDATE_FAILED",
41
+ FILE_SYSTEM_ERROR: "FILE_SYSTEM_ERROR",
42
+ STEP_DEFINITIONS_LOADING_FAILED: "STEP_DEFINITIONS_LOADING_FAILED",
43
+ STEP_COMMANDS_PROCESSING_FAILED: "STEP_COMMANDS_PROCESSING_FAILED",
44
+ STEP_INITIALIZATION_FAILED: "STEP_INITIALIZATION_FAILED",
45
+ };
@@ -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,298 +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
- const responseSize = (response) => {
13
- try {
14
- if (typeof response !== "string") {
15
- return new Blob([JSON.stringify(response)]).size;
16
- } else {
17
- return new Blob([response]).size;
18
- }
19
- } catch {
20
- return -1;
21
- }
22
- };
23
-
24
- class PromisifiedSocketServer {
25
- constructor(socket, routes) {
26
- this.socket = socket;
27
- this.routes = routes;
28
- }
29
- init() {
30
- this.socket.on("request", async (data) => {
31
- const { event, input, id, roomId, socketId } = data;
32
- if (event !== "recorderWindow.getCurrentChromiumPath") {
33
- socketLogger.info("Received request", { event, input, id, roomId, socketId });
34
- }
35
- try {
36
- const handler = this.routes[event];
37
- if (!handler) {
38
- console.error(`No handler found for event: ${event}`);
39
- return;
40
- }
41
- const response = await handler(input);
42
- if (event !== "recorderWindow.getCurrentChromiumPath") {
43
- socketLogger.info(`Sending response for ${event}, ${responseSize(response)} bytes`);
44
- }
45
- this.socket.emit("response", { id, value: response, roomId, socketId });
46
- } catch (error) {
47
- socketLogger.error("Error handling request", {
48
- event,
49
- input,
50
- id,
51
- roomId,
52
- socketId,
53
- error: error instanceof Error ? `${error.message}\n${error.stack}` : error,
54
- });
55
- this.socket.emit("response", {
56
- id,
57
- error: {
58
- message: error?.message,
59
- code: error?.code,
60
- info: error?.info,
61
- stack: error?.stack,
62
- },
63
- roomId,
64
- socketId,
65
- });
66
- }
67
- });
68
- }
69
- }
70
-
71
- const init = ({ envName, projectDir, roomId, TOKEN }) => {
72
- console.log("Connecting to " + WS_URL);
73
- const socket = io(WS_URL);
74
- socketLogger.init(socket, { context: "BVTRecorder", eventName: "BVTRecorder.log" });
75
- socket.on("connect", () => {
76
- socketLogger.info("Connected to BVTRecorder server");
77
- console.log("Connected to BVTRecorder server");
78
- });
79
- socket.on("disconnect", () => {
80
- socketLogger.info("Disconnected from server");
81
- console.log("Disconnected from server");
82
- });
83
- socket.emit("joinRoom", { id: roomId, window: "cucumber_client/bvt_recorder" });
84
- const recorder = new BVTRecorder({
85
- envName,
86
- projectDir,
87
- TOKEN,
88
- sendEvent: (event, data) => {
89
- socketLogger.info("Sending event", { event, data, roomId });
90
- socket.emit(event, data, roomId);
91
- },
92
- logger: socketLogger,
93
- });
94
- recorder
95
- .openBrowser()
96
- .then(() => {
97
- socketLogger.info("BVTRecorder.browserOpened");
98
- socket.emit("BVTRecorder.browserOpened", null, roomId);
99
- })
100
- .catch((e) => {
101
- socketLogger.error("BVTRecorder.browserLaunchFailed", e);
102
- socket.emit("BVTRecorder.browserLaunchFailed", e, roomId);
103
- });
104
- const timeOutForFunction = async (promise, timeout = 5000) => {
105
- const timeoutPromise = new Promise((resolve) => setTimeout(() => resolve(), timeout));
106
-
107
- try {
108
- const res = await Promise.race([promise, timeoutPromise]);
109
- return res;
110
- } catch (error) {
111
- console.error(error);
112
- socketLogger.error(error);
113
- throw error;
114
- }
115
- };
116
-
117
- const promisifiedSocketServer = new PromisifiedSocketServer(socket, {
118
- "recorderWindow.openBrowser": async (input) => {
119
- return recorder
120
- .openBrowser(input)
121
- .then(() => {
122
- socketLogger.info("BVTRecorder.browserOpened");
123
- console.info("BVTRecorder.browserOpened");
124
- socket.emit("BVTRecorder.browserOpened", { roomId, window: "cucumber_client/bvt_recorder" });
125
- })
126
- .catch((e) => {
127
- socketLogger.error("Error opening browser", e);
128
- console.error("BVTRecorder.browserLaunchFailed", e);
129
- socket.emit("BVTRecorder.browserLaunchFailed", { roomId, window: "cucumber_client/bvt_recorder" });
130
- });
131
- },
132
- "recorderWindow.closeBrowser": async (input) => {
133
- return recorder.closeBrowser(input);
134
- },
135
- "recorderWindow.reOpenBrowser": async (input) => {
136
- return recorder
137
- .reOpenBrowser(input)
138
- .then(() => {
139
- socketLogger.info("BVTRecorder.browserOpened");
140
- console.log("BVTRecorder.browserOpened");
141
- socket.emit("BVTRecorder.browserOpened", null, roomId);
142
- })
143
- .catch((e) => {
144
- socketLogger.info("BVTRecorder.browserLaunchFailed");
145
- console.error("BVTRecorder.browserLaunchFailed", e);
146
- socket.emit("BVTRecorder.browserLaunchFailed", null, roomId);
147
- });
148
- },
149
- "recorderWindow.startRecordingInput": async (input) => {
150
- return timeOutForFunction(recorder.startRecordingInput(input));
151
- },
152
- "recorderWindow.stopRecordingInput": async (input) => {
153
- return timeOutForFunction(recorder.stopRecordingInput(input));
154
- },
155
- "recorderWindow.startRecordingText": async (input) => {
156
- // console.log("--- {{ }} -- : recorderWindow.startRecordingText", input);
157
- return timeOutForFunction(recorder.startRecordingText(input));
158
- },
159
- "recorderWindow.stopRecordingText": async (input) => {
160
- return timeOutForFunction(recorder.stopRecordingText(input));
161
- },
162
- "recorderWindow.startRecordingContext": async (input) => {
163
- return timeOutForFunction(recorder.startRecordingContext(input));
164
- },
165
- "recorderWindow.stopRecordingContext": async (input) => {
166
- return timeOutForFunction(recorder.stopRecordingContext(input));
167
- },
168
- "recorderWindow.runStep": async (input) => {
169
- return recorder.runStep(input);
170
- },
171
- "recorderWindow.saveScenario": async (input) => {
172
- return recorder.saveScenario(input);
173
- },
174
- "recorderWindow.getImplementedSteps": async (input) => {
175
- // console.log("recorderWindow.getImplementedSteps", input);
176
- return (await recorder.getImplementedSteps(input)).implementedSteps;
177
- },
178
- "recorderWindow.getImplementedScenarios": async (input) => {
179
- // console.log("recorderWindow.getImplementedScenarios", input);
180
- return (await recorder.getImplementedSteps(input)).scenarios;
181
- },
182
- "recorderWindow.getCurrentChromiumPath": async () => {
183
- // console.log("recorderWindow.getCurrentChromiumPath");
184
- return await recorder.getCurrentChromiumPath();
185
- },
186
- "recorderWindow.overwriteTestData": async (input) => {
187
- // console.log("recorderWindow.overwriteTestData");
188
- return await recorder.overwriteTestData(input);
189
- },
190
- "recorderWindow.generateStepName": async (input) => {
191
- return recorder.generateStepName(input);
192
- },
193
- "recorderWindow.getFeatureAndScenario": async (input) => {
194
- return recorder.generateScenarioAndFeatureNames(input);
195
- },
196
- "recorderWindow.generateCommandName": async (input) => {
197
- return recorder.generateCommandName(input);
198
- },
199
- "recorderWindow.loadTestData": async (input) => {
200
- return recorder.loadTestData(input);
201
- },
202
- "recorderWindow.discard": async (input) => {
203
- return await recorder.discardTestData(input);
204
- },
205
- "recorderWindow.addToTestData": async (input) => {
206
- return await recorder.addToTestData(input);
207
- },
208
- "recorderWindow.getScenarios": async () => {
209
- return recorder.getScenarios();
210
- },
211
- "recorderWindow.setShouldTakeScreenshot": async (input) => {
212
- return recorder.setShouldTakeScreenshot(input);
213
- },
214
- "recorderWindow.compareWithScenario": async ({ projectDir, scenario }, roomId) => {
215
- return await compareWithScenario(getAppDataDir(projectDir), scenario);
216
- },
217
- "recorderWindow.getCommandsForImplementedStep": async (input) => {
218
- return recorder.getCommandsForImplementedStep(input);
219
- },
220
- "recorderWindow.getNumberOfOccurrences": async (input) => {
221
- return recorder.getNumberOfOccurrences(input);
222
- },
223
- "recorderWindow.abortExecution": async (input) => {
224
- return recorder.abortExecution(input);
225
- },
226
- "recorderWindow.pauseExecution": async (input) => {
227
- return recorder.pauseExecution(input);
228
- },
229
- "recorderWindow.resumeExecution": async (input) => {
230
- return recorder.resumeExecution(input);
231
- },
232
- "recorderWindow.loadExistingScenario": async (input) => {
233
- return recorder.loadExistingScenario(input);
234
- },
235
- "recorderWindow.findRelatedTextInAllFrames": async (input) => {
236
- return recorder.findRelatedTextInAllFrames(input);
237
- },
238
- "recorderWindow.getReportFolder": async (input) => {
239
- return recorder.getReportFolder();
240
- },
241
- "recorderWindow.getSnapshotFiles": async (input) => {
242
- const snapshotFolder = recorder.getSnapshotFolder();
243
- if (snapshotFolder) {
244
- const files = await readdir(snapshotFolder);
245
- const ymlFiles = files.filter((file) => file.endsWith(".yml") || file.endsWith(".yaml"));
246
- return { folder: snapshotFolder, files: ymlFiles };
247
- } else return { folder: null, files: [] };
248
- },
249
- "recorderWindow.getCurrentPageTitle": async (input) => {
250
- return await recorder.getCurrentPageTitle();
251
- },
252
- "recorderWindow.getCurrentPageUrl": async (input) => {
253
- return await recorder.getCurrentPageUrl();
254
- },
255
- "recorderWindow.sendAriaSnapshot": async (input) => {
256
- const snapshot = input?.snapshot;
257
- const deselect = input?.deselect;
258
- if (deselect === true) {
259
- return await recorder.deselectAriaElements();
260
- }
261
- if (snapshot !== null) {
262
- return await recorder.processAriaSnapshot(snapshot);
263
- }
264
- },
265
- "recorderWindow.revertMode": async (input) => {
266
- await recorder.revertMode();
267
- },
268
- "recorderWindow.setMode": async (input) => {
269
- const mode = input?.mode;
270
- return recorder.setMode(mode);
271
- },
272
- "recorderWindow.getStepsAndCommandsForScenario": async (input) => {
273
- return await recorder.getStepsAndCommandsForScenario(input);
274
- },
275
- "recorderWindow.getNetworkEvents": async (input) => {
276
- return await recorder.getNetworkEvents(input);
277
- },
278
- "recorderWindow.initExecution": async (input) => {
279
- return await recorder.initExecution(input);
280
- },
281
- "recorderWindow.cleanupExecution": async (input) => {
282
- return await recorder.cleanupExecution(input);
283
- },
284
- "recorderWindow.resetExecution": async (input) => {
285
- return await recorder.resetExecution(input);
286
- },
287
- "recorderWindow.stopRecordingNetwork": async (input) => {
288
- return recorder.stopRecordingNetwork(input);
289
- },
290
- });
291
- socket.on("targetBrowser.command.event", async (input) => {
292
- return recorder.onAction(input);
293
- });
294
- promisifiedSocketServer.init();
295
- };
2
+ import { BVTRecorderInit } from "./bvt_init.js";
296
3
 
297
4
  const usage = `Usage: node bvt_recorder.js <projectDir> <envName> <roomId>`;
298
5
  const args = loadArgs();
@@ -301,6 +8,7 @@ const envName = args[1].split("=")[1];
301
8
  const roomId = args[2];
302
9
  const shouldTakeScreenshot = args[3];
303
10
  const TOKEN = process.env.TOKEN;
11
+
304
12
  try {
305
13
  validateCLIArg(projectDir, "projectDir");
306
14
  validateCLIArg(envName, "envName");
@@ -312,14 +20,4 @@ try {
312
20
  } catch (error) {
313
21
  showUsage(error, usage);
314
22
  }
315
- try {
316
- init({
317
- envName,
318
- projectDir,
319
- roomId,
320
- TOKEN,
321
- shouldTakeScreenshot: shouldTakeScreenshot ? shouldTakeScreenshot === "true" : false,
322
- });
323
- } catch (error) {
324
- console.error(error);
325
- }
23
+ BVTRecorderInit({ envName, projectDir, roomId, TOKEN });
@@ -0,0 +1,39 @@
1
+ import mixpanel from "mixpanel";
2
+ let mixpanelClient = null;
3
+ let mixPaneltoken = getMixpanelToken();
4
+ function getMixpanelToken() {
5
+ if (process.env.MIXPANEL_TOKEN) {
6
+ const token = process.env.MIXPANEL_TOKEN;
7
+ if (["local-worker", "cloud-worker"].includes(process.env.CC_SOURCE || "")) {
8
+ delete process.env.MIXPANEL_TOKEN;
9
+ }
10
+ return token;
11
+ }
12
+ return null;
13
+ }
14
+ if (mixPaneltoken && process.env.NODE_ENV_BLINQ === "prod") {
15
+ mixpanelClient = mixpanel.init(mixPaneltoken, {});
16
+ console.log("✅Mixpanel client initialized.");
17
+ }
18
+ else {
19
+ console.info("MIXPANEL_TOKEN is not defined.");
20
+ }
21
+ export function mixpanelTrackEvent(event, distinctId, properties = {}) {
22
+ if (mixpanelClient === null)
23
+ return;
24
+ mixpanelClient.track(event, {
25
+ distinct_id: distinctId,
26
+ env: process.env.NODE_ENV_BLINQ || "local",
27
+ ...properties,
28
+ });
29
+ }
30
+ export function mixpanelTrackEventIdentifyUser(distinctId, properties = {}) {
31
+ if (mixpanelClient === null)
32
+ return;
33
+ mixpanelClient.people.set(distinctId, properties);
34
+ }
35
+ export const MIXPANEL_EVENTS = {
36
+ STEP_IN_SCENARIO: "There is a step in the scenario",
37
+ RECORDER_CONNECTED: "Recorder session initiated",
38
+ CHROMIUM_LOADED: "Chromium loaded",
39
+ };