frame.simulator 1.0.5 → 1.0.7
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 +27 -14
- package/dist/batch.d.ts +2 -2
- package/dist/batch.js +22 -13
- package/dist/main.js +3 -35
- package/dist/simulator.js +2 -4
- package/main.ts +3 -41
- package/package.json +2 -2
- package/simulator.ts +2 -6
package/batch.ts
CHANGED
|
@@ -92,7 +92,7 @@ export class Batch {
|
|
|
92
92
|
async handleDrawFrame(item: any, index: number) {
|
|
93
93
|
const coordinates = item.payload.coordinates;
|
|
94
94
|
console.log(` Command[${index}]: MainDrawFrame`);
|
|
95
|
-
await this.
|
|
95
|
+
await this.selectButton('FDOptions.button.draw-frame');
|
|
96
96
|
|
|
97
97
|
const coords: { x: number; y: number }[] = coordinates.points;
|
|
98
98
|
for (const point of coords) {
|
|
@@ -101,7 +101,7 @@ export class Batch {
|
|
|
101
101
|
// await new Promise(resolve => setTimeout(resolve, 500));
|
|
102
102
|
await this.sampleClickCanvasDrawAt('canvas.draw', point.x, point.y); // Example click to trigger drawing (replace with actual coordinates if needed)
|
|
103
103
|
}
|
|
104
|
-
await this.
|
|
104
|
+
await this.selectButton('Finish.button.start-transformation'); // Example button click after drawing (replace with actual testId if needed)
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
async handleScaleFrame(item: any, index: number) {
|
|
@@ -113,9 +113,9 @@ export class Batch {
|
|
|
113
113
|
);
|
|
114
114
|
await this.selectInput('ScaleInput.input.length', length.toString());
|
|
115
115
|
await this.selectInput('ScaleInput.input.height', height.toString());
|
|
116
|
-
await this.
|
|
117
|
-
await this.
|
|
118
|
-
await this.
|
|
116
|
+
await this.selectCheckbox('ShowOptions.cbx.scaledBox');
|
|
117
|
+
await this.selectButton('ScaleForm.button.apply');
|
|
118
|
+
await this.selectCheckbox('ShowOptions.cbx.points');
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
async handleDefineTrademark(item: any, index: number) {
|
|
@@ -123,15 +123,7 @@ export class Batch {
|
|
|
123
123
|
console.log(` Command[${index}]: MainDefineTrademark`);
|
|
124
124
|
console.log(` Simulating trademark definition with name: ${name}`);
|
|
125
125
|
await this.selectInput('TrademarkInput.input.name', name);
|
|
126
|
-
await this.
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
async selectButtonSafe(testId: string): Promise<void> {
|
|
130
|
-
// Small delay to ensure element is fully ready
|
|
131
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
132
|
-
|
|
133
|
-
// Now click the button
|
|
134
|
-
await this.selectButton(testId);
|
|
126
|
+
await this.selectButton('TrademarkForm.button.apply');
|
|
135
127
|
}
|
|
136
128
|
|
|
137
129
|
private async sendRequest(
|
|
@@ -171,7 +163,13 @@ export class Batch {
|
|
|
171
163
|
testId: string,
|
|
172
164
|
retries: number = 5,
|
|
173
165
|
delay: number = 1000,
|
|
166
|
+
prepareDelay = 100,
|
|
174
167
|
): Promise<void> {
|
|
168
|
+
if (prepareDelay > 0) {
|
|
169
|
+
// Small delay to ensure element is fully ready
|
|
170
|
+
await new Promise((resolve) => setTimeout(resolve, prepareDelay));
|
|
171
|
+
}
|
|
172
|
+
|
|
175
173
|
const sleep = (ms: number) =>
|
|
176
174
|
new Promise((resolve) => setTimeout(resolve, ms));
|
|
177
175
|
|
|
@@ -198,6 +196,21 @@ export class Batch {
|
|
|
198
196
|
}
|
|
199
197
|
}
|
|
200
198
|
|
|
199
|
+
async selectCheckbox(
|
|
200
|
+
testId: string,
|
|
201
|
+
prepareDelay: number = 100,
|
|
202
|
+
): Promise<void> {
|
|
203
|
+
if (prepareDelay > 0) {
|
|
204
|
+
await new Promise((resolve) => setTimeout(resolve, prepareDelay));
|
|
205
|
+
}
|
|
206
|
+
const status = await this.sendRequest(Command.SimulateCheck, {
|
|
207
|
+
testId,
|
|
208
|
+
});
|
|
209
|
+
if (status !== 'ok') {
|
|
210
|
+
console.log('Failed to send checkbox simulation command');
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
201
214
|
async selectInput(testId: string, value: string): Promise<void> {
|
|
202
215
|
const status = await this.sendRequest(Command.SimulateInput, {
|
|
203
216
|
testId,
|
package/dist/batch.d.ts
CHANGED
|
@@ -6,9 +6,9 @@ export declare class Batch {
|
|
|
6
6
|
handleDrawFrame(item: any, index: number): Promise<void>;
|
|
7
7
|
handleScaleFrame(item: any, index: number): Promise<void>;
|
|
8
8
|
handleDefineTrademark(item: any, index: number): Promise<void>;
|
|
9
|
-
selectButtonSafe(testId: string): Promise<void>;
|
|
10
9
|
private sendRequest;
|
|
11
|
-
selectButton(testId: string, retries?: number, delay?: number): Promise<void>;
|
|
10
|
+
selectButton(testId: string, retries?: number, delay?: number, prepareDelay?: number): Promise<void>;
|
|
11
|
+
selectCheckbox(testId: string, prepareDelay?: number): Promise<void>;
|
|
12
12
|
selectInput(testId: string, value: string): Promise<void>;
|
|
13
13
|
sampleClickCanvasDrawAt(testId: string, x: number, y: number): Promise<void>;
|
|
14
14
|
}
|
package/dist/batch.js
CHANGED
|
@@ -78,7 +78,7 @@ export class Batch {
|
|
|
78
78
|
async handleDrawFrame(item, index) {
|
|
79
79
|
const coordinates = item.payload.coordinates;
|
|
80
80
|
console.log(` Command[${index}]: MainDrawFrame`);
|
|
81
|
-
await this.
|
|
81
|
+
await this.selectButton('FDOptions.button.draw-frame');
|
|
82
82
|
const coords = coordinates.points;
|
|
83
83
|
for (const point of coords) {
|
|
84
84
|
console.log(` Drawing point: (${point.x}, ${point.y})`);
|
|
@@ -86,7 +86,7 @@ export class Batch {
|
|
|
86
86
|
// await new Promise(resolve => setTimeout(resolve, 500));
|
|
87
87
|
await this.sampleClickCanvasDrawAt('canvas.draw', point.x, point.y); // Example click to trigger drawing (replace with actual coordinates if needed)
|
|
88
88
|
}
|
|
89
|
-
await this.
|
|
89
|
+
await this.selectButton('Finish.button.start-transformation'); // Example button click after drawing (replace with actual testId if needed)
|
|
90
90
|
}
|
|
91
91
|
async handleScaleFrame(item, index) {
|
|
92
92
|
const length = item.payload.length;
|
|
@@ -95,22 +95,16 @@ export class Batch {
|
|
|
95
95
|
console.log(` Simulating scale frame with length: ${length}, height: ${height}`);
|
|
96
96
|
await this.selectInput('ScaleInput.input.length', length.toString());
|
|
97
97
|
await this.selectInput('ScaleInput.input.height', height.toString());
|
|
98
|
-
await this.
|
|
99
|
-
await this.
|
|
100
|
-
await this.
|
|
98
|
+
await this.selectCheckbox('ShowOptions.cbx.scaledBox');
|
|
99
|
+
await this.selectButton('ScaleForm.button.apply');
|
|
100
|
+
await this.selectCheckbox('ShowOptions.cbx.points');
|
|
101
101
|
}
|
|
102
102
|
async handleDefineTrademark(item, index) {
|
|
103
103
|
const name = item.payload.name;
|
|
104
104
|
console.log(` Command[${index}]: MainDefineTrademark`);
|
|
105
105
|
console.log(` Simulating trademark definition with name: ${name}`);
|
|
106
106
|
await this.selectInput('TrademarkInput.input.name', name);
|
|
107
|
-
await this.
|
|
108
|
-
}
|
|
109
|
-
async selectButtonSafe(testId) {
|
|
110
|
-
// Small delay to ensure element is fully ready
|
|
111
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
112
|
-
// Now click the button
|
|
113
|
-
await this.selectButton(testId);
|
|
107
|
+
await this.selectButton('TrademarkForm.button.apply');
|
|
114
108
|
}
|
|
115
109
|
async sendRequest(command, data) {
|
|
116
110
|
let status = 'blocked';
|
|
@@ -139,7 +133,11 @@ export class Batch {
|
|
|
139
133
|
console.log(`return status: ${status}`);
|
|
140
134
|
return status;
|
|
141
135
|
}
|
|
142
|
-
async selectButton(testId, retries = 5, delay = 1000) {
|
|
136
|
+
async selectButton(testId, retries = 5, delay = 1000, prepareDelay = 100) {
|
|
137
|
+
if (prepareDelay > 0) {
|
|
138
|
+
// Small delay to ensure element is fully ready
|
|
139
|
+
await new Promise((resolve) => setTimeout(resolve, prepareDelay));
|
|
140
|
+
}
|
|
143
141
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
144
142
|
for (let attempt = 1; attempt <= retries; attempt++) {
|
|
145
143
|
try {
|
|
@@ -160,6 +158,17 @@ export class Batch {
|
|
|
160
158
|
}
|
|
161
159
|
}
|
|
162
160
|
}
|
|
161
|
+
async selectCheckbox(testId, prepareDelay = 100) {
|
|
162
|
+
if (prepareDelay > 0) {
|
|
163
|
+
await new Promise((resolve) => setTimeout(resolve, prepareDelay));
|
|
164
|
+
}
|
|
165
|
+
const status = await this.sendRequest(Command.SimulateCheck, {
|
|
166
|
+
testId,
|
|
167
|
+
});
|
|
168
|
+
if (status !== 'ok') {
|
|
169
|
+
console.log('Failed to send checkbox simulation command');
|
|
170
|
+
}
|
|
171
|
+
}
|
|
163
172
|
async selectInput(testId, value) {
|
|
164
173
|
const status = await this.sendRequest(Command.SimulateInput, {
|
|
165
174
|
testId,
|
package/dist/main.js
CHANGED
|
@@ -1,47 +1,15 @@
|
|
|
1
1
|
import { Batch } from './batch';
|
|
2
|
-
async function handleDrawFrame(batch, item, index) {
|
|
3
|
-
const coordinates = item.payload.coordinates;
|
|
4
|
-
console.log(` Command[${index}]: MainDrawFrame`);
|
|
5
|
-
await batch.selectButtonSafe('FDOptions.button.draw-frame');
|
|
6
|
-
const coords = coordinates.points;
|
|
7
|
-
for (const point of coords) {
|
|
8
|
-
console.log(` Drawing point: (${point.x}, ${point.y})`);
|
|
9
|
-
// Small delay between points to simulate drawing
|
|
10
|
-
// await new Promise(resolve => setTimeout(resolve, 500));
|
|
11
|
-
await batch.sampleClickCanvasDrawAt('canvas.draw', point.x, point.y); // Example click to trigger drawing (replace with actual coordinates if needed)
|
|
12
|
-
}
|
|
13
|
-
await batch.selectButtonSafe('Finish.button.start-transformation'); // Example button click after drawing (replace with actual testId if needed)
|
|
14
|
-
}
|
|
15
|
-
async function handleScaleFrame(batch, item, index) {
|
|
16
|
-
const length = item.payload.length;
|
|
17
|
-
const height = item.payload.height;
|
|
18
|
-
console.log(` Command[${index}]: MainScaleFrame`);
|
|
19
|
-
console.log(` Simulating scale frame with length: ${length}, height: ${height}`);
|
|
20
|
-
await batch.selectInput('ScaleInput.input.length', length.toString());
|
|
21
|
-
await batch.selectInput('ScaleInput.input.height', height.toString());
|
|
22
|
-
await batch.selectButtonSafe('ShowOptions.cbx.scaledBox');
|
|
23
|
-
await batch.selectButtonSafe('ScaleForm.button.apply');
|
|
24
|
-
await batch.selectButtonSafe('ShowOptions.cbx.points');
|
|
25
|
-
}
|
|
26
|
-
async function handleDefineTrademark(batch, item, index) {
|
|
27
|
-
const name = item.payload.name;
|
|
28
|
-
console.log(` Command[${index}]: MainDefineTrademark`);
|
|
29
|
-
console.log(` Simulating trademark definition with name: ${name}`);
|
|
30
|
-
await batch.selectInput('TrademarkInput.input.name', name);
|
|
31
|
-
await batch.selectButtonSafe('TrademarkForm.button.apply');
|
|
32
|
-
}
|
|
33
2
|
async function handleCommand(batch, item, index) {
|
|
34
|
-
// console.log(JSON.stringify(item, null, 2));
|
|
35
3
|
if (item.command) {
|
|
36
4
|
switch (item.command) {
|
|
37
5
|
case 'main-draw-frame':
|
|
38
|
-
await handleDrawFrame(
|
|
6
|
+
await batch.handleDrawFrame(item, index);
|
|
39
7
|
break;
|
|
40
8
|
case 'main-scale-frame':
|
|
41
|
-
await handleScaleFrame(
|
|
9
|
+
await batch.handleScaleFrame(item, index);
|
|
42
10
|
break;
|
|
43
11
|
case 'main-define-trademark':
|
|
44
|
-
await handleDefineTrademark(
|
|
12
|
+
await batch.handleDefineTrademark(item, index);
|
|
45
13
|
break;
|
|
46
14
|
default:
|
|
47
15
|
throw new Error(`Unknown command: ${item.command}`);
|
package/dist/simulator.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { green, reset } from 'frame.constants';
|
|
2
2
|
export class Simulator {
|
|
3
|
-
constructor() {
|
|
4
|
-
console.log('Simulator initialized');
|
|
5
|
-
}
|
|
3
|
+
constructor() { }
|
|
6
4
|
findHTMLElement(testId, elementType, type) {
|
|
7
5
|
if (type) {
|
|
8
|
-
console.log(
|
|
6
|
+
console.log(`Simulating ${green}${type}${reset} [${testId}]`);
|
|
9
7
|
}
|
|
10
8
|
const element = document.querySelector(`[data-testid="${testId}"]`);
|
|
11
9
|
if (element) {
|
package/main.ts
CHANGED
|
@@ -1,54 +1,16 @@
|
|
|
1
1
|
import { Batch } from './batch';
|
|
2
2
|
|
|
3
|
-
async function handleDrawFrame(batch: Batch, item: any, index: number) {
|
|
4
|
-
const coordinates = item.payload.coordinates;
|
|
5
|
-
console.log(` Command[${index}]: MainDrawFrame`);
|
|
6
|
-
await batch.selectButtonSafe('FDOptions.button.draw-frame');
|
|
7
|
-
|
|
8
|
-
const coords: { x: number; y: number }[] = coordinates.points;
|
|
9
|
-
for (const point of coords) {
|
|
10
|
-
console.log(` Drawing point: (${point.x}, ${point.y})`);
|
|
11
|
-
// Small delay between points to simulate drawing
|
|
12
|
-
// await new Promise(resolve => setTimeout(resolve, 500));
|
|
13
|
-
await batch.sampleClickCanvasDrawAt('canvas.draw', point.x, point.y); // Example click to trigger drawing (replace with actual coordinates if needed)
|
|
14
|
-
}
|
|
15
|
-
await batch.selectButtonSafe('Finish.button.start-transformation'); // Example button click after drawing (replace with actual testId if needed)
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
async function handleScaleFrame(batch: Batch, item: any, index: number) {
|
|
19
|
-
const length = item.payload.length;
|
|
20
|
-
const height = item.payload.height;
|
|
21
|
-
console.log(` Command[${index}]: MainScaleFrame`);
|
|
22
|
-
console.log(
|
|
23
|
-
` Simulating scale frame with length: ${length}, height: ${height}`,
|
|
24
|
-
);
|
|
25
|
-
await batch.selectInput('ScaleInput.input.length', length.toString());
|
|
26
|
-
await batch.selectInput('ScaleInput.input.height', height.toString());
|
|
27
|
-
await batch.selectButtonSafe('ShowOptions.cbx.scaledBox');
|
|
28
|
-
await batch.selectButtonSafe('ScaleForm.button.apply');
|
|
29
|
-
await batch.selectButtonSafe('ShowOptions.cbx.points');
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
async function handleDefineTrademark(batch: Batch, item: any, index: number) {
|
|
33
|
-
const name = item.payload.name;
|
|
34
|
-
console.log(` Command[${index}]: MainDefineTrademark`);
|
|
35
|
-
console.log(` Simulating trademark definition with name: ${name}`);
|
|
36
|
-
await batch.selectInput('TrademarkInput.input.name', name);
|
|
37
|
-
await batch.selectButtonSafe('TrademarkForm.button.apply');
|
|
38
|
-
}
|
|
39
|
-
|
|
40
3
|
async function handleCommand(batch: Batch, item: any, index: number) {
|
|
41
|
-
// console.log(JSON.stringify(item, null, 2));
|
|
42
4
|
if (item.command) {
|
|
43
5
|
switch (item.command) {
|
|
44
6
|
case 'main-draw-frame':
|
|
45
|
-
await handleDrawFrame(
|
|
7
|
+
await batch.handleDrawFrame(item, index);
|
|
46
8
|
break;
|
|
47
9
|
case 'main-scale-frame':
|
|
48
|
-
await handleScaleFrame(
|
|
10
|
+
await batch.handleScaleFrame(item, index);
|
|
49
11
|
break;
|
|
50
12
|
case 'main-define-trademark':
|
|
51
|
-
await handleDefineTrademark(
|
|
13
|
+
await batch.handleDefineTrademark(item, index);
|
|
52
14
|
break;
|
|
53
15
|
default:
|
|
54
16
|
throw new Error(`Unknown command: ${item.command}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "frame.simulator",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "A simulator for testing form interactions in a controlled environment.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@types/cors": "^2.8.19",
|
|
25
25
|
"@types/express": "^5.0.6",
|
|
26
|
-
"@types/node": "^25.3.
|
|
26
|
+
"@types/node": "^25.3.1",
|
|
27
27
|
"cors": "^2.8.5",
|
|
28
28
|
"express": "^5.2.1",
|
|
29
29
|
"frame.constants": "^1.0.5",
|
package/simulator.ts
CHANGED
|
@@ -2,9 +2,7 @@ import { green, reset } from 'frame.constants';
|
|
|
2
2
|
import { TClick, TClickOnCanvas, TInput } from './types';
|
|
3
3
|
|
|
4
4
|
export class Simulator {
|
|
5
|
-
constructor() {
|
|
6
|
-
console.log('Simulator initialized');
|
|
7
|
-
}
|
|
5
|
+
constructor() {}
|
|
8
6
|
|
|
9
7
|
findHTMLElement(
|
|
10
8
|
testId: string,
|
|
@@ -12,9 +10,7 @@ export class Simulator {
|
|
|
12
10
|
type?: string,
|
|
13
11
|
): HTMLElement | null {
|
|
14
12
|
if (type) {
|
|
15
|
-
console.log(
|
|
16
|
-
`${green}Simulating ${type} on element with testId: ${testId}${reset}`,
|
|
17
|
-
);
|
|
13
|
+
console.log(`Simulating ${green}${type}${reset} [${testId}]`);
|
|
18
14
|
}
|
|
19
15
|
const element = document.querySelector(`[data-testid="${testId}"]`);
|
|
20
16
|
if (element) {
|