-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: ka3de <[email protected]>
- Loading branch information
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
docs/sources/next/javascript-api/k6-experimental/browser/closecontext.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--- | ||
title: 'closeContext()' | ||
excerpt: 'Browser module: close context method' | ||
--- | ||
|
||
Closes the current [BrowserContext](/javascript-api/k6-experimental/browser/browsercontext/). If there is no active browser context, because none has been created yet or because it has been previously closed, this method throws an error. | ||
|
||
|
||
### Example | ||
|
||
```javascript | ||
import { browser } from 'k6/experimental/browser'; | ||
|
||
export const options = { | ||
scenarios: { | ||
browser: { | ||
executor: 'shared-iterations', | ||
options: { | ||
browser: { | ||
type: 'chromium', | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
export default async function () { | ||
const page1 = browser.newPage({ | ||
isMobile: true, | ||
}); // implicitly creates a new context | ||
|
||
await page1.goto('https:/test.k6.io/'); | ||
page1.close(); | ||
browser.closeContext(); // closes the context created on newPage | ||
|
||
const page2 = browser.newPage({ | ||
isMobile: false, | ||
}); // creates a new context with different settings | ||
|
||
await page2.goto('https://test.k6.io/'); | ||
page2.close(); | ||
browser.closeContext(); | ||
|
||
browser.closeContext(); // throws an error as browser has no active context | ||
} | ||
``` |