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: waiting for events should start right before the main step action #57

Merged
merged 1 commit into from
Mar 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/PuppeteerRunnerExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ export class PuppeteerRunnerExtension extends RunnerExtension {
timeout: number
): Promise<void> {
const waitForVisible = true;
const assertedEventsPromise = waitForEvents(localFrame, step, timeout);
let assertedEventsPromise = null;
const startWaitingForEvents = () => {
assertedEventsPromise = waitForEvents(localFrame, step, timeout);
};

switch (step.type) {
case 'click':
Expand All @@ -106,6 +109,7 @@ export class PuppeteerRunnerExtension extends RunnerExtension {
throw new Error('Could not find element: ' + step.selectors[0]);
}
await scrollIntoViewIfNeeded(element, timeout);
startWaitingForEvents();
await element.click({
offset: {
x: step.offsetX,
Expand All @@ -117,24 +121,28 @@ export class PuppeteerRunnerExtension extends RunnerExtension {
break;
case 'emulateNetworkConditions':
{
startWaitingForEvents();
await mainPage.emulateNetworkConditions(step);
}
break;
case 'keyDown':
{
startWaitingForEvents();
await mainPage.keyboard.down(step.key);
await mainPage.waitForTimeout(100);
}
break;
case 'keyUp':
{
startWaitingForEvents();
await mainPage.keyboard.up(step.key);
await mainPage.waitForTimeout(100);
}
break;
case 'close':
{
if ('close' in targetPageOrFrame) {
startWaitingForEvents();
await targetPageOrFrame.close();
}
}
Expand All @@ -150,6 +158,7 @@ export class PuppeteerRunnerExtension extends RunnerExtension {
/* c8 ignore next 1 */
(el: Element) => (el as HTMLInputElement).type
);
startWaitingForEvents();
if (typeableInputTypes.has(inputType)) {
const textToType = await element.evaluate(
(el: Element, newValue: string) => {
Expand Down Expand Up @@ -196,6 +205,7 @@ export class PuppeteerRunnerExtension extends RunnerExtension {
break;
case 'setViewport': {
if ('setViewport' in targetPageOrFrame) {
startWaitingForEvents();
await targetPageOrFrame.setViewport(step);
}
break;
Expand All @@ -207,6 +217,7 @@ export class PuppeteerRunnerExtension extends RunnerExtension {
visible: waitForVisible,
});
await scrollIntoViewIfNeeded(element, timeout);
startWaitingForEvents();
await element.evaluate(
(e: Element, x: number, y: number) => {
/* c8 ignore next 2 */
Expand All @@ -218,6 +229,7 @@ export class PuppeteerRunnerExtension extends RunnerExtension {
);
await element.dispose();
} else {
startWaitingForEvents();
await localFrame.evaluate(
(x, y) => {
/* c8 ignore next 1 */
Expand All @@ -230,11 +242,13 @@ export class PuppeteerRunnerExtension extends RunnerExtension {
break;
}
case 'navigate': {
startWaitingForEvents();
await localFrame.goto(step.url);
break;
}
case 'waitForElement': {
try {
startWaitingForEvents();
await waitForElement(step, localFrame, timeout);
} catch (err) {
if ((err as Error).message === 'Timed out') {
Expand All @@ -248,6 +262,7 @@ export class PuppeteerRunnerExtension extends RunnerExtension {
break;
}
case 'waitForExpression': {
startWaitingForEvents();
await localFrame.waitForFunction(step.expression, {
timeout,
});
Expand Down