Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(codegen): add timeout to our actions, catch errors #5188

Merged
merged 1 commit into from
Jan 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/server/supplements/injected/recorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ export class Recorder {

private async _performAction(action: actions.Action) {
this._performingAction = true;
await window.playwrightRecorderPerformAction(action);
await window.playwrightRecorderPerformAction(action).catch(e => {});
this._performingAction = false;

// Action could have changed DOM, update hovered model selectors.
Expand Down
5 changes: 5 additions & 0 deletions src/server/supplements/recorder/codeGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ export class CodeGenerator {
this._currentAction = action;
}

performedActionFailed(action: ActionInContext) {
if (this._currentAction === action)
this._currentAction = undefined;
}

didPerformAction(actionInContext: ActionInContext) {
const { action, pageAlias } = actionInContext;
let eraseLastAction = false;
Expand Down
34 changes: 20 additions & 14 deletions src/server/supplements/recorderSupplement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,21 +194,27 @@ export class RecorderSupplement {
action
};
this._generator.willPerformAction(actionInContext);
if (action.name === 'click') {
const { options } = toClickOptions(action);
await frame.click(controller, action.selector, options);
}
if (action.name === 'press') {
const modifiers = toModifiers(action.modifiers);
const shortcut = [...modifiers, action.key].join('+');
await frame.press(controller, action.selector, shortcut);
try {
const kActionTimeout = 5000;
if (action.name === 'click') {
const { options } = toClickOptions(action);
await frame.click(controller, action.selector, { ...options, timeout: kActionTimeout });
}
if (action.name === 'press') {
const modifiers = toModifiers(action.modifiers);
const shortcut = [...modifiers, action.key].join('+');
await frame.press(controller, action.selector, shortcut, { timeout: kActionTimeout });
}
if (action.name === 'check')
await frame.check(controller, action.selector, { timeout: kActionTimeout });
if (action.name === 'uncheck')
await frame.uncheck(controller, action.selector, { timeout: kActionTimeout });
if (action.name === 'select')
await frame.selectOption(controller, action.selector, [], action.options.map(value => ({ value })), { timeout: kActionTimeout });
} catch (e) {
this._generator.performedActionFailed(actionInContext);
return;
}
if (action.name === 'check')
await frame.check(controller, action.selector);
if (action.name === 'uncheck')
await frame.uncheck(controller, action.selector);
if (action.name === 'select')
await frame.selectOption(controller, action.selector, [], action.options.map(value => ({ value })));
const timer = setTimeout(() => {
actionInContext.committed = true;
this._timers.delete(timer);
Expand Down