Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions docs/src/api/class-apiresponseassertions.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,24 @@ def test_navigates_to_login_page(page: Page) -> None:
expect(response).to_be_ok()
```

```csharp
using Microsoft.Playwright;
using Microsoft.Playwright.MSTest;

namespace PlaywrightTests;

[TestClass]
public class ExampleTests : PageTest
{
[TestMethod]
public async Task NavigatesToLoginPage()
{
var response = await Page.APIRequest.GetAsync("https://playwright.dev");
await Expect(response).ToBeOKAsync();
}
}
```

## property: APIResponseAssertions.not
* since: v1.20
* langs: java, js, csharp
Expand All @@ -65,6 +83,10 @@ await expect(response).not.toBeOK();
assertThat(response).not().isOK();
```

```csharp
await Expect(response).Not.ToBeOKAsync();
```

## async method: APIResponseAssertions.NotToBeOK
* since: v1.19
* langs: python
Expand Down Expand Up @@ -102,3 +124,7 @@ from playwright.sync_api import expect
# ...
expect(response).to_be_ok()
```

```csharp
await Expect(response).ToBeOKAsync();
```
9 changes: 0 additions & 9 deletions docs/src/api/class-browsercontext.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ Playwright has ability to mock clock and passage of time.

## property: BrowserContext.debugger
* since: v1.59
* langs: js
- type: <[Debugger]>

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

Creates a new page in the browser context.

## method: BrowserContext.contextOptions
* since: v1.59
* langs: js
- returns: <[Object]>

Returns the context options that were used to create this browser context. The return type matches the options
accepted by [`method: Browser.newContext`].

## method: BrowserContext.pages
* since: v1.8
- returns: <[Array]<[Page]>>
Expand Down
2 changes: 1 addition & 1 deletion docs/src/api/class-cdpsession.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ client.send("Animation.setPlaybackRate", params);

## event: CDPSession.close
* since: v1.59
* langs: js
- argument: <[CDPSession]>

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

Expand Down
1 change: 0 additions & 1 deletion docs/src/api/class-debugger.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# class: Debugger
* since: v1.59
* langs: js

API for controlling the Playwright debugger. The debugger allows pausing script execution and inspecting the page.
Obtain the debugger instance via [`property: BrowserContext.debugger`].
Expand Down
23 changes: 20 additions & 3 deletions docs/src/api/class-page.md
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,6 @@ Brings page to front (activates tab).

## async method: Page.cancelPickLocator
* since: v1.59
* langs: js

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

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

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

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

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

```java
Locator locator = page.pickLocator();
System.out.println(locator);
```

```python async
locator = await page.pick_locator()
print(locator)
```

```python sync
locator = page.pick_locator()
print(locator)
```

```csharp
var locator = await page.PickLocatorAsync();
Console.WriteLine(locator);
```

## async method: Page.press
* since: v1.8
* discouraged: Use locator-based [`method: Locator.press`] instead. Read more about [locators](../locators.md).
Expand Down
4 changes: 4 additions & 0 deletions docs/src/api/class-screencast.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Interface for capturing screencast frames from a page.

## async method: Screencast.start
* since: v1.59
* langs: js
- returns: <[Disposable]>

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

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

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

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.

## async method: Screencast.stop
* since: v1.59
* langs: js

Stops the screencast started with [`method: Screencast.start`].
17 changes: 6 additions & 11 deletions packages/playwright-client/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8318,11 +8318,6 @@ export interface BrowserContext {
behavior?: 'wait'|'ignoreErrors'|'default'
}): Promise<void>;

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

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

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

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

/**
* Removes an event listener added by `on` or `addListener`.
Expand All @@ -15930,7 +15925,7 @@ export interface CDPSession {
/**
* Removes an event listener added by `on` or `addListener`.
*/
off(event: 'close', listener: () => any): this;
off(event: 'close', listener: (cdpSession: CDPSession) => any): this;

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

/**
* Emitted for every CDP event received from the session. Allows subscribing to all CDP events at once without knowing
Expand Down
24 changes: 1 addition & 23 deletions packages/playwright-core/src/client/browserContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import { WebError } from './webError';
import { Worker } from './worker';
import { TimeoutSettings } from './timeoutSettings';
import { mkdirIfNeeded } from './fileUtils';
import { headersArrayToObject, headersObjectToArray } from '../utils/isomorphic/headers';
import { headersObjectToArray } from '../utils/isomorphic/headers';
import { urlMatchesEqual } from '../utils/isomorphic/urlMatch';
import { isRegExp, isString } from '../utils/isomorphic/rtti';
import { rewriteErrorMessage } from '../utils/isomorphic/stackTrace';
Expand Down Expand Up @@ -290,10 +290,6 @@ export class BrowserContext extends ChannelOwner<channels.BrowserContextChannel>
return this._browser;
}

contextOptions() {
return contextParamsToPublicOptions(this._options);
}

pages(): Page[] {
return [...this._pages];
}
Expand Down Expand Up @@ -607,24 +603,6 @@ export async function prepareBrowserContextParams(platform: Platform, options: B
return contextParams;
}

function contextParamsToPublicOptions(params: channels.BrowserNewContextParams): api.BrowserContextOptions {
const result = {
...params,
viewport: params.noDefaultViewport ? null : params.viewport,
extraHTTPHeaders: params.extraHTTPHeaders ? headersArrayToObject(params.extraHTTPHeaders, false) : undefined,
colorScheme: params.colorScheme === 'no-override' ? null : params.colorScheme,
reducedMotion: params.reducedMotion === 'no-override' ? null : params.reducedMotion,
forcedColors: params.forcedColors === 'no-override' ? null : params.forcedColors,
contrast: params.contrast === 'no-override' ? null : params.contrast,
acceptDownloads: params.acceptDownloads === 'accept' ? true : params.acceptDownloads === 'deny' ? false : undefined,
storageState: undefined,
};
delete result.clientCertificates;
delete result.noDefaultViewport;
delete result.selectorEngines;
return result;
}

function toAcceptDownloadsProtocol(acceptDownloads?: boolean) {
if (acceptDownloads === undefined)
return undefined;
Expand Down
2 changes: 1 addition & 1 deletion packages/playwright-core/src/client/cdpSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class CDPSession extends ChannelOwner<channels.CDPSessionChannel> impleme
});

this._channel.on('close', () => {
this.emit('close');
this.emit('close', this);
});

this.on = super.on;
Expand Down
17 changes: 6 additions & 11 deletions packages/playwright-core/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8318,11 +8318,6 @@ export interface BrowserContext {
behavior?: 'wait'|'ignoreErrors'|'default'
}): Promise<void>;

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

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

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

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

/**
* Removes an event listener added by `on` or `addListener`.
Expand All @@ -15930,7 +15925,7 @@ export interface CDPSession {
/**
* Removes an event listener added by `on` or `addListener`.
*/
off(event: 'close', listener: () => any): this;
off(event: 'close', listener: (cdpSession: CDPSession) => any): this;

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

/**
* Emitted for every CDP event received from the session. Allows subscribing to all CDP events at once without knowing
Expand Down
14 changes: 0 additions & 14 deletions tests/library/browsercontext-basic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,6 @@ it('should create new context @smoke', async function({ browser }) {
await context2.close();
});

it('should return context options', async function({ browser }) {
const context = await browser.newContext({
userAgent: 'custom-ua',
locale: 'fr-FR',
extraHTTPHeaders: { 'foo': 'bar' },
});
const options = context.contextOptions();
expect(options.userAgent).toBe('custom-ua');
expect(options.locale).toBe('fr-FR');
expect(options.extraHTTPHeaders).toEqual({ 'foo': 'bar' });
expect((options as any).noDefaultViewport).toBeUndefined(); // internal option should not leak
await context.close();
});

it('should be able to click across browser contexts', async function({ browser }) {
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/29096' });
expect(browser.contexts().length).toBe(0);
Expand Down
11 changes: 6 additions & 5 deletions tests/library/chromium/session.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,19 +160,20 @@ it('should emit event for each CDP event', async function({ page, server }) {

it('should emit close event when session is detached', async function({ page }) {
const client = await page.context().newCDPSession(page);
let closeFired = false;
client.on('close', () => closeFired = true);
let closedSession: any = null;
client.on('close', session => closedSession = session);
await client.detach();
expect(closeFired).toBe(true);
expect(closedSession).toBe(client);
});

browserTest('should emit close event when page closes', async function({ browser }) {
const context = await browser.newContext();
const page = await context.newPage();
const session = await context.newCDPSession(page);
const closePromise = new Promise<void>(f => session.on('close', f));
const closePromise = new Promise(f => session.on('close', f));
await page.close();
await closePromise;
const closedSession = await closePromise;
expect(closedSession).toBe(session);
await context.close();
});

Expand Down
Loading
Loading