mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
refactor!: remove waitForTimeout (#11780)
This commit is contained in:
parent
4fc14026e9
commit
1900fa9418
@ -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) | | |
|
||||
|
@ -1,41 +0,0 @@
|
||||
---
|
||||
sidebar_label: Frame.waitForTimeout
|
||||
---
|
||||
|
||||
# Frame.waitForTimeout() method
|
||||
|
||||
> Warning: This API is now obsolete.
|
||||
>
|
||||
> Replace with `new Promise(r => setTimeout(r, milliseconds));`.
|
||||
>
|
||||
> Causes your script to wait for the given number of milliseconds.
|
||||
|
||||
#### Signature:
|
||||
|
||||
```typescript
|
||||
class Frame {
|
||||
waitForTimeout(milliseconds: number): Promise<void>;
|
||||
}
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| ------------ | ------ | ----------------------------------- |
|
||||
| milliseconds | number | the number of milliseconds to wait. |
|
||||
|
||||
**Returns:**
|
||||
|
||||
Promise<void>
|
||||
|
||||
## Remarks
|
||||
|
||||
It's generally recommended to not wait for a number of seconds, but instead use [Frame.waitForSelector()](./puppeteer.frame.waitforselector.md), [Frame.waitForXPath()](./puppeteer.frame.waitforxpath.md) or [Frame.waitForFunction()](./puppeteer.frame.waitforfunction.md) to wait for exactly the conditions you want.
|
||||
|
||||
## Example
|
||||
|
||||
Wait for 1 second:
|
||||
|
||||
```ts
|
||||
await frame.waitForTimeout(1000);
|
||||
```
|
@ -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. |
|
||||
|
@ -1,41 +0,0 @@
|
||||
---
|
||||
sidebar_label: Page.waitForTimeout
|
||||
---
|
||||
|
||||
# Page.waitForTimeout() method
|
||||
|
||||
> Warning: This API is now obsolete.
|
||||
>
|
||||
> Replace with `new Promise(r => setTimeout(r, milliseconds));`.
|
||||
>
|
||||
> Causes your script to wait for the given number of milliseconds.
|
||||
|
||||
#### Signature:
|
||||
|
||||
```typescript
|
||||
class Page {
|
||||
waitForTimeout(milliseconds: number): Promise<void>;
|
||||
}
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| ------------ | ------ | ----------------------------------- |
|
||||
| milliseconds | number | the number of milliseconds to wait. |
|
||||
|
||||
**Returns:**
|
||||
|
||||
Promise<void>
|
||||
|
||||
## Remarks
|
||||
|
||||
It's generally recommended to not wait for a number of seconds, but instead use [Frame.waitForSelector()](./puppeteer.frame.waitforselector.md), [Frame.waitForXPath()](./puppeteer.frame.waitforxpath.md) or [Frame.waitForFunction()](./puppeteer.frame.waitforfunction.md) to wait for exactly the conditions you want.
|
||||
|
||||
## Example
|
||||
|
||||
Wait for 1 second:
|
||||
|
||||
```ts
|
||||
await page.waitForTimeout(1000);
|
||||
```
|
@ -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.
|
||||
*/
|
||||
|
@ -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
|
||||
|
@ -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));
|
||||
|
Loading…
Reference in New Issue
Block a user