Merge branch 'develop' into integration_airtable
This commit is contained in:
@@ -39,6 +39,7 @@ interface MetaData {
|
||||
pairs: number;
|
||||
updatedAt: string;
|
||||
params: string[],
|
||||
isLogin?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -97,6 +98,7 @@ export class WorkflowGenerator {
|
||||
pairs: 0,
|
||||
updatedAt: '',
|
||||
params: [],
|
||||
isLogin: false,
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -134,9 +136,9 @@ export class WorkflowGenerator {
|
||||
*/
|
||||
private registerEventHandlers = (socket: Socket) => {
|
||||
socket.on('save', (data) => {
|
||||
const { fileName, userId } = data;
|
||||
const { fileName, userId, isLogin } = data;
|
||||
logger.log('debug', `Saving workflow ${fileName} for user ID ${userId}`);
|
||||
this.saveNewWorkflow(fileName, userId);
|
||||
this.saveNewWorkflow(fileName, userId, isLogin);
|
||||
});
|
||||
socket.on('new-recording', () => this.workflowRecord = {
|
||||
workflow: [],
|
||||
@@ -425,6 +427,40 @@ export class WorkflowGenerator {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((elementInfo?.tagName === 'INPUT' || elementInfo?.tagName === 'TEXTAREA') && selector) {
|
||||
// Calculate the exact position within the element
|
||||
const elementPos = await page.evaluate((selector) => {
|
||||
const element = document.querySelector(selector);
|
||||
if (!element) return null;
|
||||
const rect = element.getBoundingClientRect();
|
||||
return {
|
||||
x: rect.left,
|
||||
y: rect.top
|
||||
};
|
||||
}, selector);
|
||||
|
||||
if (elementPos) {
|
||||
const relativeX = coordinates.x - elementPos.x;
|
||||
const relativeY = coordinates.y - elementPos.y;
|
||||
|
||||
const pair: WhereWhatPair = {
|
||||
where,
|
||||
what: [{
|
||||
action: 'click',
|
||||
args: [selector, { position: { x: relativeX, y: relativeY } }]
|
||||
}]
|
||||
};
|
||||
|
||||
if (selector) {
|
||||
this.generatedData.lastUsedSelector = selector;
|
||||
this.generatedData.lastAction = 'click';
|
||||
}
|
||||
|
||||
await this.addPairToWorkflowAndNotifyClient(pair, page);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//const element = await getElementMouseIsOver(page, coordinates);
|
||||
//logger.log('debug', `Element: ${JSON.stringify(element, null, 2)}`);
|
||||
if (selector) {
|
||||
@@ -474,6 +510,10 @@ export class WorkflowGenerator {
|
||||
public onKeyboardInput = async (key: string, coordinates: Coordinates, page: Page) => {
|
||||
let where: WhereWhatPair["where"] = { url: this.getBestUrl(page.url()) };
|
||||
const selector = await this.generateSelector(page, coordinates, ActionType.Keydown);
|
||||
|
||||
const elementInfo = await getElementInformation(page, coordinates, '', false);
|
||||
const inputType = elementInfo?.attributes?.type || "text";
|
||||
|
||||
if (selector) {
|
||||
where.selectors = [selector];
|
||||
}
|
||||
@@ -481,7 +521,7 @@ export class WorkflowGenerator {
|
||||
where,
|
||||
what: [{
|
||||
action: 'press',
|
||||
args: [selector, encrypt(key)],
|
||||
args: [selector, encrypt(key), inputType],
|
||||
}],
|
||||
}
|
||||
if (selector) {
|
||||
@@ -660,7 +700,7 @@ export class WorkflowGenerator {
|
||||
* @param fileName The name of the file.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
public saveNewWorkflow = async (fileName: string, userId: number) => {
|
||||
public saveNewWorkflow = async (fileName: string, userId: number, isLogin: boolean) => {
|
||||
const recording = this.optimizeWorkflow(this.workflowRecord);
|
||||
try {
|
||||
this.recordingMeta = {
|
||||
@@ -670,6 +710,7 @@ export class WorkflowGenerator {
|
||||
pairs: recording.workflow.length,
|
||||
updatedAt: new Date().toLocaleString(),
|
||||
params: this.getParams() || [],
|
||||
isLogin: isLogin,
|
||||
}
|
||||
const robot = await Robot.create({
|
||||
userId,
|
||||
@@ -991,6 +1032,7 @@ export class WorkflowGenerator {
|
||||
let input = {
|
||||
selector: '',
|
||||
value: '',
|
||||
type: '',
|
||||
actionCounter: 0,
|
||||
};
|
||||
|
||||
@@ -1005,7 +1047,7 @@ export class WorkflowGenerator {
|
||||
// when more than one press action is present, add a type action
|
||||
pair.what.splice(index - input.actionCounter, input.actionCounter, {
|
||||
action: 'type',
|
||||
args: [input.selector, encrypt(input.value)],
|
||||
args: [input.selector, encrypt(input.value), input.type],
|
||||
}, {
|
||||
action: 'waitForLoadState',
|
||||
args: ['networkidle'],
|
||||
@@ -1033,13 +1075,14 @@ export class WorkflowGenerator {
|
||||
action: 'waitForLoadState',
|
||||
args: ['networkidle'],
|
||||
})
|
||||
input = { selector: '', value: '', actionCounter: 0 };
|
||||
input = { selector: '', value: '', type: '', actionCounter: 0 };
|
||||
}
|
||||
} else {
|
||||
pushTheOptimizedAction(pair, index);
|
||||
input = {
|
||||
selector: condition.args[0],
|
||||
value: condition.args[1],
|
||||
type: condition.args[2],
|
||||
actionCounter: 1,
|
||||
};
|
||||
}
|
||||
@@ -1048,7 +1091,7 @@ export class WorkflowGenerator {
|
||||
if (input.value.length !== 0) {
|
||||
pushTheOptimizedAction(pair, index);
|
||||
// clear the input
|
||||
input = { selector: '', value: '', actionCounter: 0 };
|
||||
input = { selector: '', value: '', type: '', actionCounter: 0 };
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user