Skip to content

Commit 837d8eb

Browse files
authored
chore: update APIs for ports (#39796)
1 parent 7f55e11 commit 837d8eb

15 files changed

Lines changed: 79 additions & 82 deletions

File tree

docs/src/api/class-apiresponseassertions.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,24 @@ def test_navigates_to_login_page(page: Page) -> None:
4646
expect(response).to_be_ok()
4747
```
4848

49+
```csharp
50+
using Microsoft.Playwright;
51+
using Microsoft.Playwright.MSTest;
52+
53+
namespace PlaywrightTests;
54+
55+
[TestClass]
56+
public class ExampleTests : PageTest
57+
{
58+
[TestMethod]
59+
public async Task NavigatesToLoginPage()
60+
{
61+
var response = await Page.APIRequest.GetAsync("https://playwright.dev");
62+
await Expect(response).ToBeOKAsync();
63+
}
64+
}
65+
```
66+
4967
## property: APIResponseAssertions.not
5068
* since: v1.20
5169
* langs: java, js, csharp
@@ -65,6 +83,10 @@ await expect(response).not.toBeOK();
6583
assertThat(response).not().isOK();
6684
```
6785

86+
```csharp
87+
await Expect(response).Not.ToBeOKAsync();
88+
```
89+
6890
## async method: APIResponseAssertions.NotToBeOK
6991
* since: v1.19
7092
* langs: python
@@ -102,3 +124,7 @@ from playwright.sync_api import expect
102124
# ...
103125
expect(response).to_be_ok()
104126
```
127+
128+
```csharp
129+
await Expect(response).ToBeOKAsync();
130+
```

docs/src/api/class-browsercontext.md

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ Playwright has ability to mock clock and passage of time.
7676

7777
## property: BrowserContext.debugger
7878
* since: v1.59
79-
* langs: js
8079
- type: <[Debugger]>
8180

8281
Debugger allows to pause and resume the execution.
@@ -1004,14 +1003,6 @@ named `page`, but it can be a `Page` or `Frame` type.
10041003

10051004
Creates a new page in the browser context.
10061005

1007-
## method: BrowserContext.contextOptions
1008-
* since: v1.59
1009-
* langs: js
1010-
- returns: <[Object]>
1011-
1012-
Returns the context options that were used to create this browser context. The return type matches the options
1013-
accepted by [`method: Browser.newContext`].
1014-
10151006
## method: BrowserContext.pages
10161007
* since: v1.8
10171008
- returns: <[Array]<[Page]>>

docs/src/api/class-cdpsession.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ client.send("Animation.setPlaybackRate", params);
6969

7070
## event: CDPSession.close
7171
* since: v1.59
72-
* langs: js
72+
- argument: <[CDPSession]>
7373

7474
Emitted when the session is closed, either because the target was closed or `session.detach()` was called.
7575

docs/src/api/class-debugger.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# class: Debugger
22
* since: v1.59
3-
* langs: js
43

54
API for controlling the Playwright debugger. The debugger allows pausing script execution and inspecting the page.
65
Obtain the debugger instance via [`property: BrowserContext.debugger`].

docs/src/api/class-page.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,6 @@ Brings page to front (activates tab).
717717

718718
## async method: Page.cancelPickLocator
719719
* since: v1.59
720-
* langs: js
721720

722721
Cancels an ongoing [`method: Page.pickLocator`] call by deactivating pick locator mode.
723722
If no pick locator mode is active, this method is a no-op.
@@ -2725,7 +2724,6 @@ Returns up to (currently) 200 last page errors from this page. See [`event: Page
27252724

27262725
### option: Page.pageErrors.filter
27272726
* since: v1.59
2728-
* langs: js
27292727
- `filter` <[PageErrorsFilter]<"all"|"sinceNavigation">>
27302728

27312729
Controls which errors are returned:
@@ -3036,7 +3034,6 @@ Whether or not to embed the document outline into the PDF. Defaults to `false`.
30363034

30373035
## async method: Page.pickLocator
30383036
* since: v1.59
3039-
* langs: js
30403037
- returns: <[Locator]>
30413038

30423039
Enters pick locator mode where hovering over page elements highlights them and shows the corresponding locator.
@@ -3049,6 +3046,26 @@ const locator = await page.pickLocator();
30493046
console.log(locator);
30503047
```
30513048

3049+
```java
3050+
Locator locator = page.pickLocator();
3051+
System.out.println(locator);
3052+
```
3053+
3054+
```python async
3055+
locator = await page.pick_locator()
3056+
print(locator)
3057+
```
3058+
3059+
```python sync
3060+
locator = page.pick_locator()
3061+
print(locator)
3062+
```
3063+
3064+
```csharp
3065+
var locator = await page.PickLocatorAsync();
3066+
Console.WriteLine(locator);
3067+
```
3068+
30523069
## async method: Page.press
30533070
* since: v1.8
30543071
* discouraged: Use locator-based [`method: Locator.press`] instead. Read more about [locators](../locators.md).

docs/src/api/class-screencast.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Interface for capturing screencast frames from a page.
66

77
## async method: Screencast.start
88
* since: v1.59
9+
* langs: js
910
- returns: <[Disposable]>
1011

1112
Starts capturing screencast frames.
@@ -30,6 +31,7 @@ Callback that receives JPEG-encoded frame data.
3031

3132
### option: Screencast.start.preferredSize
3233
* since: v1.59
34+
* langs: js
3335
- `preferredSize` ?<[Object]>
3436
- `width` <[int]> Max frame width in pixels.
3537
- `height` <[int]> Max frame height in pixels.
@@ -42,12 +44,14 @@ Defaults to 800×800.
4244

4345
### option: Screencast.start.annotate
4446
* since: v1.59
47+
* langs: js
4548
- `annotate` ?<[Object]>
4649
- `delay` ?<[int]> How long each annotation is displayed in milliseconds. Defaults to `500`.
4750

4851
If specified, enables visual annotations on interacted elements during screencast. Interacted elements are highlighted with a semi-transparent blue box and click points are shown as red circles.
4952

5053
## async method: Screencast.stop
5154
* since: v1.59
55+
* langs: js
5256

5357
Stops the screencast started with [`method: Screencast.start`].

packages/playwright-client/types/types.d.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8318,11 +8318,6 @@ export interface BrowserContext {
83188318
behavior?: 'wait'|'ignoreErrors'|'default'
83198319
}): Promise<void>;
83208320

8321-
/**
8322-
* Returns the context options that were used to create this browser context. The return type matches the options
8323-
* accepted by [browser.newContext([options])](https://playwright.dev/docs/api/class-browser#browser-new-context).
8324-
*/
8325-
contextOptions(): BrowserContextOptions;
83268321
/**
83278322
* This event is not emitted.
83288323
*/
@@ -15830,7 +15825,7 @@ export interface CDPSession {
1583015825
/**
1583115826
* Emitted when the session is closed, either because the target was closed or `session.detach()` was called.
1583215827
*/
15833-
on(event: 'close', listener: () => any): this;
15828+
on(event: 'close', listener: (cdpSession: CDPSession) => any): this;
1583415829

1583515830
/**
1583615831
* Emitted for every CDP event received from the session. Allows subscribing to all CDP events at once without knowing
@@ -15860,7 +15855,7 @@ export interface CDPSession {
1586015855
/**
1586115856
* Adds an event listener that will be automatically removed after it is triggered once. See `addListener` for more information about this event.
1586215857
*/
15863-
once(event: 'close', listener: () => any): this;
15858+
once(event: 'close', listener: (cdpSession: CDPSession) => any): this;
1586415859

1586515860
/**
1586615861
* Adds an event listener that will be automatically removed after it is triggered once. See `addListener` for more information about this event.
@@ -15880,7 +15875,7 @@ export interface CDPSession {
1588015875
/**
1588115876
* Emitted when the session is closed, either because the target was closed or `session.detach()` was called.
1588215877
*/
15883-
addListener(event: 'close', listener: () => any): this;
15878+
addListener(event: 'close', listener: (cdpSession: CDPSession) => any): this;
1588415879

1588515880
/**
1588615881
* Emitted for every CDP event received from the session. Allows subscribing to all CDP events at once without knowing
@@ -15910,7 +15905,7 @@ export interface CDPSession {
1591015905
/**
1591115906
* Removes an event listener added by `on` or `addListener`.
1591215907
*/
15913-
removeListener(event: 'close', listener: () => any): this;
15908+
removeListener(event: 'close', listener: (cdpSession: CDPSession) => any): this;
1591415909

1591515910
/**
1591615911
* Removes an event listener added by `on` or `addListener`.
@@ -15930,7 +15925,7 @@ export interface CDPSession {
1593015925
/**
1593115926
* Removes an event listener added by `on` or `addListener`.
1593215927
*/
15933-
off(event: 'close', listener: () => any): this;
15928+
off(event: 'close', listener: (cdpSession: CDPSession) => any): this;
1593415929

1593515930
/**
1593615931
* Removes an event listener added by `on` or `addListener`.
@@ -15950,7 +15945,7 @@ export interface CDPSession {
1595015945
/**
1595115946
* Emitted when the session is closed, either because the target was closed or `session.detach()` was called.
1595215947
*/
15953-
prependListener(event: 'close', listener: () => any): this;
15948+
prependListener(event: 'close', listener: (cdpSession: CDPSession) => any): this;
1595415949

1595515950
/**
1595615951
* Emitted for every CDP event received from the session. Allows subscribing to all CDP events at once without knowing

packages/playwright-core/src/client/browserContext.ts

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import { WebError } from './webError';
3838
import { Worker } from './worker';
3939
import { TimeoutSettings } from './timeoutSettings';
4040
import { mkdirIfNeeded } from './fileUtils';
41-
import { headersArrayToObject, headersObjectToArray } from '../utils/isomorphic/headers';
41+
import { headersObjectToArray } from '../utils/isomorphic/headers';
4242
import { urlMatchesEqual } from '../utils/isomorphic/urlMatch';
4343
import { isRegExp, isString } from '../utils/isomorphic/rtti';
4444
import { rewriteErrorMessage } from '../utils/isomorphic/stackTrace';
@@ -290,10 +290,6 @@ export class BrowserContext extends ChannelOwner<channels.BrowserContextChannel>
290290
return this._browser;
291291
}
292292

293-
contextOptions() {
294-
return contextParamsToPublicOptions(this._options);
295-
}
296-
297293
pages(): Page[] {
298294
return [...this._pages];
299295
}
@@ -607,24 +603,6 @@ export async function prepareBrowserContextParams(platform: Platform, options: B
607603
return contextParams;
608604
}
609605

610-
function contextParamsToPublicOptions(params: channels.BrowserNewContextParams): api.BrowserContextOptions {
611-
const result = {
612-
...params,
613-
viewport: params.noDefaultViewport ? null : params.viewport,
614-
extraHTTPHeaders: params.extraHTTPHeaders ? headersArrayToObject(params.extraHTTPHeaders, false) : undefined,
615-
colorScheme: params.colorScheme === 'no-override' ? null : params.colorScheme,
616-
reducedMotion: params.reducedMotion === 'no-override' ? null : params.reducedMotion,
617-
forcedColors: params.forcedColors === 'no-override' ? null : params.forcedColors,
618-
contrast: params.contrast === 'no-override' ? null : params.contrast,
619-
acceptDownloads: params.acceptDownloads === 'accept' ? true : params.acceptDownloads === 'deny' ? false : undefined,
620-
storageState: undefined,
621-
};
622-
delete result.clientCertificates;
623-
delete result.noDefaultViewport;
624-
delete result.selectorEngines;
625-
return result;
626-
}
627-
628606
function toAcceptDownloadsProtocol(acceptDownloads?: boolean) {
629607
if (acceptDownloads === undefined)
630608
return undefined;

packages/playwright-core/src/client/cdpSession.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class CDPSession extends ChannelOwner<channels.CDPSessionChannel> impleme
3434
});
3535

3636
this._channel.on('close', () => {
37-
this.emit('close');
37+
this.emit('close', this);
3838
});
3939

4040
this.on = super.on;

packages/playwright-core/types/types.d.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8318,11 +8318,6 @@ export interface BrowserContext {
83188318
behavior?: 'wait'|'ignoreErrors'|'default'
83198319
}): Promise<void>;
83208320

8321-
/**
8322-
* Returns the context options that were used to create this browser context. The return type matches the options
8323-
* accepted by [browser.newContext([options])](https://playwright.dev/docs/api/class-browser#browser-new-context).
8324-
*/
8325-
contextOptions(): BrowserContextOptions;
83268321
/**
83278322
* This event is not emitted.
83288323
*/
@@ -15830,7 +15825,7 @@ export interface CDPSession {
1583015825
/**
1583115826
* Emitted when the session is closed, either because the target was closed or `session.detach()` was called.
1583215827
*/
15833-
on(event: 'close', listener: () => any): this;
15828+
on(event: 'close', listener: (cdpSession: CDPSession) => any): this;
1583415829

1583515830
/**
1583615831
* Emitted for every CDP event received from the session. Allows subscribing to all CDP events at once without knowing
@@ -15860,7 +15855,7 @@ export interface CDPSession {
1586015855
/**
1586115856
* Adds an event listener that will be automatically removed after it is triggered once. See `addListener` for more information about this event.
1586215857
*/
15863-
once(event: 'close', listener: () => any): this;
15858+
once(event: 'close', listener: (cdpSession: CDPSession) => any): this;
1586415859

1586515860
/**
1586615861
* Adds an event listener that will be automatically removed after it is triggered once. See `addListener` for more information about this event.
@@ -15880,7 +15875,7 @@ export interface CDPSession {
1588015875
/**
1588115876
* Emitted when the session is closed, either because the target was closed or `session.detach()` was called.
1588215877
*/
15883-
addListener(event: 'close', listener: () => any): this;
15878+
addListener(event: 'close', listener: (cdpSession: CDPSession) => any): this;
1588415879

1588515880
/**
1588615881
* Emitted for every CDP event received from the session. Allows subscribing to all CDP events at once without knowing
@@ -15910,7 +15905,7 @@ export interface CDPSession {
1591015905
/**
1591115906
* Removes an event listener added by `on` or `addListener`.
1591215907
*/
15913-
removeListener(event: 'close', listener: () => any): this;
15908+
removeListener(event: 'close', listener: (cdpSession: CDPSession) => any): this;
1591415909

1591515910
/**
1591615911
* Removes an event listener added by `on` or `addListener`.
@@ -15930,7 +15925,7 @@ export interface CDPSession {
1593015925
/**
1593115926
* Removes an event listener added by `on` or `addListener`.
1593215927
*/
15933-
off(event: 'close', listener: () => any): this;
15928+
off(event: 'close', listener: (cdpSession: CDPSession) => any): this;
1593415929

1593515930
/**
1593615931
* Removes an event listener added by `on` or `addListener`.
@@ -15950,7 +15945,7 @@ export interface CDPSession {
1595015945
/**
1595115946
* Emitted when the session is closed, either because the target was closed or `session.detach()` was called.
1595215947
*/
15953-
prependListener(event: 'close', listener: () => any): this;
15948+
prependListener(event: 'close', listener: (cdpSession: CDPSession) => any): this;
1595415949

1595515950
/**
1595615951
* Emitted for every CDP event received from the session. Allows subscribing to all CDP events at once without knowing

0 commit comments

Comments
 (0)