frame.simulator 1.0.6 → 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 +20 -5
- package/dist/batch.d.ts +2 -1
- package/dist/batch.js +16 -5
- 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
|
@@ -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.
|
|
116
|
+
await this.selectCheckbox('ShowOptions.cbx.scaledBox');
|
|
117
117
|
await this.selectButton('ScaleForm.button.apply');
|
|
118
|
-
await this.
|
|
118
|
+
await this.selectCheckbox('ShowOptions.cbx.points');
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
async handleDefineTrademark(item: any, index: number) {
|
|
@@ -163,11 +163,11 @@ export class Batch {
|
|
|
163
163
|
testId: string,
|
|
164
164
|
retries: number = 5,
|
|
165
165
|
delay: number = 1000,
|
|
166
|
-
|
|
166
|
+
prepareDelay = 100,
|
|
167
167
|
): Promise<void> {
|
|
168
|
-
if (
|
|
168
|
+
if (prepareDelay > 0) {
|
|
169
169
|
// Small delay to ensure element is fully ready
|
|
170
|
-
await new Promise((resolve) => setTimeout(resolve,
|
|
170
|
+
await new Promise((resolve) => setTimeout(resolve, prepareDelay));
|
|
171
171
|
}
|
|
172
172
|
|
|
173
173
|
const sleep = (ms: number) =>
|
|
@@ -196,6 +196,21 @@ export class Batch {
|
|
|
196
196
|
}
|
|
197
197
|
}
|
|
198
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
|
+
|
|
199
214
|
async selectInput(testId: string, value: string): Promise<void> {
|
|
200
215
|
const status = await this.sendRequest(Command.SimulateInput, {
|
|
201
216
|
testId,
|
package/dist/batch.d.ts
CHANGED
|
@@ -7,7 +7,8 @@ export declare class Batch {
|
|
|
7
7
|
handleScaleFrame(item: any, index: number): Promise<void>;
|
|
8
8
|
handleDefineTrademark(item: any, index: number): Promise<void>;
|
|
9
9
|
private sendRequest;
|
|
10
|
-
selectButton(testId: string, retries?: number, delay?: number,
|
|
10
|
+
selectButton(testId: string, retries?: number, delay?: number, prepareDelay?: number): Promise<void>;
|
|
11
|
+
selectCheckbox(testId: string, prepareDelay?: number): Promise<void>;
|
|
11
12
|
selectInput(testId: string, value: string): Promise<void>;
|
|
12
13
|
sampleClickCanvasDrawAt(testId: string, x: number, y: number): Promise<void>;
|
|
13
14
|
}
|
package/dist/batch.js
CHANGED
|
@@ -95,9 +95,9 @@ 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.
|
|
98
|
+
await this.selectCheckbox('ShowOptions.cbx.scaledBox');
|
|
99
99
|
await this.selectButton('ScaleForm.button.apply');
|
|
100
|
-
await this.
|
|
100
|
+
await this.selectCheckbox('ShowOptions.cbx.points');
|
|
101
101
|
}
|
|
102
102
|
async handleDefineTrademark(item, index) {
|
|
103
103
|
const name = item.payload.name;
|
|
@@ -133,10 +133,10 @@ export class Batch {
|
|
|
133
133
|
console.log(`return status: ${status}`);
|
|
134
134
|
return status;
|
|
135
135
|
}
|
|
136
|
-
async selectButton(testId, retries = 5, delay = 1000,
|
|
137
|
-
if (
|
|
136
|
+
async selectButton(testId, retries = 5, delay = 1000, prepareDelay = 100) {
|
|
137
|
+
if (prepareDelay > 0) {
|
|
138
138
|
// Small delay to ensure element is fully ready
|
|
139
|
-
await new Promise((resolve) => setTimeout(resolve,
|
|
139
|
+
await new Promise((resolve) => setTimeout(resolve, prepareDelay));
|
|
140
140
|
}
|
|
141
141
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
142
142
|
for (let attempt = 1; attempt <= retries; attempt++) {
|
|
@@ -158,6 +158,17 @@ export class Batch {
|
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
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
|
+
}
|
|
161
172
|
async selectInput(testId, value) {
|
|
162
173
|
const status = await this.sendRequest(Command.SimulateInput, {
|
|
163
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.selectButton('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.selectButton('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.selectButton('ShowOptions.cbx.scaledBox');
|
|
23
|
-
await batch.selectButton('ScaleForm.button.apply');
|
|
24
|
-
await batch.selectButton('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.selectButton('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.selectButton('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.selectButton('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.selectButton('ShowOptions.cbx.scaledBox');
|
|
28
|
-
await batch.selectButton('ScaleForm.button.apply');
|
|
29
|
-
await batch.selectButton('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.selectButton('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) {
|