Skip to content

Commit 114d586

Browse files
authored
chore: add python aliases (#4949)
1 parent f0a8729 commit 114d586

15 files changed

+125
-34
lines changed

docs/src/api/class-browsercontext.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ await context.grantPermissions(['geolocation']);
481481
Event name, same one would pass into `browserContext.on(event)`.
482482

483483
### param: BrowserContext.waitForEvent.optionsOrPredicate
484+
* langs: js
484485
- `optionsOrPredicate` <[Function]|[Object]>
485486
- `predicate` <[Function]> receives the event data and resolves to truthy value when the waiting should resolve.
486487
- `timeout` <[float]> maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can be changed by using the [`method: BrowserContext.setDefaultTimeout`].

docs/src/api/class-elementhandle.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ JSHandle.dispose`]. ElementHandles are auto-disposed when their origin frame get
2222
ElementHandle instances can be used as an argument in [`method: Page.$eval`] and [`method: Page.evaluate`] methods.
2323

2424
## async method: ElementHandle.$
25+
* langs:
26+
- alias-python: query_selector
2527
- returns: <[null]|[ElementHandle]>
2628

2729
The method finds an element matching the specified selector in the `ElementHandle`'s subtree. See [Working with
@@ -30,6 +32,8 @@ selectors](./selectors.md#working-with-selectors) for more details. If no elemen
3032
### param: ElementHandle.$.selector = %%-query-selector-%%
3133

3234
## async method: ElementHandle.$$
35+
* langs:
36+
- alias-python: query_selector_all
3337
- returns: <[Array]<[ElementHandle]>>
3438

3539
The method finds all elements matching the specified selector in the `ElementHandle`s subtree. See [Working with
@@ -38,6 +42,8 @@ selectors](./selectors.md#working-with-selectors) for more details. If no elemen
3842
### param: ElementHandle.$$.selector = %%-query-selector-%%
3943

4044
## async method: ElementHandle.$eval
45+
* langs:
46+
- alias-python: eval_on_selector
4147
- returns: <[Serializable]>
4248

4349
Returns the return value of [`param: pageFunction`]
@@ -70,6 +76,8 @@ Function to be evaluated in browser context
7076
Optional argument to pass to [`param: pageFunction`]
7177

7278
## async method: ElementHandle.$$eval
79+
* langs:
80+
- alias-python: eval_on_selector_all
7381
- returns: <[Serializable]>
7482

7583
Returns the return value of [`param: pageFunction`]

docs/src/api/class-frame.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ console.log(text);
3838
```
3939

4040
## async method: Frame.$
41+
* langs:
42+
- alias-python: query_selector
4143
- returns: <[null]|[ElementHandle]>
4244

4345
Returns the ElementHandle pointing to the frame element.
@@ -48,6 +50,8 @@ selectors](./selectors.md#working-with-selectors) for more details. If no elemen
4850
### param: Frame.$.selector = %%-query-selector-%%
4951

5052
## async method: Frame.$$
53+
* langs:
54+
- alias-python: query_selector_all
5155
- returns: <[Array]<[ElementHandle]>>
5256

5357
Returns the ElementHandles pointing to the frame elements.
@@ -58,6 +62,8 @@ selectors](./selectors.md#working-with-selectors) for more details. If no elemen
5862
### param: Frame.$$.selector = %%-query-selector-%%
5963

6064
## async method: Frame.$eval
65+
* langs:
66+
- alias-python: eval_on_selector
6167
- returns: <[Serializable]>
6268

6369
Returns the return value of [`param: pageFunction`]
@@ -90,6 +96,8 @@ Function to be evaluated in browser context
9096
Optional argument to pass to [`param: pageFunction`]
9197

9298
## async method: Frame.$$eval
99+
* langs:
100+
- alias-python: eval_on_selector_all
93101
- returns: <[Serializable]>
94102

95103
Returns the return value of [`param: pageFunction`]

docs/src/api/class-page.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ Emitted when a dedicated [WebWorker](https://developer.mozilla.org/en-US/docs/We
210210
page.
211211

212212
## async method: Page.$
213+
* langs:
214+
- alias-python: query_selector
213215
- returns: <[null]|[ElementHandle]>
214216

215217
The method finds an element matching the specified selector within the page. If no elements match the selector, the
@@ -220,6 +222,8 @@ Shortcut for main frame's [`method: Frame.$`].
220222
### param: Page.$.selector = %%-query-selector-%%
221223

222224
## async method: Page.$$
225+
* langs:
226+
- alias-python: query_selector_all
223227
- returns: <[Array]<[ElementHandle]>>
224228

225229
The method finds all elements matching the specified selector within the page. If no elements match the selector, the
@@ -230,6 +234,8 @@ Shortcut for main frame's [`method: Frame.$$`].
230234
### param: Page.$$.selector = %%-query-selector-%%
231235

232236
## async method: Page.$eval
237+
* langs:
238+
- alias-python: eval_on_selector
233239
- returns: <[Serializable]>
234240

235241
The method finds an element matching the specified selector within the page and passes it as a first argument to
@@ -262,6 +268,8 @@ Function to be evaluated in browser context
262268
Optional argument to pass to [`param: pageFunction`]
263269

264270
## async method: Page.$$eval
271+
* langs:
272+
- alias-python: eval_on_selector_all
265273
- returns: <[Serializable]>
266274

267275
The method finds all elements matching the specified selector within the page and passes an array of matched elements as
@@ -560,6 +568,7 @@ await page.evaluate(() => matchMedia('(prefers-color-scheme: no-preference)').ma
560568
```
561569

562570
### param: Page.emulateMedia.params
571+
* langs: js
563572
- `params` <[Object]>
564573
- `media` <[null]|"screen"|"print"> Changes the CSS media type of the page. The only allowed values are `'screen'`, `'print'` and `null`. Passing `null` disables CSS media emulation. Omitting `media` or passing `undefined` does not change the emulated value. Optional.
565574
- `colorScheme` <[null]|"light"|"dark"|"no-preference"> Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. Passing `null` disables color scheme emulation. Omitting `colorScheme` or passing `undefined` does not change the emulated value. Optional.
@@ -1569,6 +1578,7 @@ value. Will throw an error if the page is closed before the event is fired.
15691578
Event name, same one would pass into `page.on(event)`.
15701579

15711580
### param: Page.waitForEvent.optionsOrPredicate
1581+
* langs: js
15721582
- `optionsOrPredicate` <[Function]|[Object]>
15731583
- `predicate` <[Function]> receives the event data and resolves to truthy value when the waiting should resolve.
15741584
- `timeout` <[float]> maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can be changed by using the [`method: BrowserContext.setDefaultTimeout`].

docs/src/api/class-route.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ Optional error code. Defaults to `failed`, could be one of the following:
2727
* `'failed'` - A generic failure occurred.
2828

2929
## async method: Route.continue
30+
* langs:
31+
- alias-python: continue_
3032

3133
Continues route's request with optional overrides.
3234

docs/src/api/class-websocket.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ value. Will throw an error if the webSocket is closed before the event is fired.
4747
Event name, same one would pass into `webSocket.on(event)`.
4848

4949
### param: WebSocket.waitForEvent.optionsOrPredicate
50+
* langs: js
5051
- `optionsOrPredicate` <[Function]|[Object]>
5152
- `predicate` <[Function]> receives the event data and resolves to truthy value when the waiting should resolve.
5253
- `timeout` <[float]> maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can be changed by using the [`method: BrowserContext.setDefaultTimeout`].

docs/src/api/params.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,19 @@ only the first option matching one of the passed options is selected. Optional.
303303
Options to select by label. If the `<select>` has the `multiple` attribute, all given options are selected, otherwise
304304
only the first option matching one of the passed options is selected. Optional.
305305

306+
## python-wait-for-event-predicate
307+
* langs: python
308+
- `predicate` <[Function]>
309+
310+
Receives the event data and resolves to truthy value when the waiting should resolve.
311+
312+
## python-wait-for-event-timeout
313+
* langs: python
314+
- `timeout` <[float]>
315+
316+
Maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout.
317+
The default value can be changed by using the [`method: BrowserContext.setDefaultTimeout`].
318+
306319

307320
## shared-context-params-list
308321
- %%-context-option-acceptdownloads-%%

docs/src/api/python.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,26 @@ Longitude between -180 and 180. **required**
7979
- `accuracy` <[float]>
8080

8181
Non-negative accuracy value. Defaults to `0`. Optional.
82+
83+
### param: Page.emulateMedia.params
84+
* langs: python
85+
- `media` <[null]|"screen"|"print">
86+
87+
Changes the CSS media type of the page. The only allowed values are `'screen'`, `'print'` and `null`.
88+
Passing `null` disables CSS media emulation. Omitting `media` or passing `undefined` does not change the emulated value.
89+
Optional.
90+
91+
### param: Page.emulateMedia.params
92+
* langs: python
93+
- `colorScheme` <[null]|"light"|"dark"|"no-preference">
94+
95+
Emulates `'prefers-colors-scheme'` media feature, supported values are `'light'`, `'dark'`, `'no-preference'`. Passing
96+
`null` disables color scheme emulation. Omitting `colorScheme` or passing `undefined` does not change the emulated
97+
value. Optional.
98+
99+
### option: BrowserContext.waitForEvent.predicate = %%-python-wait-for-event-predicate-%%
100+
### option: BrowserContext.waitForEvent.timeout = %%-python-wait-for-event-timeout-%%
101+
### option: Page.waitForEvent.predicate = %%-python-wait-for-event-predicate-%%
102+
### option: Page.waitForEvent.timeout = %%-python-wait-for-event-timeout-%%
103+
### option: WebSocket.waitForEvent.predicate = %%-python-wait-for-event-predicate-%%
104+
### option: WebSocket.waitForEvent.timeout = %%-python-wait-for-event-timeout-%%

docs/src/selectors.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,15 +207,17 @@ Consider a page with two buttons, first invisible and second visible.
207207
<button>Visible</button>
208208
```
209209

210-
* ```js
210+
* This will find the first button, because it is the first one in DOM order. Then it will wait for the button to become visible before clicking, or timeout while waiting:
211+
212+
```js
211213
await page.click('button');
212214
```
213-
This will find the first button, because it is the first one in DOM order. Then it will wait for the button to become visible before clicking, or timeout while waiting.
214215

215-
* ```js
216+
* This will find a second button, because it is visible, and then click it.
217+
218+
```js
216219
await page.click('button:visible');
217-
```
218-
This will find a second button, because it is visible, and then click it.
220+
```
219221

220222
Use `:visible` with caution, because it has two major drawbacks:
221223
* When elements change their visibility dynamically, `:visible` will give upredictable results based on the timing.

utils/doclint/api_parser.js

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class ApiParser {
113113
let options = method.argsArray.find(o => o.name === 'options');
114114
if (!options) {
115115
const type = new Documentation.Type('Object', []);
116-
options = Documentation.Member.createProperty(null, 'options', type, undefined, false);
116+
options = Documentation.Member.createProperty({}, 'options', type, undefined, false);
117117
method.argsArray.push(options);
118118
}
119119
const p = this.parseProperty(spec);
@@ -143,7 +143,7 @@ class ApiParser {
143143
for (const child of spec.children || []) {
144144
const { name, text } = parseVariable(child.text);
145145
const comments = /** @type {MarkdownNode[]} */ ([{ type: 'text', text }]);
146-
properties.push(Documentation.Member.createProperty(null, name, this.parseType(child), comments, guessRequired(text)));
146+
properties.push(Documentation.Member.createProperty({}, name, this.parseType(child), comments, guessRequired(text)));
147147
}
148148
return Documentation.Type.parse(arg.type, properties);
149149
}
@@ -272,13 +272,27 @@ function parseApi(apiDir) {
272272

273273
/**
274274
* @param {MarkdownNode} spec
275-
* @returns {?Set<string>}
275+
* @returns {import('./documentation').Langs}
276276
*/
277277
function extractLangs(spec) {
278-
for (const child of spec.children)
279-
if (child.type === 'li' && child.liType === 'bullet' && child.text.startsWith('langs: '))
280-
return new Set(child.text.substring('langs: '.length).split(',').map(l => l.trim()));
281-
return null;
278+
for (const child of spec.children) {
279+
if (child.type !== 'li' || child.liType !== 'bullet' || !child.text.startsWith('langs:'))
280+
continue;
281+
282+
const only = child.text.substring('langs:'.length).trim();
283+
/** @type {Object<string, string>} */
284+
const aliases = {};
285+
for (const p of child.children || []) {
286+
const match = p.text.match(/alias-(\w+)[\s]*:(.*)/);
287+
if (match)
288+
aliases[match[1].trim()] = match[2].trim();
289+
}
290+
return {
291+
only: only ? only.split(',') : undefined,
292+
aliases
293+
};
294+
}
295+
return {};
282296
}
283297

284298
/**

0 commit comments

Comments
 (0)