Skip to content

Commit

Permalink
refactor!: remove waitForTimeout (#11780)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lightning00Blade committed Feb 2, 2024
1 parent 4fc1402 commit 1900fa9
Show file tree
Hide file tree
Showing 7 changed files with 0 additions and 168 deletions.
1 change: 0 additions & 1 deletion docs/api/puppeteer.frame.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,4 @@ console.log(text);
| [waitForFunction(pageFunction, options, args)](./puppeteer.frame.waitforfunction.md) | | |
| [waitForNavigation(options)](./puppeteer.frame.waitfornavigation.md) | | <p>Waits for the frame to navigate. It is useful for when you run code which will indirectly cause the frame to navigate.</p><p>Usage of the [History API](https://developer.mozilla.org/en-US/docs/Web/API/History_API) to change the URL is considered a navigation.</p> |
| [waitForSelector(selector, options)](./puppeteer.frame.waitforselector.md) | | <p>Waits for an element matching the given selector to appear in the frame.</p><p>This method works across navigations.</p> |
| [waitForTimeout(milliseconds)](./puppeteer.frame.waitfortimeout.md) | | |
| [waitForXPath(xpath, options)](./puppeteer.frame.waitforxpath.md) | | |
41 changes: 0 additions & 41 deletions docs/api/puppeteer.frame.waitfortimeout.md

This file was deleted.

1 change: 0 additions & 1 deletion docs/api/puppeteer.page.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,5 @@ page.off('request', logRequest);
| [waitForRequest(urlOrPredicate, options)](./puppeteer.page.waitforrequest.md) | | |
| [waitForResponse(urlOrPredicate, options)](./puppeteer.page.waitforresponse.md) | | |
| [waitForSelector(selector, options)](./puppeteer.page.waitforselector.md) | | Wait for the <code>selector</code> to appear in page. If at the moment of calling the method the <code>selector</code> already exists, the method will return immediately. If the <code>selector</code> doesn't appear after the <code>timeout</code> milliseconds of waiting, the function will throw. |
| [waitForTimeout(milliseconds)](./puppeteer.page.waitfortimeout.md) | | |
| [waitForXPath(xpath, options)](./puppeteer.page.waitforxpath.md) | | Wait for the <code>xpath</code> to appear in page. If at the moment of calling the method the <code>xpath</code> already exists, the method will return immediately. If the <code>xpath</code> doesn't appear after the <code>timeout</code> milliseconds of waiting, the function will throw. |
| [workers()](./puppeteer.page.workers.md) | | All of the dedicated [WebWorkers](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API) associated with the page. |
41 changes: 0 additions & 41 deletions docs/api/puppeteer.page.waitfortimeout.md

This file was deleted.

26 changes: 0 additions & 26 deletions packages/puppeteer-core/src/api/Frame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1151,32 +1151,6 @@ export abstract class Frame extends EventEmitter<FrameEvents> {
await handle.type(text, options);
}

/**
* @deprecated Replace with `new Promise(r => setTimeout(r, milliseconds));`.
*
* Causes your script to wait for the given number of milliseconds.
*
* @remarks
* It's generally recommended to not wait for a number of seconds, but instead
* use {@link Frame.waitForSelector}, {@link Frame.waitForXPath} or
* {@link Frame.waitForFunction} to wait for exactly the conditions you want.
*
* @example
*
* Wait for 1 second:
*
* ```ts
* await frame.waitForTimeout(1000);
* ```
*
* @param milliseconds - the number of milliseconds to wait.
*/
async waitForTimeout(milliseconds: number): Promise<void> {
return await new Promise(resolve => {
setTimeout(resolve, milliseconds);
});
}

/**
* The frame's title.
*/
Expand Down
25 changes: 0 additions & 25 deletions packages/puppeteer-core/src/api/Page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2784,31 +2784,6 @@ export abstract class Page extends EventEmitter<PageEvents> {
return this.mainFrame().type(selector, text, options);
}

/**
* @deprecated Replace with `new Promise(r => setTimeout(r, milliseconds));`.
*
* Causes your script to wait for the given number of milliseconds.
*
* @remarks
*
* It's generally recommended to not wait for a number of seconds, but instead
* use {@link Frame.waitForSelector}, {@link Frame.waitForXPath} or
* {@link Frame.waitForFunction} to wait for exactly the conditions you want.
*
* @example
*
* Wait for 1 second:
*
* ```ts
* await page.waitForTimeout(1000);
* ```
*
* @param milliseconds - the number of milliseconds to wait.
*/
waitForTimeout(milliseconds: number): Promise<void> {
return this.mainFrame().waitForTimeout(milliseconds);
}

/**
* Wait for the `selector` to appear in page. If at the moment of calling the
* method the `selector` already exists, the method will return immediately. If
Expand Down
33 changes: 0 additions & 33 deletions test/src/waittask.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,39 +336,6 @@ describe('waittask specs', function () {
});
});

describe('Page.waitForTimeout', () => {
it('waits for the given timeout before resolving', async () => {
const {page, server} = await getTestState();
await page.goto(server.EMPTY_PAGE);
const startTime = Date.now();
await page.waitForTimeout(1000);
const endTime = Date.now();
/* In a perfect world endTime - startTime would be exactly 1000 but we
* expect some fluctuations and for it to be off by a little bit. So to
* avoid a flaky test we'll make sure it waited for roughly 1 second.
*/
expect(endTime - startTime).toBeGreaterThan(700);
expect(endTime - startTime).toBeLessThan(1300);
});
});

describe('Frame.waitForTimeout', () => {
it('waits for the given timeout before resolving', async () => {
const {page, server} = await getTestState();
await page.goto(server.EMPTY_PAGE);
const frame = page.mainFrame();
const startTime = Date.now();
await frame.waitForTimeout(1000);
const endTime = Date.now();
/* In a perfect world endTime - startTime would be exactly 1000 but we
* expect some fluctuations and for it to be off by a little bit. So to
* avoid a flaky test we'll make sure it waited for roughly 1 second
*/
expect(endTime - startTime).toBeGreaterThan(700);
expect(endTime - startTime).toBeLessThan(1300);
});
});

describe('Frame.waitForSelector', function () {
const addElement = (tag: string) => {
return document.body.appendChild(document.createElement(tag));
Expand Down

0 comments on commit 1900fa9

Please sign in to comment.