frame.simulator 1.0.1 → 1.0.2
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/batch.ts +82 -0
- package/command.ts +2 -1
- package/commandHandler.ts +7 -3
- package/package.json +3 -1
- package/simulator.ts +14 -13
- package/types.ts +6 -1
package/batch.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Command } from './command';
|
|
2
|
+
import { TUserAction } from './types';
|
|
3
|
+
|
|
4
|
+
const PORT: number = parseInt(process.env.PORT || '3010', 10);
|
|
5
|
+
|
|
6
|
+
export class Batch {
|
|
7
|
+
constructor() {
|
|
8
|
+
// Initialize any necessary properties here
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
private async sendRequest(
|
|
12
|
+
command: string,
|
|
13
|
+
data?: TUserAction,
|
|
14
|
+
): Promise<string> {
|
|
15
|
+
let status = 'blocked';
|
|
16
|
+
try {
|
|
17
|
+
const response = await fetch(`http://localhost:${PORT}/send-command`, {
|
|
18
|
+
method: 'POST',
|
|
19
|
+
headers: {
|
|
20
|
+
'Content-Type': 'application/json',
|
|
21
|
+
},
|
|
22
|
+
body: JSON.stringify({
|
|
23
|
+
command,
|
|
24
|
+
data,
|
|
25
|
+
}),
|
|
26
|
+
});
|
|
27
|
+
// console.log(`response: ${JSON.stringify(response, null)}`);
|
|
28
|
+
// console.log(`response.status: ${response.status}`);
|
|
29
|
+
if (response.status === 200) {
|
|
30
|
+
status = 'ok';
|
|
31
|
+
}
|
|
32
|
+
return status;
|
|
33
|
+
} catch (error) {
|
|
34
|
+
console.log(`error.status: ${status}`);
|
|
35
|
+
console.error('Error:', error);
|
|
36
|
+
}
|
|
37
|
+
console.log(`return status: ${status}`);
|
|
38
|
+
return status;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async selectButton(
|
|
42
|
+
testId: string,
|
|
43
|
+
retries: number = 5,
|
|
44
|
+
delay: number = 1000,
|
|
45
|
+
): Promise<void> {
|
|
46
|
+
const sleep = (ms: number) =>
|
|
47
|
+
new Promise((resolve) => setTimeout(resolve, ms));
|
|
48
|
+
|
|
49
|
+
for (let attempt = 1; attempt <= retries; attempt++) {
|
|
50
|
+
try {
|
|
51
|
+
if (attempt >= 1) {
|
|
52
|
+
console.log(
|
|
53
|
+
`Attempt ${attempt}/${retries} to click button: ${testId}`,
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const status = await this.sendRequest(Command.SimulateClick, {
|
|
58
|
+
testId,
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
if (status !== 'ok') {
|
|
62
|
+
console.log('Failed to send button simulation command');
|
|
63
|
+
}
|
|
64
|
+
await sleep(delay);
|
|
65
|
+
return; // Success, exit the retry loop
|
|
66
|
+
} catch (error) {
|
|
67
|
+
console.error('Error in main:', error);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async sampleClickCanvasDrawAt(x: number, y: number) {
|
|
73
|
+
console.log(`sampleClickCanvasDrawAt(${x}, ${y})`);
|
|
74
|
+
await this.sendRequest(Command.SimulateClickOnCanvas, {
|
|
75
|
+
testId: 'canvas.draw',
|
|
76
|
+
x,
|
|
77
|
+
y,
|
|
78
|
+
});
|
|
79
|
+
// Small delay to ensure element is fully ready
|
|
80
|
+
await new Promise((resolve) => setTimeout(resolve, 300));
|
|
81
|
+
}
|
|
82
|
+
}
|
package/command.ts
CHANGED
package/commandHandler.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Command } from './command';
|
|
2
2
|
import { Simulator } from './simulator';
|
|
3
|
-
import { TUserAction, TClick, TClickOnCanvas,
|
|
3
|
+
import { TUserAction, TClick, TClickOnCanvas, TInput } from './types';
|
|
4
4
|
|
|
5
5
|
export function useCommandHandler() {
|
|
6
6
|
const handleCommand = async (command: string, data: TUserAction) => {
|
|
@@ -11,8 +11,12 @@ export function useCommandHandler() {
|
|
|
11
11
|
return simulator.simulateUserClick(data as TClick);
|
|
12
12
|
case Command.SimulateClickOnCanvas:
|
|
13
13
|
return simulator.simulateClickOnCanvas(data as TClickOnCanvas);
|
|
14
|
-
case Command.MainScaleFrame:
|
|
15
|
-
|
|
14
|
+
// case Command.MainScaleFrame:
|
|
15
|
+
// return simulator.simulateScaleFrame(data as TScaleFrame);
|
|
16
|
+
case Command.SimulateInput:
|
|
17
|
+
return simulator.simulateUserInput(data as TInput);
|
|
18
|
+
case Command.SimulateCheck:
|
|
19
|
+
return simulator.simulateUserCheck(data as TClick);
|
|
16
20
|
default:
|
|
17
21
|
console.warn('Unknown command:', command);
|
|
18
22
|
console.log(`SimulateUserAction command received with data:`, data);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "frame.simulator",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "A simulator for testing form interactions in a controlled environment.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"license": "MIT",
|
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
"frame.constants": "^1.0.5"
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
|
+
"@types/cors": "^2.8.19",
|
|
16
|
+
"@types/express": "^5.0.6",
|
|
15
17
|
"@types/node": "^25.3.0",
|
|
16
18
|
"cors": "^2.8.5",
|
|
17
19
|
"express": "^5.2.1",
|
package/simulator.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { green, red, reset } from 'frame.constants';
|
|
2
|
-
import { TClick, TClickOnCanvas,
|
|
2
|
+
import { TClick, TClickOnCanvas, TInput } from './types';
|
|
3
3
|
|
|
4
4
|
export class Simulator {
|
|
5
5
|
constructor() {
|
|
@@ -77,7 +77,8 @@ export class Simulator {
|
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
simulateUserInput(
|
|
80
|
+
simulateUserInput(data: TInput) {
|
|
81
|
+
const { testId, value } = data;
|
|
81
82
|
const element = this.findHTMLElement(testId, HTMLDivElement, 'input');
|
|
82
83
|
|
|
83
84
|
if (element) {
|
|
@@ -95,15 +96,15 @@ export class Simulator {
|
|
|
95
96
|
}
|
|
96
97
|
}
|
|
97
98
|
|
|
98
|
-
simulateScaleFrame(scaleValues: TScaleFrame) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
99
|
+
// simulateScaleFrame(scaleValues: TScaleFrame) {
|
|
100
|
+
// const { length, height } = scaleValues;
|
|
101
|
+
// console.log(
|
|
102
|
+
// `${red}Simulating scale frame with length: ${length}, height: ${height}${reset}`,
|
|
103
|
+
// );
|
|
104
|
+
// this.simulateUserInput('ScaleInput.input.length', length.toString());
|
|
105
|
+
// this.simulateUserInput('ScaleInput.input.height', height.toString());
|
|
106
|
+
// this.simulateUserCheck({ testId: 'ShowOptions.cbx.scaledBox' });
|
|
107
|
+
// this.simulateUserClick({ testId: 'ScaleForm.button.apply' });
|
|
108
|
+
// this.simulateUserCheck({ testId: 'ShowOptions.cbx.points' });
|
|
109
|
+
// }
|
|
109
110
|
}
|
package/types.ts
CHANGED
|
@@ -2,6 +2,11 @@ export type TClick = {
|
|
|
2
2
|
testId: string;
|
|
3
3
|
};
|
|
4
4
|
|
|
5
|
+
export type TInput = {
|
|
6
|
+
testId: string;
|
|
7
|
+
value: string;
|
|
8
|
+
};
|
|
9
|
+
|
|
5
10
|
export type TClickOnCanvas = {
|
|
6
11
|
x: number;
|
|
7
12
|
y: number;
|
|
@@ -12,4 +17,4 @@ export type TScaleFrame = {
|
|
|
12
17
|
height: number;
|
|
13
18
|
};
|
|
14
19
|
|
|
15
|
-
export type TUserAction = TClickOnCanvas | TScaleFrame | TClick;
|
|
20
|
+
export type TUserAction = TClickOnCanvas | TScaleFrame | TClick | TInput;
|