frame.simulator 1.0.3 → 1.0.5
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 +15 -12
- package/command.ts +1 -1
- package/commandHandler.ts +3 -3
- package/dist/batch.d.ts +14 -0
- package/dist/batch.js +182 -0
- package/dist/command-server.d.ts +3 -0
- package/dist/command.d.ts +6 -0
- package/dist/command.js +7 -0
- package/dist/commandHandler.d.ts +6 -0
- package/dist/commandHandler.js +22 -0
- package/dist/frame-simulator.cjs +1 -0
- package/dist/frame-simulator.js +60 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +4 -0
- package/dist/main.d.ts +1 -0
- package/dist/main.js +66 -0
- package/dist/simulator.d.ts +11 -0
- package/dist/simulator.js +81 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types.d.ts +16 -0
- package/dist/types.js +1 -0
- package/dist/vite.config.d.ts +2 -0
- package/dist/vite.config.js +21 -0
- package/package.json +13 -3
- package/simulator.ts +2 -2
- package/tsconfig.json +2 -1
- package/vite.config.ts +22 -0
package/batch.ts
CHANGED
|
@@ -3,14 +3,14 @@ import * as path from 'path';
|
|
|
3
3
|
import { Command } from './command';
|
|
4
4
|
import { TUserAction } from './types';
|
|
5
5
|
|
|
6
|
-
const PORT: number = parseInt(process.env.PORT || '3010', 10);
|
|
7
|
-
|
|
8
6
|
export class Batch {
|
|
9
7
|
private filename: string;
|
|
8
|
+
port: number;
|
|
10
9
|
|
|
11
|
-
constructor(filename: string) {
|
|
10
|
+
constructor(filename: string, port: number = 3010) {
|
|
12
11
|
const batchFilePath = path.join(process.cwd(), filename);
|
|
13
12
|
this.filename = batchFilePath;
|
|
13
|
+
this.port = port;
|
|
14
14
|
|
|
15
15
|
// Check if batch.json exists
|
|
16
16
|
if (!fs.existsSync(batchFilePath)) {
|
|
@@ -140,16 +140,19 @@ export class Batch {
|
|
|
140
140
|
): Promise<string> {
|
|
141
141
|
let status = 'blocked';
|
|
142
142
|
try {
|
|
143
|
-
const response = await fetch(
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
143
|
+
const response = await fetch(
|
|
144
|
+
`http://localhost:${this.port}/send-command`,
|
|
145
|
+
{
|
|
146
|
+
method: 'POST',
|
|
147
|
+
headers: {
|
|
148
|
+
'Content-Type': 'application/json',
|
|
149
|
+
},
|
|
150
|
+
body: JSON.stringify({
|
|
151
|
+
command,
|
|
152
|
+
data,
|
|
153
|
+
}),
|
|
147
154
|
},
|
|
148
|
-
|
|
149
|
-
command,
|
|
150
|
-
data,
|
|
151
|
-
}),
|
|
152
|
-
});
|
|
155
|
+
);
|
|
153
156
|
// console.log(`response: ${JSON.stringify(response, null)}`);
|
|
154
157
|
// console.log(`response.status: ${response.status}`);
|
|
155
158
|
if (response.status === 200) {
|
package/command.ts
CHANGED
package/commandHandler.ts
CHANGED
|
@@ -14,12 +14,12 @@ export function useCommandHandler() {
|
|
|
14
14
|
case Command.SimulateInput:
|
|
15
15
|
return simulator.simulateInput(data as TInput);
|
|
16
16
|
case Command.SimulateCheck:
|
|
17
|
-
return simulator.
|
|
17
|
+
return simulator.simulateCheck(data as TClick);
|
|
18
18
|
default:
|
|
19
19
|
console.warn('Unknown command:', command);
|
|
20
|
-
console.log(`
|
|
20
|
+
console.log(`useCommandHandler: command received with data:`, data);
|
|
21
21
|
throw new Error(
|
|
22
|
-
'
|
|
22
|
+
'command should be handled by useCommandHandler function',
|
|
23
23
|
);
|
|
24
24
|
}
|
|
25
25
|
};
|
package/dist/batch.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare class Batch {
|
|
2
|
+
private filename;
|
|
3
|
+
port: number;
|
|
4
|
+
constructor(filename: string, port?: number);
|
|
5
|
+
run(handleCommand: (batch: Batch, item: any, index: number) => Promise<void>): Promise<void>;
|
|
6
|
+
handleDrawFrame(item: any, index: number): Promise<void>;
|
|
7
|
+
handleScaleFrame(item: any, index: number): Promise<void>;
|
|
8
|
+
handleDefineTrademark(item: any, index: number): Promise<void>;
|
|
9
|
+
selectButtonSafe(testId: string): Promise<void>;
|
|
10
|
+
private sendRequest;
|
|
11
|
+
selectButton(testId: string, retries?: number, delay?: number): Promise<void>;
|
|
12
|
+
selectInput(testId: string, value: string): Promise<void>;
|
|
13
|
+
sampleClickCanvasDrawAt(testId: string, x: number, y: number): Promise<void>;
|
|
14
|
+
}
|
package/dist/batch.js
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import { Command } from './command';
|
|
4
|
+
export class Batch {
|
|
5
|
+
constructor(filename, port = 3010) {
|
|
6
|
+
const batchFilePath = path.join(process.cwd(), filename);
|
|
7
|
+
this.filename = batchFilePath;
|
|
8
|
+
this.port = port;
|
|
9
|
+
// Check if batch.json exists
|
|
10
|
+
if (!fs.existsSync(batchFilePath)) {
|
|
11
|
+
console.error('Error: batch.json file not found in the current directory');
|
|
12
|
+
process.exit(1);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
async run(handleCommand) {
|
|
16
|
+
try {
|
|
17
|
+
// Read the batch.json file
|
|
18
|
+
const fileContent = fs.readFileSync(this.filename, 'utf-8');
|
|
19
|
+
// Parse the JSON content
|
|
20
|
+
let batchData;
|
|
21
|
+
try {
|
|
22
|
+
batchData = JSON.parse(fileContent);
|
|
23
|
+
}
|
|
24
|
+
catch (parseError) {
|
|
25
|
+
console.error('Error: Invalid JSON in batch.json file');
|
|
26
|
+
console.error(parseError);
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
console.log('Processing batch.json...');
|
|
30
|
+
console.log('='.repeat(50));
|
|
31
|
+
// Check if batchData is an array or object
|
|
32
|
+
if (Array.isArray(batchData)) {
|
|
33
|
+
// If it's an array of objects, process each object sequentially
|
|
34
|
+
for (let index = 0; index < batchData.length; index++) {
|
|
35
|
+
// console.log(`Processing item ${index + 1}/${batchData.length}...`);
|
|
36
|
+
const item = batchData[index];
|
|
37
|
+
if (typeof item === 'object' && item !== null) {
|
|
38
|
+
// Print all keys in the object
|
|
39
|
+
await handleCommand(this, item, index + 1);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
console.log(` Not an object: ${item}`);
|
|
43
|
+
}
|
|
44
|
+
console.log('');
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else if (typeof batchData === 'object' && batchData !== null) {
|
|
48
|
+
// If it's a single object, print its keys
|
|
49
|
+
console.log('Root object keys:');
|
|
50
|
+
const keys = Object.keys(batchData);
|
|
51
|
+
keys.forEach((key) => {
|
|
52
|
+
console.log(` Key: ${key}`);
|
|
53
|
+
});
|
|
54
|
+
// If any values are also objects, print their keys too
|
|
55
|
+
keys.forEach((key) => {
|
|
56
|
+
const value = batchData[key];
|
|
57
|
+
if (typeof value === 'object' &&
|
|
58
|
+
value !== null &&
|
|
59
|
+
!Array.isArray(value)) {
|
|
60
|
+
console.log(`\nKeys in "${key}" object:`);
|
|
61
|
+
Object.keys(value).forEach((subKey) => {
|
|
62
|
+
console.log(` Key: ${subKey}`);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
console.log('Error: batch.json should contain an object or array of objects');
|
|
69
|
+
process.exit(1);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
console.error('Error processing batch.json:');
|
|
74
|
+
console.error(error);
|
|
75
|
+
process.exit(1);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
async handleDrawFrame(item, index) {
|
|
79
|
+
const coordinates = item.payload.coordinates;
|
|
80
|
+
console.log(` Command[${index}]: MainDrawFrame`);
|
|
81
|
+
await this.selectButtonSafe('FDOptions.button.draw-frame');
|
|
82
|
+
const coords = coordinates.points;
|
|
83
|
+
for (const point of coords) {
|
|
84
|
+
console.log(` Drawing point: (${point.x}, ${point.y})`);
|
|
85
|
+
// Small delay between points to simulate drawing
|
|
86
|
+
// await new Promise(resolve => setTimeout(resolve, 500));
|
|
87
|
+
await this.sampleClickCanvasDrawAt('canvas.draw', point.x, point.y); // Example click to trigger drawing (replace with actual coordinates if needed)
|
|
88
|
+
}
|
|
89
|
+
await this.selectButtonSafe('Finish.button.start-transformation'); // Example button click after drawing (replace with actual testId if needed)
|
|
90
|
+
}
|
|
91
|
+
async handleScaleFrame(item, index) {
|
|
92
|
+
const length = item.payload.length;
|
|
93
|
+
const height = item.payload.height;
|
|
94
|
+
console.log(` Command[${index}]: MainScaleFrame`);
|
|
95
|
+
console.log(` Simulating scale frame with length: ${length}, height: ${height}`);
|
|
96
|
+
await this.selectInput('ScaleInput.input.length', length.toString());
|
|
97
|
+
await this.selectInput('ScaleInput.input.height', height.toString());
|
|
98
|
+
await this.selectButtonSafe('ShowOptions.cbx.scaledBox');
|
|
99
|
+
await this.selectButtonSafe('ScaleForm.button.apply');
|
|
100
|
+
await this.selectButtonSafe('ShowOptions.cbx.points');
|
|
101
|
+
}
|
|
102
|
+
async handleDefineTrademark(item, index) {
|
|
103
|
+
const name = item.payload.name;
|
|
104
|
+
console.log(` Command[${index}]: MainDefineTrademark`);
|
|
105
|
+
console.log(` Simulating trademark definition with name: ${name}`);
|
|
106
|
+
await this.selectInput('TrademarkInput.input.name', name);
|
|
107
|
+
await this.selectButtonSafe('TrademarkForm.button.apply');
|
|
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);
|
|
114
|
+
}
|
|
115
|
+
async sendRequest(command, data) {
|
|
116
|
+
let status = 'blocked';
|
|
117
|
+
try {
|
|
118
|
+
const response = await fetch(`http://localhost:${this.port}/send-command`, {
|
|
119
|
+
method: 'POST',
|
|
120
|
+
headers: {
|
|
121
|
+
'Content-Type': 'application/json',
|
|
122
|
+
},
|
|
123
|
+
body: JSON.stringify({
|
|
124
|
+
command,
|
|
125
|
+
data,
|
|
126
|
+
}),
|
|
127
|
+
});
|
|
128
|
+
// console.log(`response: ${JSON.stringify(response, null)}`);
|
|
129
|
+
// console.log(`response.status: ${response.status}`);
|
|
130
|
+
if (response.status === 200) {
|
|
131
|
+
status = 'ok';
|
|
132
|
+
}
|
|
133
|
+
return status;
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
console.log(`error.status: ${status}`);
|
|
137
|
+
console.error('Error:', error);
|
|
138
|
+
}
|
|
139
|
+
console.log(`return status: ${status}`);
|
|
140
|
+
return status;
|
|
141
|
+
}
|
|
142
|
+
async selectButton(testId, retries = 5, delay = 1000) {
|
|
143
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
144
|
+
for (let attempt = 1; attempt <= retries; attempt++) {
|
|
145
|
+
try {
|
|
146
|
+
if (attempt >= 1) {
|
|
147
|
+
console.log(`Attempt ${attempt}/${retries} to click button: ${testId}`);
|
|
148
|
+
}
|
|
149
|
+
const status = await this.sendRequest(Command.SimulateClick, {
|
|
150
|
+
testId,
|
|
151
|
+
});
|
|
152
|
+
if (status !== 'ok') {
|
|
153
|
+
console.log('Failed to send button simulation command');
|
|
154
|
+
}
|
|
155
|
+
await sleep(delay);
|
|
156
|
+
return; // Success, exit the retry loop
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
console.error('Error in main:', error);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
async selectInput(testId, value) {
|
|
164
|
+
const status = await this.sendRequest(Command.SimulateInput, {
|
|
165
|
+
testId,
|
|
166
|
+
value,
|
|
167
|
+
});
|
|
168
|
+
if (status !== 'ok') {
|
|
169
|
+
console.log('Failed to send input simulation command');
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
async sampleClickCanvasDrawAt(testId, x, y) {
|
|
173
|
+
console.log(`sampleClickCanvasDrawAt(${x}, ${y})`);
|
|
174
|
+
await this.sendRequest(Command.SimulateClickOnCanvas, {
|
|
175
|
+
testId,
|
|
176
|
+
x,
|
|
177
|
+
y,
|
|
178
|
+
});
|
|
179
|
+
// Small delay to ensure element is fully ready
|
|
180
|
+
await new Promise((resolve) => setTimeout(resolve, 300));
|
|
181
|
+
}
|
|
182
|
+
}
|
package/dist/command.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export var Command;
|
|
2
|
+
(function (Command) {
|
|
3
|
+
Command["SimulateClick"] = "SimulateClick";
|
|
4
|
+
Command["SimulateClickOnCanvas"] = "SimulateClickOnCanvas";
|
|
5
|
+
Command["SimulateInput"] = "SimulateInput";
|
|
6
|
+
Command["SimulateCheck"] = "SimulateCheck";
|
|
7
|
+
})(Command || (Command = {}));
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Command } from './command';
|
|
2
|
+
import { Simulator } from './simulator';
|
|
3
|
+
export function useCommandHandler() {
|
|
4
|
+
const handleCommand = async (command, data) => {
|
|
5
|
+
const simulator = new Simulator();
|
|
6
|
+
switch (command) {
|
|
7
|
+
case Command.SimulateClick:
|
|
8
|
+
return simulator.simulateClick(data);
|
|
9
|
+
case Command.SimulateClickOnCanvas:
|
|
10
|
+
return simulator.simulateClickOnCanvas(data);
|
|
11
|
+
case Command.SimulateInput:
|
|
12
|
+
return simulator.simulateInput(data);
|
|
13
|
+
case Command.SimulateCheck:
|
|
14
|
+
return simulator.simulateCheck(data);
|
|
15
|
+
default:
|
|
16
|
+
console.warn('Unknown command:', command);
|
|
17
|
+
console.log(`useCommandHandler: command received with data:`, data);
|
|
18
|
+
throw new Error('command should be handled by useCommandHandler function');
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
return { handleCommand };
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("frame.constants");class o{constructor(){console.log("Simulator initialized")}findHTMLElement(n,i,t){t&&console.log(`${c.green}Simulating ${t} on element with testId: ${n}${c.reset}`);const e=document.querySelector(`[data-testid="${n}"]`);return e?e instanceof i||console.error(`Element found but not a ${i.name} for ${t} simulation: ${n}`):console.error(`Element not found for ${t} simulation: ${n}`),e}simulateClickOnCanvas(n){const{x:i,y:t}=n,e=this.findHTMLElement("canvas.draw",HTMLCanvasElement,"click");if(e){const s=e.getBoundingClientRect(),l=new MouseEvent("click",{clientX:s.left+s.width/2+i,clientY:s.top+s.height/2-t,bubbles:!0});l.isBatch=!0,l.batchX=i,l.batchY=t,e.dispatchEvent(l)}}simulateClick(n){const{testId:i}=n,t=this.findHTMLElement(i,HTMLButtonElement,"click");if(t){const e=new MouseEvent("click",{bubbles:!0});e.isBatch=!0,t.click()}}simulateCheck(n){const{testId:i}=n,t=this.findHTMLElement(i,HTMLInputElement,"check");if(t){const e=new MouseEvent("click",{bubbles:!0});e.isBatch=!0,t.dispatchEvent(e)}}simulateInput(n){const{testId:i,value:t}=n,e=this.findHTMLElement(i,HTMLDivElement,"input");if(e){if(e instanceof HTMLInputElement)return e.value=t.toString(),e.dispatchEvent(new Event("input",{bubbles:!0})),{status:"ok"};if(e instanceof HTMLDivElement){const s=e.firstChild;s instanceof HTMLInputElement&&(s.value=t||"",s.dispatchEvent(new Event("input",{bubbles:!0})))}}}}exports.Simulator=o;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { green as c, reset as o } from "frame.constants";
|
|
2
|
+
class r {
|
|
3
|
+
constructor() {
|
|
4
|
+
console.log("Simulator initialized");
|
|
5
|
+
}
|
|
6
|
+
findHTMLElement(n, i, t) {
|
|
7
|
+
t && console.log(
|
|
8
|
+
`${c}Simulating ${t} on element with testId: ${n}${o}`
|
|
9
|
+
);
|
|
10
|
+
const e = document.querySelector(`[data-testid="${n}"]`);
|
|
11
|
+
return e ? e instanceof i || console.error(
|
|
12
|
+
`Element found but not a ${i.name} for ${t} simulation: ${n}`
|
|
13
|
+
) : console.error(`Element not found for ${t} simulation: ${n}`), e;
|
|
14
|
+
}
|
|
15
|
+
simulateClickOnCanvas(n) {
|
|
16
|
+
const { x: i, y: t } = n, e = this.findHTMLElement(
|
|
17
|
+
"canvas.draw",
|
|
18
|
+
HTMLCanvasElement,
|
|
19
|
+
"click"
|
|
20
|
+
);
|
|
21
|
+
if (e) {
|
|
22
|
+
const s = e.getBoundingClientRect(), l = new MouseEvent("click", {
|
|
23
|
+
clientX: s.left + s.width / 2 + i,
|
|
24
|
+
// Convert canvas-relative to screen coordinates
|
|
25
|
+
clientY: s.top + s.height / 2 - t,
|
|
26
|
+
// Convert canvas-relative to screen coordinates (flip Y)
|
|
27
|
+
bubbles: !0
|
|
28
|
+
});
|
|
29
|
+
l.isBatch = !0, l.batchX = i, l.batchY = t, e.dispatchEvent(l);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
simulateClick(n) {
|
|
33
|
+
const { testId: i } = n, t = this.findHTMLElement(i, HTMLButtonElement, "click");
|
|
34
|
+
if (t) {
|
|
35
|
+
const e = new MouseEvent("click", { bubbles: !0 });
|
|
36
|
+
e.isBatch = !0, t.click();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
simulateCheck(n) {
|
|
40
|
+
const { testId: i } = n, t = this.findHTMLElement(i, HTMLInputElement, "check");
|
|
41
|
+
if (t) {
|
|
42
|
+
const e = new MouseEvent("click", { bubbles: !0 });
|
|
43
|
+
e.isBatch = !0, t.dispatchEvent(e);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
simulateInput(n) {
|
|
47
|
+
const { testId: i, value: t } = n, e = this.findHTMLElement(i, HTMLDivElement, "input");
|
|
48
|
+
if (e) {
|
|
49
|
+
if (e instanceof HTMLInputElement)
|
|
50
|
+
return e.value = t.toString(), e.dispatchEvent(new Event("input", { bubbles: !0 })), { status: "ok" };
|
|
51
|
+
if (e instanceof HTMLDivElement) {
|
|
52
|
+
const s = e.firstChild;
|
|
53
|
+
s instanceof HTMLInputElement && (s.value = t || "", s.dispatchEvent(new Event("input", { bubbles: !0 })));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
export {
|
|
59
|
+
r as Simulator
|
|
60
|
+
};
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/dist/main.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/main.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
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
|
+
async function handleCommand(batch, item, index) {
|
|
34
|
+
// console.log(JSON.stringify(item, null, 2));
|
|
35
|
+
if (item.command) {
|
|
36
|
+
switch (item.command) {
|
|
37
|
+
case 'main-draw-frame':
|
|
38
|
+
await handleDrawFrame(batch, item, index);
|
|
39
|
+
break;
|
|
40
|
+
case 'main-scale-frame':
|
|
41
|
+
await handleScaleFrame(batch, item, index);
|
|
42
|
+
break;
|
|
43
|
+
case 'main-define-trademark':
|
|
44
|
+
await handleDefineTrademark(batch, item, index);
|
|
45
|
+
break;
|
|
46
|
+
default:
|
|
47
|
+
throw new Error(`Unknown command: ${item.command}`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
console.log('No command found in this item.');
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async function main(batchFile) {
|
|
55
|
+
try {
|
|
56
|
+
const batch = new Batch(batchFile);
|
|
57
|
+
await batch.run(handleCommand);
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
console.error('Error in main:', error);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// Accept batch file path as command-line argument
|
|
64
|
+
const batchFileArg = process.argv[2] || 'batch.json';
|
|
65
|
+
console.log(`Starting batch processing with file: ${batchFileArg}`);
|
|
66
|
+
main(batchFileArg);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { TClick, TClickOnCanvas, TInput } from './types';
|
|
2
|
+
export declare class Simulator {
|
|
3
|
+
constructor();
|
|
4
|
+
findHTMLElement(testId: string, elementType: typeof HTMLElement, type?: string): HTMLElement | null;
|
|
5
|
+
simulateClickOnCanvas(data: TClickOnCanvas): void;
|
|
6
|
+
simulateClick(data: TClick): void;
|
|
7
|
+
simulateCheck(data: TClick): void;
|
|
8
|
+
simulateInput(data: TInput): {
|
|
9
|
+
status: string;
|
|
10
|
+
} | undefined;
|
|
11
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { green, reset } from 'frame.constants';
|
|
2
|
+
export class Simulator {
|
|
3
|
+
constructor() {
|
|
4
|
+
console.log('Simulator initialized');
|
|
5
|
+
}
|
|
6
|
+
findHTMLElement(testId, elementType, type) {
|
|
7
|
+
if (type) {
|
|
8
|
+
console.log(`${green}Simulating ${type} on element with testId: ${testId}${reset}`);
|
|
9
|
+
}
|
|
10
|
+
const element = document.querySelector(`[data-testid="${testId}"]`);
|
|
11
|
+
if (element) {
|
|
12
|
+
if (element instanceof elementType) {
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
console.error(`Element found but not a ${elementType.name} for ${type} simulation: ${testId}`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
console.error(`Element not found for ${type} simulation: ${testId}`);
|
|
20
|
+
}
|
|
21
|
+
return element;
|
|
22
|
+
}
|
|
23
|
+
simulateClickOnCanvas(data) {
|
|
24
|
+
const { x, y } = data;
|
|
25
|
+
const canvas = this.findHTMLElement('canvas.draw', HTMLCanvasElement, 'click');
|
|
26
|
+
if (canvas) {
|
|
27
|
+
const rect = canvas.getBoundingClientRect();
|
|
28
|
+
const event = new MouseEvent('click', {
|
|
29
|
+
clientX: rect.left + rect.width / 2 + x, // Convert canvas-relative to screen coordinates
|
|
30
|
+
clientY: rect.top + rect.height / 2 - y, // Convert canvas-relative to screen coordinates (flip Y)
|
|
31
|
+
bubbles: true,
|
|
32
|
+
});
|
|
33
|
+
// Set batch properties
|
|
34
|
+
// @ts-ignore - Add custom properties for batch identification
|
|
35
|
+
event.isBatch = true;
|
|
36
|
+
// @ts-ignore - Store original canvas-relative coordinates
|
|
37
|
+
event.batchX = x;
|
|
38
|
+
// @ts-ignore - Store original canvas-relative coordinates
|
|
39
|
+
event.batchY = y;
|
|
40
|
+
canvas.dispatchEvent(event);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
simulateClick(data) {
|
|
44
|
+
const { testId } = data;
|
|
45
|
+
const element = this.findHTMLElement(testId, HTMLButtonElement, 'click');
|
|
46
|
+
if (element) {
|
|
47
|
+
const event = new MouseEvent('click', { bubbles: true });
|
|
48
|
+
// @ts-ignore - Add custom property to identify this as a batch click
|
|
49
|
+
event.isBatch = true;
|
|
50
|
+
element.click();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
simulateCheck(data) {
|
|
54
|
+
const { testId } = data;
|
|
55
|
+
const element = this.findHTMLElement(testId, HTMLInputElement, 'check');
|
|
56
|
+
if (element) {
|
|
57
|
+
const event = new MouseEvent('click', { bubbles: true });
|
|
58
|
+
// @ts-ignore - Add custom property to identify this as a batch click
|
|
59
|
+
event.isBatch = true;
|
|
60
|
+
element.dispatchEvent(event);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
simulateInput(data) {
|
|
64
|
+
const { testId, value } = data;
|
|
65
|
+
const element = this.findHTMLElement(testId, HTMLDivElement, 'input');
|
|
66
|
+
if (element) {
|
|
67
|
+
if (element instanceof HTMLInputElement) {
|
|
68
|
+
element.value = value.toString();
|
|
69
|
+
element.dispatchEvent(new Event('input', { bubbles: true }));
|
|
70
|
+
return { status: 'ok' };
|
|
71
|
+
}
|
|
72
|
+
else if (element instanceof HTMLDivElement) {
|
|
73
|
+
const childElement = element.firstChild;
|
|
74
|
+
if (childElement instanceof HTMLInputElement) {
|
|
75
|
+
childElement.value = value || '';
|
|
76
|
+
childElement.dispatchEvent(new Event('input', { bubbles: true }));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"root":["../batch.ts","../command-server.ts","../command.ts","../commandhandler.ts","../index.ts","../main.ts","../simulator.ts","../types.ts","../vite.config.ts"],"version":"5.6.3"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type TClick = {
|
|
2
|
+
testId: string;
|
|
3
|
+
};
|
|
4
|
+
export type TInput = {
|
|
5
|
+
testId: string;
|
|
6
|
+
value: string;
|
|
7
|
+
};
|
|
8
|
+
export type TClickOnCanvas = {
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
};
|
|
12
|
+
export type TScaleFrame = {
|
|
13
|
+
length: number;
|
|
14
|
+
height: number;
|
|
15
|
+
};
|
|
16
|
+
export type TUserAction = TClickOnCanvas | TScaleFrame | TClick | TInput;
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { defineConfig } from 'vite';
|
|
2
|
+
import tsconfigPaths from 'vite-tsconfig-paths';
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
plugins: [tsconfigPaths()],
|
|
5
|
+
build: {
|
|
6
|
+
lib: {
|
|
7
|
+
entry: './simulator.ts',
|
|
8
|
+
name: 'FrameSimulator',
|
|
9
|
+
fileName: 'frame-simulator',
|
|
10
|
+
formats: ['es', 'cjs'],
|
|
11
|
+
},
|
|
12
|
+
rollupOptions: {
|
|
13
|
+
external: ['frame.constants'],
|
|
14
|
+
output: {
|
|
15
|
+
globals: {
|
|
16
|
+
'frame.constants': 'frameConstants',
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
});
|
package/package.json
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "frame.simulator",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "A simulator for testing form interactions in a controlled environment.",
|
|
5
|
-
"main": "index.js",
|
|
6
5
|
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"require": "./dist/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
7
15
|
"scripts": {
|
|
8
16
|
"build": "tsc -b",
|
|
9
17
|
"command-server": "tsx command-server.ts",
|
|
@@ -19,6 +27,8 @@
|
|
|
19
27
|
"cors": "^2.8.5",
|
|
20
28
|
"express": "^5.2.1",
|
|
21
29
|
"frame.constants": "^1.0.5",
|
|
22
|
-
"tsx": "^4.21.0"
|
|
30
|
+
"tsx": "^4.21.0",
|
|
31
|
+
"vite": "^7.3.1",
|
|
32
|
+
"vite-tsconfig-paths": "^6.1.1"
|
|
23
33
|
}
|
|
24
34
|
}
|
package/simulator.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { green,
|
|
1
|
+
import { green, reset } from 'frame.constants';
|
|
2
2
|
import { TClick, TClickOnCanvas, TInput } from './types';
|
|
3
3
|
|
|
4
4
|
export class Simulator {
|
|
@@ -66,7 +66,7 @@ export class Simulator {
|
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
simulateCheck(data: TClick) {
|
|
70
70
|
const { testId } = data;
|
|
71
71
|
const element = this.findHTMLElement(testId, HTMLInputElement, 'check');
|
|
72
72
|
if (element) {
|
package/tsconfig.json
CHANGED
package/vite.config.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { defineConfig } from 'vite';
|
|
2
|
+
import tsconfigPaths from 'vite-tsconfig-paths';
|
|
3
|
+
|
|
4
|
+
export default defineConfig({
|
|
5
|
+
plugins: [tsconfigPaths()],
|
|
6
|
+
build: {
|
|
7
|
+
lib: {
|
|
8
|
+
entry: './simulator.ts',
|
|
9
|
+
name: 'FrameSimulator',
|
|
10
|
+
fileName: 'frame-simulator',
|
|
11
|
+
formats: ['es', 'cjs'],
|
|
12
|
+
},
|
|
13
|
+
rollupOptions: {
|
|
14
|
+
external: ['frame.constants'],
|
|
15
|
+
output: {
|
|
16
|
+
globals: {
|
|
17
|
+
'frame.constants': 'frameConstants',
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
});
|