Skip to content

Commit

Permalink
feat: move duration to click attributes (#507)
Browse files Browse the repository at this point in the history
All clicks have a duration (even double clicks [it's the last click])
associated with them within Chrome. We should reflect that here.
  • Loading branch information
jrandolf committed Apr 12, 2023
1 parent e6e53dd commit a87dbdd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/PuppeteerStringifyExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ export class PuppeteerStringifyExtension extends StringifyExtension {
this.#appendWaitForSelector(out, step);
out.appendLine('await element.click({');
out.appendLine(` clickCount: 2,`);
if (step.duration) {
out.appendLine(` delay: ${step.duration},`);
}
if (step.button) {
out.appendLine(` button: '${mouseButtonMap.get(step.button)}',`);
}
Expand Down
11 changes: 6 additions & 5 deletions src/Schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ export interface ClickAttributes {
* to the center of the element
*/
offsetY: number;
/**
* Delay (in ms) between the mouse up and mouse down of the click.
*
* @defaultValue `50`
*/
duration?: number;
}

export interface DoubleClickStep extends ClickAttributes, StepWithSelectors {
Expand All @@ -135,11 +141,6 @@ export interface DoubleClickStep extends ClickAttributes, StepWithSelectors {

export interface ClickStep extends ClickAttributes, StepWithSelectors {
type: StepType.Click;
/**
* Delay (in ms) between the mouse up and mouse down of the click. Defaults to
* 50ms.
*/
duration?: number;
}

export interface HoverStep extends StepWithSelectors {
Expand Down
2 changes: 1 addition & 1 deletion src/SchemaUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ function parseClickAttributes(step: object): ClickAttributes {
const attributes: ClickAttributes = {
offsetX: parseNumber(step, 'offsetX'),
offsetY: parseNumber(step, 'offsetY'),
duration: parseOptionalNumber(step, 'duration'),
};
const deviceType = parseOptionalString(step, 'deviceType');
if (deviceType) {
Expand Down Expand Up @@ -331,7 +332,6 @@ function parseClickStep(step: object): ClickStep {
...parseStepWithSelectors(StepType.Click, step),
...parseClickAttributes(step),
type: StepType.Click,
duration: parseOptionalNumber(step, 'duration'),
};
}

Expand Down

0 comments on commit a87dbdd

Please sign in to comment.