@dev-blinq/cucumber_client 1.0.1475-dev → 1.0.1475-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 +1560 -1183
  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 -293
  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,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 });
@@ -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
+ };