Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update context, newContext and newPage description for browser module #1242

Merged
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ The browser module is the entry point for all your tests, and it is what interac

| Method | Description |
|-------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------|
| [browser.contexts()](/javascript-api/k6-experimental/browser/contexts) | Lets you access all open [BrowserContext](/javascript-api/k6-experimental/browser/browsercontext/)s. |
| [browser.context()](/javascript-api/k6-experimental/browser/context) | Returns the current [BrowserContext](/javascript-api/k6-experimental/browser/browsercontext/). |
| [browser.isConnected](/javascript-api/k6-experimental/browser/isconnected) <BWIPT id="453"/> | Indicates whether the [CDP](https://chromedevtools.github.io/devtools-protocol/) connection to the browser process is active or not. |
| [browser.newContext([options])](/javascript-api/k6-experimental/browser/newcontext/) <BWIPT id="455"/> | Creates and returns a new [BrowserContext](/javascript-api/k6-experimental/browser/browsercontext/). |
| [browser.newPage([options])](/javascript-api/k6-experimental/browser/newpage) <BWIPT id="455"/> | Creates a new [Page](/javascript-api/k6-experimental/browser/page/) in a new [BrowserContext](/javascript-api/k6-experimental/browser/browsercontext/) and returns the page. |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
title: 'context()'
excerpt: 'Browser module: context method'
---

Returns the current [BrowserContext](/javascript-api/k6-experimental/browser/browsercontext/).

<Blockquote mod="note" title="">

A 1-to-1 mapping between [Browser](/javascript-api/k6-experimental/browser) and `BrowserContext` means you cannot run `BrowserContexts` concurrently. If you wish to create a new `BrowserContext` while one already exists, you will need to [close](/javascript-api/k6-experimental/browser/browsercontext/close) the current one, and create a new one with either [newContext](/javascript-api/k6-experimental/browser/newcontext/) or [newPage](/javascript-api/k6-experimental/browser/newpage). All resources associated to the closed `BrowserContext` will also be closed and cleaned up (such as [Page](/javascript-api/k6-experimental/browser/page/)s).

</Blockquote>

### Returns

| Type | Description |
| -------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| object \| null | The current [BrowserContext](/javascript-api/k6-experimental/browser/browsercontext/) if one has been created, otherwise `null`. |


### Example

```javascript
import { browser } from 'k6/experimental/browser';

export const options = {
scenarios: {
browser: {
executor: 'shared-iterations',
options: {
browser: {
type: 'chromium',
},
},
},
},
}

export default function () {
console.log(browser.context()); // null

const page = browser.newPage();
const context = browser.context();
console.log(context); // {"base_event_emitter":{}}
ankur22 marked this conversation as resolved.
Show resolved Hide resolved

page.close();
context.close();
}
```

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ title: 'newContext([options])'
excerpt: 'Browser module: newContext method'
---

Creates and returns a new [BrowserContext](/javascript-api/k6-experimental/browser/browsercontext/).
Creates and returns a new [BrowserContext](/javascript-api/k6-experimental/browser/browsercontext/), if one hasn't already been initialized for the [Browser](/javascript-api/k6-experimental/browser). If one has already been initialized an error is thrown.

<Blockquote mod="note" title="">

A 1-to-1 mapping between [Browser](/javascript-api/k6-experimental/browser) and `BrowserContext` means you cannot run `BrowserContexts` concurrently. Due to this restriction, if one already exists, it must be [close](/javascript-api/k6-experimental/browser/browsercontext/close)d first before creating a new one.

</Blockquote>

<TableWithNestedRows>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ title: 'newPage([options])'
excerpt: 'Browser module: newPage method'
---

Creates a new [Page](/javascript-api/k6-experimental/browser/page/) in a new [BrowserContext](/javascript-api/k6-experimental/browser/browsercontext/) and returns the page. You do not need to create a new `BrowserContext` prior to using `newPage`.
Creates and returns a new [Page](/javascript-api/k6-experimental/browser/page/) in a new [BrowserContext](/javascript-api/k6-experimental/browser/browsercontext/) if a `BrowserContext` hasn't already been initialized for the [Browser](/javascript-api/k6-experimental/browser). If a `BrowserContext` has already been initialized an error is thrown.

<Blockquote mod="note" title="">

A 1-to-1 mapping between [Browser](/javascript-api/k6-experimental/browser) and `BrowserContext` means you cannot run `BrowserContexts` concurrently. Due to this restriction, if one already exists, it must be [retrieved](/javascript-api/k6-experimental/browser/context) and [close](/javascript-api/k6-experimental/browser/browsercontext/close)d first before creating a new one.

</Blockquote>

<TableWithNestedRows>

Expand Down