Skip to content

Commit

Permalink
Revert "refactor(waitFor): replaced .waitFor by its successor .waitFo…
Browse files Browse the repository at this point in the history
…rTimeout (#1277)"

This reverts commit 5702987.
  • Loading branch information
garris committed Feb 10, 2021
1 parent 5702987 commit f785123
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
10 changes: 5 additions & 5 deletions capture/engine_scripts/puppet/clickAndHoverHelper.js
Expand Up @@ -7,31 +7,31 @@ module.exports = async (page, scenario) => {

if (keyPressSelector) {
for (const keyPressSelectorItem of [].concat(keyPressSelector)) {
await page.waitForTimeout(keyPressSelectorItem.selector);
await page.waitFor(keyPressSelectorItem.selector);
await page.type(keyPressSelectorItem.selector, keyPressSelectorItem.keyPress);
}
}

if (hoverSelector) {
for (const hoverSelectorIndex of [].concat(hoverSelector)) {
await page.waitForTimeout(hoverSelectorIndex);
await page.waitFor(hoverSelectorIndex);
await page.hover(hoverSelectorIndex);
}
}

if (clickSelector) {
for (const clickSelectorIndex of [].concat(clickSelector)) {
await page.waitForTimeout(clickSelectorIndex);
await page.waitFor(clickSelectorIndex);
await page.click(clickSelectorIndex);
}
}

if (postInteractionWait) {
await page.waitForTimeout(postInteractionWait);
await page.waitFor(postInteractionWait);
}

if (scrollToSelector) {
await page.waitForTimeout(scrollToSelector);
await page.waitFor(scrollToSelector);
await page.evaluate(scrollToSelector => {
document.querySelector(scrollToSelector).scrollIntoView();
}, scrollToSelector);
Expand Down
4 changes: 2 additions & 2 deletions core/util/runPuppet.js
Expand Up @@ -132,13 +132,13 @@ async function processScenarioView (scenario, variantOrScenarioLabelSafe, scenar

// --- WAIT FOR SELECTOR ---
if (scenario.readySelector) {
await page.waitForTimeout(scenario.readySelector);
await page.waitFor(scenario.readySelector);
}
//

// --- DELAY ---
if (scenario.delay > 0) {
await page.waitForTimeout(scenario.delay);
await page.waitFor(scenario.delay);
}

// --- REMOVE SELECTORS ---
Expand Down
Expand Up @@ -4,16 +4,16 @@ module.exports = async (page, scenario) => {
const postInteractionWait = scenario.postInteractionWait; // selector [str] | ms [int]

if (hoverSelector) {
await page.waitForTimeout(hoverSelector);
await page.waitFor(hoverSelector);
await page.hover(hoverSelector);
}

if (clickSelector) {
await page.waitForTimeout(clickSelector);
await page.waitFor(clickSelector);
await page.click(clickSelector);
}

if (postInteractionWait) {
await page.waitForTimeout(postInteractionWait);
await page.waitFor(postInteractionWait);
}
};
Expand Up @@ -6,24 +6,24 @@ module.exports = async (page, scenario) => {

if (hoverSelector) {
for (const hoverSelectorIndex of [].concat(hoverSelector)) {
await page.waitForTimeout(hoverSelectorIndex);
await page.waitFor(hoverSelectorIndex);
await page.hover(hoverSelectorIndex);
}
}

if (clickSelector) {
for (const clickSelectorIndex of [].concat(clickSelector)) {
await page.waitForTimeout(clickSelectorIndex);
await page.waitFor(clickSelectorIndex);
await page.click(clickSelectorIndex);
}
}

if (postInteractionWait) {
await page.waitForTimeout(postInteractionWait);
await page.waitFor(postInteractionWait);
}

if (scrollToSelector) {
await page.waitForTimeout(scrollToSelector);
await page.waitFor(scrollToSelector);
await page.evaluate(scrollToSelector => {
document.querySelector(scrollToSelector).scrollIntoView();
}, scrollToSelector);
Expand Down
Expand Up @@ -7,27 +7,27 @@ module.exports = async (page, scenario) => {

if (keyPressSelector) {
for (const keyPressSelectorItem of [].concat(keyPressSelector)) {
await page.waitForTimeout(keyPressSelectorItem.selector);
await page.waitFor(keyPressSelectorItem.selector);
await page.type(keyPressSelectorItem.selector, keyPressSelectorItem.keyPress);
}
}

if (hoverSelector) {
await page.waitForTimeout(hoverSelector);
await page.waitFor(hoverSelector);
await page.hover(hoverSelector);
}

if (clickSelector) {
await page.waitForTimeout(clickSelector);
await page.waitFor(clickSelector);
await page.click(clickSelector);
}

if (postInteractionWait) {
await page.waitForTimeout(postInteractionWait);
await page.waitFor(postInteractionWait);
}

if (scrollToSelector) {
await page.waitForTimeout(scrollToSelector);
await page.waitFor(scrollToSelector);
await page.evaluate(scrollToSelector => {
document.querySelector(scrollToSelector).scrollIntoView();
}, scrollToSelector);
Expand Down

2 comments on commit f785123

@extra808
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading the Puppeteer Issue referenced in the waitFor is deprecated message, I think the mistake was replacing all instances of waitFor() with waitForTimeout(). The new function is only for when the argument is a number (milliseconds to wait) so only await page.waitForTimeout(scenario.delay); and await page.waitForTimeout(postInteractionWait); would be correct.

Just reading the argument names, the correct replacement for all the other instances is waitForSelector(). If any take functions as arguments instead of strings, waitForFunction() is the replacement.

@digitaldonkey
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. This cost me a lot of sleep 😫
Thanks for the revert.

Please sign in to comment.