# Table of Contents
- [Installation | Playwright](#installation-playwright)
- [PlaywrightAssertions | Playwright](#playwrightassertions-playwright)
- [Video | Playwright Java](#video-playwright-java)
- [Mouse | Playwright .NET](#mouse-playwright-net)
- [TimeoutError | Playwright Java](#timeouterror-playwright-java)
- [Video | Playwright .NET](#video-playwright-net)
- [WebError | Playwright Java](#weberror-playwright-java)
- [Selectors | Playwright Java](#selectors-playwright-java)
- [Download | Playwright .NET](#download-playwright-net)
- [Dialog | Playwright .NET](#dialog-playwright-net)
- [Snapshot testing | Playwright .NET](#snapshot-testing-playwright-net)
- [Clock | Playwright .NET](#clock-playwright-net)
- [Mouse | Playwright Java](#mouse-playwright-java)
- [WebError | Playwright .NET](#weberror-playwright-net)
- [Running and debugging tests | Playwright .NET](#running-and-debugging-tests-playwright-net)
- [Debugging Tests | Playwright .NET](#debugging-tests-playwright-net)
- [TimeoutError | Playwright .NET](#timeouterror-playwright-net)
- [JSHandle | Playwright Java](#jshandle-playwright-java)
- [Page object models | Playwright .NET](#page-object-models-playwright-net)
- [Evaluating JavaScript | Playwright .NET](#evaluating-javascript-playwright-net)
- [Installation | Playwright Python](#installation-playwright-python)
- [Touch events (legacy) | Playwright .NET](#touch-events-legacy-playwright-net)
- [Getting started - Library | Playwright .NET](#getting-started-library-playwright-net)
- [Web server | Playwright](#web-server-playwright)
- [UI Mode | Playwright](#ui-mode-playwright)
- [Clock | Playwright .NET](#clock-playwright-net)
- [Visual comparisons | Playwright](#visual-comparisons-playwright)
- [Command line | Playwright](#command-line-playwright)
- [Sharding | Playwright](#sharding-playwright)
- [Test configuration | Playwright](#test-configuration-playwright)
- [TypeScript | Playwright](#typescript-playwright)
- [Reporters | Playwright](#reporters-playwright)
- [Parallelism | Playwright](#parallelism-playwright)
- [Projects | Playwright](#projects-playwright)
- [Timeouts | Playwright](#timeouts-playwright)
- [Installation | Playwright .NET](#installation-playwright-net)
- [Annotations | Playwright](#annotations-playwright)
- [Retries | Playwright](#retries-playwright)
- [Parameterize tests | Playwright](#parameterize-tests-playwright)
- [Global setup and teardown | Playwright](#global-setup-and-teardown-playwright)
- [Writing tests | Playwright](#writing-tests-playwright)
- [Mock APIs | Playwright .NET](#mock-apis-playwright-net)
- [Writing tests | Playwright .NET](#writing-tests-playwright-net)
- [Test Runners | Playwright .NET](#test-runners-playwright-net)
- [Test use options | Playwright](#test-use-options-playwright)
- [Emulation | Playwright .NET](#emulation-playwright-net)
- [Selectors | Playwright .NET](#selectors-playwright-net)
- [Dialog | Playwright Java](#dialog-playwright-java)
- [Trace viewer | Playwright](#trace-viewer-playwright)
- [Components (experimental) | Playwright](#components-experimental-playwright)
- [Videos | Playwright](#videos-playwright)
- [Screenshots | Playwright](#screenshots-playwright)
- [WebView2 | Playwright](#webview2-playwright)
- [Trace viewer | Playwright](#trace-viewer-playwright)
- [Selenium Grid (experimental) | Playwright](#selenium-grid-experimental-playwright)
- [Assertions | Playwright](#assertions-playwright)
- [Touch events (legacy) | Playwright](#touch-events-legacy-playwright)
- [JSHandle | Playwright Python](#jshandle-playwright-python)
- [Migrating from Testing Library | Playwright](#migrating-from-testing-library-playwright)
- [Network | Playwright .NET](#network-playwright-net)
- [Touch events (legacy) | Playwright Java](#touch-events-legacy-playwright-java)
- [Network | Playwright Java](#network-playwright-java)
- [Pytest Plugin Reference | Playwright Python](#pytest-plugin-reference-playwright-python)
- [Other locators | Playwright Python](#other-locators-playwright-python)
- [Other locators | Playwright Java](#other-locators-playwright-java)
- [Installation | Playwright Java](#installation-playwright-java)
- [Fixtures | Playwright](#fixtures-playwright)
- [Playwright | Playwright Python](#playwright-playwright-python)
- [Installation | Playwright .NET](#installation-playwright-net)
- [Playwright | Playwright Java](#playwright-playwright-java)
- [Playwright | Playwright .NET](#playwright-playwright-net)
- [Test Runners | Playwright Java](#test-runners-playwright-java)
- [Videos | Playwright Python](#videos-playwright-python)
- [Network | Playwright Python](#network-playwright-python)
- [Writing tests | Playwright Python](#writing-tests-playwright-python)
- [WebView2 | Playwright Python](#webview2-playwright-python)
- [Screenshots | Playwright Python](#screenshots-playwright-python)
- [APIRequest | Playwright .NET](#apirequest-playwright-net)
- [Selenium Grid (experimental) | Playwright Python](#selenium-grid-experimental-playwright-python)
- [Writing tests | Playwright Java](#writing-tests-playwright-java)
- [Assertions | Playwright Python](#assertions-playwright-python)
- [Trace viewer | Playwright Python](#trace-viewer-playwright-python)
- [Video | Playwright Python](#video-playwright-python)
- [Installation | Playwright Java](#installation-playwright-java)
- [Writing tests | Playwright .NET](#writing-tests-playwright-net)
- [TimeoutError | Playwright Python](#timeouterror-playwright-python)
- [WebError | Playwright Python](#weberror-playwright-python)
- [Selectors | Playwright Python](#selectors-playwright-python)
- [Trace viewer | Playwright Python](#trace-viewer-playwright-python)
- [Download | Playwright Python](#download-playwright-python)
- [Dialog | Playwright Python](#dialog-playwright-python)
- [Page object models | Playwright Python](#page-object-models-playwright-python)
- [Mouse | Playwright Python](#mouse-playwright-python)
- [Clock | Playwright Python](#clock-playwright-python)
- [JSHandle | Playwright .NET](#jshandle-playwright-net)
- [Evaluating JavaScript | Playwright Python](#evaluating-javascript-playwright-python)
- [Getting started - Library | Playwright Python](#getting-started-library-playwright-python)
- [Generating tests | Playwright Python](#generating-tests-playwright-python)
- [Running and debugging tests | Playwright Python](#running-and-debugging-tests-playwright-python)
- [Playwright | Playwright Java](#playwright-playwright-java)
- [Touch events (legacy) | Playwright Python](#touch-events-legacy-playwright-python)
- [Touch events (legacy) | Playwright Python](#touch-events-legacy-playwright-python)
- [Videos | Playwright Java](#videos-playwright-java)
- [Debugging Tests | Playwright Python](#debugging-tests-playwright-python)
- [APIRequest | Playwright Java](#apirequest-playwright-java)
- [Generating tests | Playwright .NET](#generating-tests-playwright-net)
- [Screenshots | Playwright Java](#screenshots-playwright-java)
- [Generating tests | Playwright .NET](#generating-tests-playwright-net)
- [Generating tests | Playwright Java](#generating-tests-playwright-java)
- [Assertions | Playwright Java](#assertions-playwright-java)
- [Mock APIs | Playwright Python](#mock-apis-playwright-python)
- [Emulation | Playwright Python](#emulation-playwright-python)
- [APIResponse | Playwright Java](#apiresponse-playwright-java)
- [Trace viewer | Playwright Java](#trace-viewer-playwright-java)
- [Page object models | Playwright Java](#page-object-models-playwright-java)
- [Trace viewer | Playwright Java](#trace-viewer-playwright-java)
- [Videos | Playwright .NET](#videos-playwright-net)
- [Screenshots | Playwright .NET](#screenshots-playwright-net)
- [Accessibility | Playwright .NET](#accessibility-playwright-net)
- [CDPSessionEvent | Playwright .NET](#cdpsessionevent-playwright-net)
- [CDPSession | Playwright .NET](#cdpsession-playwright-net)
- [CDPSession | Playwright Java](#cdpsession-playwright-java)
- [Assertions | Playwright .NET](#assertions-playwright-net)
- [APIResponse | Playwright Python](#apiresponse-playwright-python)
- [Setting up CI | Playwright .NET](#setting-up-ci-playwright-net)
- [ConsoleMessage | Playwright Java](#consolemessage-playwright-java)
- [Error | Playwright Python](#error-playwright-python)
- [ConsoleMessage | Playwright Python](#consolemessage-playwright-python)
- [FileChooser | Playwright Python](#filechooser-playwright-python)
- [CDPSession | Playwright Python](#cdpsession-playwright-python)
- [Route | Playwright Python](#route-playwright-python)
- [Keyboard | Playwright Python](#keyboard-playwright-python)
- [BrowserType | Playwright Python](#browsertype-playwright-python)
- [Request | Playwright Python](#request-playwright-python)
- [Docker | Playwright Java](#docker-playwright-java)
- [Supported languages | Playwright Java](#supported-languages-playwright-java)
- [Supported languages | Playwright Python](#supported-languages-playwright-python)
- [PlaywrightAssertions | Playwright Java](#playwrightassertions-playwright-java)
- [Videos | Playwright .NET](#videos-playwright-net)
- [WebView2 | Playwright .NET](#webview2-playwright-net)
- [Page object models | Playwright Java](#page-object-models-playwright-java)
- [Extensibility | Playwright .NET](#extensibility-playwright-net)
- [APIResponseAssertions | Playwright .NET](#apiresponseassertions-playwright-net)
- [Events | Playwright Python](#events-playwright-python)
- [Page object models | Playwright .NET](#page-object-models-playwright-net)
- [Docker | Playwright Python](#docker-playwright-python)
- [Page | Playwright Java](#page-playwright-java)
- [Network | Playwright .NET](#network-playwright-net)
- [WebSocket | Playwright .NET](#websocket-playwright-net)
- [Extensibility | Playwright Python](#extensibility-playwright-python)
- [Events | Playwright .NET](#events-playwright-net)
- [PageAssertions | Playwright .NET](#pageassertions-playwright-net)
- [APIResponseAssertions | Playwright Python](#apiresponseassertions-playwright-python)
- [Frames | Playwright Python](#frames-playwright-python)
- [WebSocketRoute | Playwright Python](#websocketroute-playwright-python)
- [Test generator | Playwright .NET](#test-generator-playwright-net)
- [Pages | Playwright .NET](#pages-playwright-net)
---
# Installation | Playwright
[Skip to main content](https://playwright.dev/docs/intro#__docusaurus_skipToContent_fallback)
On this page
Introduction[](https://playwright.dev/docs/intro#introduction "Direct link to Introduction")
----------------------------------------------------------------------------------------------
Playwright Test is an end-to-end test framework for modern web apps. It bundles test runner, assertions, isolation, parallelization and rich tooling. Playwright supports Chromium, WebKit and Firefox on Windows, Linux and macOS, locally or in CI, headless or headed, with native mobile emulation for Chrome (Android) and Mobile Safari.
**You will learn**
* [How to install Playwright](https://playwright.dev/docs/intro#installing-playwright)
* [What's installed](https://playwright.dev/docs/intro#whats-installed)
* [How to run the example test](https://playwright.dev/docs/intro#running-the-example-test)
* [How to open the HTML test report](https://playwright.dev/docs/intro#html-test-reports)
Installing Playwright[](https://playwright.dev/docs/intro#installing-playwright "Direct link to Installing Playwright")
-------------------------------------------------------------------------------------------------------------------------
Get started by installing Playwright using one of the following methods.
### Using npm, yarn or pnpm[](https://playwright.dev/docs/intro#using-npm-yarn-or-pnpm "Direct link to Using npm, yarn or pnpm")
The command below either initializes a new project or adds Playwright to an existing one.
* npm
* yarn
* pnpm
npm init playwright@latest
yarn create playwright
pnpm create playwright
When prompted, choose / confirm:
* TypeScript or JavaScript (default: TypeScript)
* Tests folder name (default: `tests`, or `e2e` if `tests` already exists)
* Add a GitHub Actions workflow (recommended for CI)
* Install Playwright browsers (default: yes)
You can re-run the command later; it does not overwrite existing tests.
### Using the VS Code Extension[](https://playwright.dev/docs/intro#using-the-vs-code-extension "Direct link to Using the VS Code Extension")
You can also create and run tests with the [VS Code Extension](https://playwright.dev/docs/getting-started-vscode)
.
What's Installed[](https://playwright.dev/docs/intro#whats-installed "Direct link to What's Installed")
---------------------------------------------------------------------------------------------------------
Playwright downloads required browser binaries and creates the scaffold below.
playwright.config.ts # Test configurationpackage.jsonpackage-lock.json # Or yarn.lock / pnpm-lock.yamltests/ example.spec.ts # Minimal example testtests-examples/ demo-todo-app.spec.ts # Richer example tests
The [playwright.config](https://playwright.dev/docs/test-configuration)
centralizes configuration: target browsers, timeouts, retries, projects, reporters and more. In existing projects dependencies are added to your current `package.json`.
`tests/` contains a minimal starter test. `tests-examples/` provides richer samples (e.g. a todo app) to explore patterns.
Running the Example Test[](https://playwright.dev/docs/intro#running-the-example-test "Direct link to Running the Example Test")
----------------------------------------------------------------------------------------------------------------------------------
By default tests run headless in parallel across Chromium, Firefox and WebKit (configurable in [playwright.config](https://playwright.dev/docs/test-configuration)
). Output and aggregated results display in the terminal.
* npm
* yarn
* pnpm
npx playwright test
yarn playwright test
pnpm exec playwright test
Tips:
* See the browser window: add `--headed`.
* Run a single project/browser: `--project=chromium`.
* Run one file: `npx playwright test tests/example.spec.ts`.
* Open testing UI: `--ui`.
See [Running Tests](https://playwright.dev/docs/running-tests)
for details on filtering, headed mode, sharding and retries.
HTML Test Reports[](https://playwright.dev/docs/intro#html-test-reports "Direct link to HTML Test Reports")
-------------------------------------------------------------------------------------------------------------
After a test run, the [HTML Reporter](https://playwright.dev/docs/test-reporters#html-reporter)
provides a dashboard filterable by the browser, passed, failed, skipped, flaky and more. Click a test to inspect errors, attachments and steps. It auto-opens only when failures occur; open manually with the command below.
* npm
* yarn
* pnpm
npx playwright show-report
yarn playwright show-report
pnpm exec playwright show-report
Running the Example Test in UI Mode[](https://playwright.dev/docs/intro#running-the-example-test-in-ui-mode "Direct link to Running the Example Test in UI Mode")
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
Run tests with [UI Mode](https://playwright.dev/docs/test-ui-mode)
for watch mode, live step view, time travel debugging and more.
* npm
* yarn
* pnpm
npx playwright test --ui
yarn playwright test --ui
pnpm exec playwright test --ui
See the [detailed guide on UI Mode](https://playwright.dev/docs/test-ui-mode)
for watch filters, step details and trace integration.
Updating Playwright[](https://playwright.dev/docs/intro#updating-playwright "Direct link to Updating Playwright")
-------------------------------------------------------------------------------------------------------------------
Update Playwright and download new browser binaries and their dependencies:
* npm
* yarn
* pnpm
npm install -D @playwright/test@latestnpx playwright install --with-deps
yarn add --dev @playwright/test@latestyarn playwright install --with-deps
pnpm install --save-dev @playwright/test@latestpnpm exec playwright install --with-deps
Check your installed version:
* npm
* yarn
* pnpm
npx playwright --version
yarn playwright --version
pnpm exec playwright --version
System requirements[](https://playwright.dev/docs/intro#system-requirements "Direct link to System requirements")
-------------------------------------------------------------------------------------------------------------------
* Node.js: latest 20.x, 22.x or 24.x.
* Windows 10+, Windows Server 2016+ or Windows Subsystem for Linux (WSL).
* macOS 14 (Ventura) or later.
* Debian 12 / 13, Ubuntu 22.04 / 24.04 (x86-64 or arm64).
What's next[](https://playwright.dev/docs/intro#whats-next "Direct link to What's next")
------------------------------------------------------------------------------------------
* [Write tests using web-first assertions, fixtures and locators](https://playwright.dev/docs/writing-tests)
* [Run single or multiple tests; headed mode](https://playwright.dev/docs/running-tests)
* [Generate tests with Codegen](https://playwright.dev/docs/codegen-intro)
* [View a trace of your tests](https://playwright.dev/docs/trace-viewer-intro)
* [Introduction](https://playwright.dev/docs/intro#introduction)
* [Installing Playwright](https://playwright.dev/docs/intro#installing-playwright)
* [Using npm, yarn or pnpm](https://playwright.dev/docs/intro#using-npm-yarn-or-pnpm)
* [Using the VS Code Extension](https://playwright.dev/docs/intro#using-the-vs-code-extension)
* [What's Installed](https://playwright.dev/docs/intro#whats-installed)
* [Running the Example Test](https://playwright.dev/docs/intro#running-the-example-test)
* [HTML Test Reports](https://playwright.dev/docs/intro#html-test-reports)
* [Running the Example Test in UI Mode](https://playwright.dev/docs/intro#running-the-example-test-in-ui-mode)
* [Updating Playwright](https://playwright.dev/docs/intro#updating-playwright)
* [System requirements](https://playwright.dev/docs/intro#system-requirements)
* [What's next](https://playwright.dev/docs/intro#whats-next)
---
# PlaywrightAssertions | Playwright
[Skip to main content](https://playwright.dev/docs/next/api/class-playwrightassertions#__docusaurus_skipToContent_fallback)
This is unreleased documentation for Playwright **Next** version.
For up-to-date documentation, see the **[latest version](https://playwright.dev/docs/api/class-playwrightassertions)
** (stable).
Version: Next
On this page
Playwright gives you Web-First Assertions with convenience methods for creating assertions that will wait and retry until the expected condition is met.
Consider the following example:
import { test, expect } from '@playwright/test';test('status becomes submitted', async ({ page }) => { // ... await page.locator('#submit-button').click(); await expect(page.locator('.status')).toHaveText('Submitted');});
Playwright will be re-testing the node with the selector `.status` until fetched Node has the `"Submitted"` text. It will be re-fetching the node and checking it over and over, until the condition is met or until the timeout is reached. You can pass this timeout as an option.
By default, the timeout for assertions is set to 5 seconds.
* * *
Methods[](https://playwright.dev/docs/next/api/class-playwrightassertions#methods "Direct link to Methods")
-------------------------------------------------------------------------------------------------------------
### expect(response)[](https://playwright.dev/docs/next/api/class-playwrightassertions#playwright-assertions-expect-api-response "Direct link to expect(response)")
Added in: v1.18 playwrightAssertions.expect(response)
Creates a [APIResponseAssertions](https://playwright.dev/docs/next/api/class-apiresponseassertions "APIResponseAssertions")
object for the given [APIResponse](https://playwright.dev/docs/next/api/class-apiresponse "APIResponse")
.
**Usage**
**Arguments**
* `response` [APIResponse](https://playwright.dev/docs/next/api/class-apiresponse "APIResponse")
[#](https://playwright.dev/docs/next/api/class-playwrightassertions#playwright-assertions-expect-api-response-option-response)
[APIResponse](https://playwright.dev/docs/next/api/class-apiresponse "APIResponse")
object to use for assertions.
**Returns**
* [APIResponseAssertions](https://playwright.dev/docs/next/api/class-apiresponseassertions "APIResponseAssertions")
[#](https://playwright.dev/docs/next/api/class-playwrightassertions#playwright-assertions-expect-api-response-return)
* * *
### expect(value)[](https://playwright.dev/docs/next/api/class-playwrightassertions#playwright-assertions-expect-generic "Direct link to expect(value)")
Added in: v1.9 playwrightAssertions.expect(value)
Creates a [GenericAssertions](https://playwright.dev/docs/next/api/class-genericassertions "GenericAssertions")
object for the given value.
**Usage**
expect(value);
**Arguments**
* `value` [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")
[#](https://playwright.dev/docs/next/api/class-playwrightassertions#playwright-assertions-expect-generic-option-value)
Value that will be asserted.
**Returns**
* [GenericAssertions](https://playwright.dev/docs/next/api/class-genericassertions "GenericAssertions")
[#](https://playwright.dev/docs/next/api/class-playwrightassertions#playwright-assertions-expect-generic-return)
* * *
### expect(locator)[](https://playwright.dev/docs/next/api/class-playwrightassertions#playwright-assertions-expect-locator "Direct link to expect(locator)")
Added in: v1.18 playwrightAssertions.expect(locator)
Creates a [LocatorAssertions](https://playwright.dev/docs/next/api/class-locatorassertions "LocatorAssertions")
object for the given [Locator](https://playwright.dev/docs/next/api/class-locator "Locator")
.
**Usage**
**Arguments**
* `locator` [Locator](https://playwright.dev/docs/next/api/class-locator "Locator")
[#](https://playwright.dev/docs/next/api/class-playwrightassertions#playwright-assertions-expect-locator-option-locator)
[Locator](https://playwright.dev/docs/next/api/class-locator "Locator")
object to use for assertions.
**Returns**
* [LocatorAssertions](https://playwright.dev/docs/next/api/class-locatorassertions "LocatorAssertions")
[#](https://playwright.dev/docs/next/api/class-playwrightassertions#playwright-assertions-expect-locator-return)
* * *
### expect(page)[](https://playwright.dev/docs/next/api/class-playwrightassertions#playwright-assertions-expect-page "Direct link to expect(page)")
Added in: v1.18 playwrightAssertions.expect(page)
Creates a [PageAssertions](https://playwright.dev/docs/next/api/class-pageassertions "PageAssertions")
object for the given [Page](https://playwright.dev/docs/next/api/class-page "Page")
.
**Usage**
**Arguments**
* `page` [Page](https://playwright.dev/docs/next/api/class-page "Page")
[#](https://playwright.dev/docs/next/api/class-playwrightassertions#playwright-assertions-expect-page-option-page)
[Page](https://playwright.dev/docs/next/api/class-page "Page")
object to use for assertions.
**Returns**
* [PageAssertions](https://playwright.dev/docs/next/api/class-pageassertions "PageAssertions")
[#](https://playwright.dev/docs/next/api/class-playwrightassertions#playwright-assertions-expect-page-return)
* [Methods](https://playwright.dev/docs/next/api/class-playwrightassertions#methods)
* [expect(response)](https://playwright.dev/docs/next/api/class-playwrightassertions#playwright-assertions-expect-api-response)
* [expect(value)](https://playwright.dev/docs/next/api/class-playwrightassertions#playwright-assertions-expect-generic)
* [expect(locator)](https://playwright.dev/docs/next/api/class-playwrightassertions#playwright-assertions-expect-locator)
* [expect(page)](https://playwright.dev/docs/next/api/class-playwrightassertions#playwright-assertions-expect-page)
---
# Video | Playwright Java
[Skip to main content](https://playwright.dev/java/docs/api/class-video#__docusaurus_skipToContent_fallback)
On this page
When browser context is created with the `recordVideo` option, each page has a video object associated with it.
System.out.println(page.video().path());
* * *
Methods[](https://playwright.dev/java/docs/api/class-video#methods "Direct link to Methods")
----------------------------------------------------------------------------------------------
### delete[](https://playwright.dev/java/docs/api/class-video#video-delete "Direct link to delete")
Added in: v1.11 video.delete
Deletes the video file. Will wait for the video to finish if necessary.
**Usage**
Video.delete();
**Returns**
* [void](https://docs.oracle.com/javase/tutorial/java/javaOO/methods.html "void")
[#](https://playwright.dev/java/docs/api/class-video#video-delete-return)
* * *
### path[](https://playwright.dev/java/docs/api/class-video#video-path "Direct link to path")
Added before v1.9 video.path
Returns the file system path this video will be recorded to. The video is guaranteed to be written to the filesystem upon closing the browser context. This method throws when connected remotely.
**Usage**
Video.path();
**Returns**
* [Path](https://docs.oracle.com/javase/8/docs/api/java/nio/file/Path.html "Path")
[#](https://playwright.dev/java/docs/api/class-video#video-path-return)
* * *
### saveAs[](https://playwright.dev/java/docs/api/class-video#video-save-as "Direct link to saveAs")
Added in: v1.11 video.saveAs
Saves the video to a user-specified path. It is safe to call this method while the video is still in progress, or after the page has closed. This method waits until the page is closed and the video is fully saved.
**Usage**
Video.saveAs(path);
**Arguments**
* `path` [Path](https://docs.oracle.com/javase/8/docs/api/java/nio/file/Path.html "Path")
[#](https://playwright.dev/java/docs/api/class-video#video-save-as-option-path)
Path where the video should be saved.
**Returns**
* [void](https://docs.oracle.com/javase/tutorial/java/javaOO/methods.html "void")
[#](https://playwright.dev/java/docs/api/class-video#video-save-as-return)
* [Methods](https://playwright.dev/java/docs/api/class-video#methods)
* [delete](https://playwright.dev/java/docs/api/class-video#video-delete)
* [path](https://playwright.dev/java/docs/api/class-video#video-path)
* [saveAs](https://playwright.dev/java/docs/api/class-video#video-save-as)
---
# Mouse | Playwright .NET
[Skip to main content](https://playwright.dev/dotnet/docs/api/class-mouse#__docusaurus_skipToContent_fallback)
On this page
The Mouse class operates in main-frame CSS pixels relative to the top-left corner of the viewport.
tip
If you want to debug where the mouse moved, you can use the [Trace viewer](https://playwright.dev/dotnet/docs/trace-viewer-intro)
or [Playwright Inspector](https://playwright.dev/dotnet/docs/running-tests)
. A red dot showing the location of the mouse will be shown for every mouse action.
Every `page` object has its own Mouse, accessible with [Page.Mouse](https://playwright.dev/dotnet/docs/api/class-page#page-mouse)
.
await Page.Mouse.MoveAsync(0, 0);await Page.Mouse.DownAsync();await Page.Mouse.MoveAsync(0, 100);await Page.Mouse.MoveAsync(100, 100);await Page.Mouse.MoveAsync(100, 0);await Page.Mouse.MoveAsync(0, 0);await Page.Mouse.UpAsync();
* * *
Methods[](https://playwright.dev/dotnet/docs/api/class-mouse#methods "Direct link to Methods")
------------------------------------------------------------------------------------------------
### ClickAsync[](https://playwright.dev/dotnet/docs/api/class-mouse#mouse-click "Direct link to ClickAsync")
Added before v1.9 mouse.ClickAsync
Shortcut for [Mouse.MoveAsync()](https://playwright.dev/dotnet/docs/api/class-mouse#mouse-move)
, [Mouse.DownAsync()](https://playwright.dev/dotnet/docs/api/class-mouse#mouse-down)
, [Mouse.UpAsync()](https://playwright.dev/dotnet/docs/api/class-mouse#mouse-up)
.
**Usage**
await Mouse.ClickAsync(x, y, options);
**Arguments**
* `x` \[float\][#](https://playwright.dev/dotnet/docs/api/class-mouse#mouse-click-option-x)
X coordinate relative to the main frame's viewport in CSS pixels.
* `y` \[float\][#](https://playwright.dev/dotnet/docs/api/class-mouse#mouse-click-option-y)
Y coordinate relative to the main frame's viewport in CSS pixels.
* `options` `MouseClickOptions?` _(optional)_
* `Button` `enum MouseButton { Left, Right, Middle }?` _(optional)_[#](https://playwright.dev/dotnet/docs/api/class-mouse#mouse-click-option-button)
Defaults to `left`.
* `ClickCount` [int](https://docs.microsoft.com/en-us/dotnet/api/system.int32 "int")
? _(optional)_[#](https://playwright.dev/dotnet/docs/api/class-mouse#mouse-click-option-click-count)
defaults to 1. See [UIEvent.detail](https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/detail "UIEvent.detail")
.
* `Delay` \[float\]? _(optional)_[#](https://playwright.dev/dotnet/docs/api/class-mouse#mouse-click-option-delay)
Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0.
**Returns**
* [void](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/void "void")
[#](https://playwright.dev/dotnet/docs/api/class-mouse#mouse-click-return)
* * *
### DblClickAsync[](https://playwright.dev/dotnet/docs/api/class-mouse#mouse-dblclick "Direct link to DblClickAsync")
Added before v1.9 mouse.DblClickAsync
Shortcut for [Mouse.MoveAsync()](https://playwright.dev/dotnet/docs/api/class-mouse#mouse-move)
, [Mouse.DownAsync()](https://playwright.dev/dotnet/docs/api/class-mouse#mouse-down)
, [Mouse.UpAsync()](https://playwright.dev/dotnet/docs/api/class-mouse#mouse-up)
, [Mouse.DownAsync()](https://playwright.dev/dotnet/docs/api/class-mouse#mouse-down)
and [Mouse.UpAsync()](https://playwright.dev/dotnet/docs/api/class-mouse#mouse-up)
.
**Usage**
await Mouse.DblClickAsync(x, y, options);
**Arguments**
* `x` \[float\][#](https://playwright.dev/dotnet/docs/api/class-mouse#mouse-dblclick-option-x)
X coordinate relative to the main frame's viewport in CSS pixels.
* `y` \[float\][#](https://playwright.dev/dotnet/docs/api/class-mouse#mouse-dblclick-option-y)
Y coordinate relative to the main frame's viewport in CSS pixels.
* `options` `MouseDblClickOptions?` _(optional)_
* `Button` `enum MouseButton { Left, Right, Middle }?` _(optional)_[#](https://playwright.dev/dotnet/docs/api/class-mouse#mouse-dblclick-option-button)
Defaults to `left`.
* `Delay` \[float\]? _(optional)_[#](https://playwright.dev/dotnet/docs/api/class-mouse#mouse-dblclick-option-delay)
Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0.
**Returns**
* [void](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/void "void")
[#](https://playwright.dev/dotnet/docs/api/class-mouse#mouse-dblclick-return)
* * *
### DownAsync[](https://playwright.dev/dotnet/docs/api/class-mouse#mouse-down "Direct link to DownAsync")
Added before v1.9 mouse.DownAsync
Dispatches a `mousedown` event.
**Usage**
await Mouse.DownAsync(options);
**Arguments**
* `options` `MouseDownOptions?` _(optional)_
* `Button` `enum MouseButton { Left, Right, Middle }?` _(optional)_[#](https://playwright.dev/dotnet/docs/api/class-mouse#mouse-down-option-button)
Defaults to `left`.
* `ClickCount` [int](https://docs.microsoft.com/en-us/dotnet/api/system.int32 "int")
? _(optional)_[#](https://playwright.dev/dotnet/docs/api/class-mouse#mouse-down-option-click-count)
defaults to 1. See [UIEvent.detail](https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/detail "UIEvent.detail")
.
**Returns**
* [void](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/void "void")
[#](https://playwright.dev/dotnet/docs/api/class-mouse#mouse-down-return)
* * *
### MoveAsync[](https://playwright.dev/dotnet/docs/api/class-mouse#mouse-move "Direct link to MoveAsync")
Added before v1.9 mouse.MoveAsync
Dispatches a `mousemove` event.
**Usage**
await Mouse.MoveAsync(x, y, options);
**Arguments**
* `x` \[float\][#](https://playwright.dev/dotnet/docs/api/class-mouse#mouse-move-option-x)
X coordinate relative to the main frame's viewport in CSS pixels.
* `y` \[float\][#](https://playwright.dev/dotnet/docs/api/class-mouse#mouse-move-option-y)
Y coordinate relative to the main frame's viewport in CSS pixels.
* `options` `MouseMoveOptions?` _(optional)_
* `Steps` [int](https://docs.microsoft.com/en-us/dotnet/api/system.int32 "int")
? _(optional)_[#](https://playwright.dev/dotnet/docs/api/class-mouse#mouse-move-option-steps)
Defaults to 1. Sends intermediate `mousemove` events.
**Returns**
* [void](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/void "void")
[#](https://playwright.dev/dotnet/docs/api/class-mouse#mouse-move-return)
* * *
### UpAsync[](https://playwright.dev/dotnet/docs/api/class-mouse#mouse-up "Direct link to UpAsync")
Added before v1.9 mouse.UpAsync
Dispatches a `mouseup` event.
**Usage**
await Mouse.UpAsync(options);
**Arguments**
* `options` `MouseUpOptions?` _(optional)_
* `Button` `enum MouseButton { Left, Right, Middle }?` _(optional)_[#](https://playwright.dev/dotnet/docs/api/class-mouse#mouse-up-option-button)
Defaults to `left`.
* `ClickCount` [int](https://docs.microsoft.com/en-us/dotnet/api/system.int32 "int")
? _(optional)_[#](https://playwright.dev/dotnet/docs/api/class-mouse#mouse-up-option-click-count)
defaults to 1. See [UIEvent.detail](https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/detail "UIEvent.detail")
.
**Returns**
* [void](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/void "void")
[#](https://playwright.dev/dotnet/docs/api/class-mouse#mouse-up-return)
* * *
### WheelAsync[](https://playwright.dev/dotnet/docs/api/class-mouse#mouse-wheel "Direct link to WheelAsync")
Added in: v1.15 mouse.WheelAsync
Dispatches a `wheel` event. This method is usually used to manually scroll the page. See [scrolling](https://playwright.dev/dotnet/docs/input#scrolling)
for alternative ways to scroll.
note
Wheel events may cause scrolling if they are not handled, and this method does not wait for the scrolling to finish before returning.
**Usage**
await Mouse.WheelAsync(deltaX, deltaY);
**Arguments**
* `deltaX` \[float\][#](https://playwright.dev/dotnet/docs/api/class-mouse#mouse-wheel-option-delta-x)
Pixels to scroll horizontally.
* `deltaY` \[float\][#](https://playwright.dev/dotnet/docs/api/class-mouse#mouse-wheel-option-delta-y)
Pixels to scroll vertically.
**Returns**
* [void](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/void "void")
[#](https://playwright.dev/dotnet/docs/api/class-mouse#mouse-wheel-return)
* [Methods](https://playwright.dev/dotnet/docs/api/class-mouse#methods)
* [ClickAsync](https://playwright.dev/dotnet/docs/api/class-mouse#mouse-click)
* [DblClickAsync](https://playwright.dev/dotnet/docs/api/class-mouse#mouse-dblclick)
* [DownAsync](https://playwright.dev/dotnet/docs/api/class-mouse#mouse-down)
* [MoveAsync](https://playwright.dev/dotnet/docs/api/class-mouse#mouse-move)
* [UpAsync](https://playwright.dev/dotnet/docs/api/class-mouse#mouse-up)
* [WheelAsync](https://playwright.dev/dotnet/docs/api/class-mouse#mouse-wheel)
---
# TimeoutError | Playwright Java
[Skip to main content](https://playwright.dev/java/docs/api/class-timeouterror#__docusaurus_skipToContent_fallback)
* extends: [PlaywrightException](https://playwright.dev/java/docs/api/class-playwrightexception "PlaywrightException")
TimeoutError is emitted whenever certain operations are terminated due to timeout, e.g. [Locator.waitFor()](https://playwright.dev/java/docs/api/class-locator#locator-wait-for)
or [BrowserType.launch()](https://playwright.dev/java/docs/api/class-browsertype#browser-type-launch)
.
package org.example;import com.microsoft.playwright.*;public class TimeoutErrorExample { public static void main(String[] args) { try (Playwright playwright = Playwright.create()) { Browser browser = playwright.firefox().launch(); BrowserContext context = browser.newContext(); Page page = context.newPage(); try { page.locator("text=Example").click(new Locator.ClickOptions().setTimeout(100)); } catch (TimeoutError e) { System.out.println("Timeout!"); } } }}
---
# Video | Playwright .NET
[Skip to main content](https://playwright.dev/dotnet/docs/api/class-video#__docusaurus_skipToContent_fallback)
On this page
When browser context is created with the `recordVideo` option, each page has a video object associated with it.
Console.WriteLine(await page.Video.GetPathAsync());
* * *
Methods[](https://playwright.dev/dotnet/docs/api/class-video#methods "Direct link to Methods")
------------------------------------------------------------------------------------------------
### DeleteAsync[](https://playwright.dev/dotnet/docs/api/class-video#video-delete "Direct link to DeleteAsync")
Added in: v1.11 video.DeleteAsync
Deletes the video file. Will wait for the video to finish if necessary.
**Usage**
await Video.DeleteAsync();
**Returns**
* [void](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/void "void")
[#](https://playwright.dev/dotnet/docs/api/class-video#video-delete-return)
* * *
### PathAsync[](https://playwright.dev/dotnet/docs/api/class-video#video-path "Direct link to PathAsync")
Added before v1.9 video.PathAsync
Returns the file system path this video will be recorded to. The video is guaranteed to be written to the filesystem upon closing the browser context. This method throws when connected remotely.
**Usage**
await Video.PathAsync();
**Returns**
* [string](https://docs.microsoft.com/en-us/dotnet/api/system.string "string")
[#](https://playwright.dev/dotnet/docs/api/class-video#video-path-return)
* * *
### SaveAsAsync[](https://playwright.dev/dotnet/docs/api/class-video#video-save-as "Direct link to SaveAsAsync")
Added in: v1.11 video.SaveAsAsync
Saves the video to a user-specified path. It is safe to call this method while the video is still in progress, or after the page has closed. This method waits until the page is closed and the video is fully saved.
**Usage**
await Video.SaveAsAsync(path);
**Arguments**
* `path` [string](https://docs.microsoft.com/en-us/dotnet/api/system.string "string")
[#](https://playwright.dev/dotnet/docs/api/class-video#video-save-as-option-path)
Path where the video should be saved.
**Returns**
* [void](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/void "void")
[#](https://playwright.dev/dotnet/docs/api/class-video#video-save-as-return)
* [Methods](https://playwright.dev/dotnet/docs/api/class-video#methods)
* [DeleteAsync](https://playwright.dev/dotnet/docs/api/class-video#video-delete)
* [PathAsync](https://playwright.dev/dotnet/docs/api/class-video#video-path)
* [SaveAsAsync](https://playwright.dev/dotnet/docs/api/class-video#video-save-as)
---
# WebError | Playwright Java
[Skip to main content](https://playwright.dev/java/docs/api/class-weberror#__docusaurus_skipToContent_fallback)
On this page
[WebError](https://playwright.dev/java/docs/api/class-weberror "WebError")
class represents an unhandled exception thrown in the page. It is dispatched via the [BrowserContext.onWebError(handler)](https://playwright.dev/java/docs/api/class-browsercontext#browser-context-event-web-error)
event.
// Log all uncaught errors to the terminalcontext.onWebError(webError -> { System.out.println("Uncaught exception: " + webError.error());});// Navigate to a page with an exception.page.navigate("data:text/html,");
* * *
Methods[](https://playwright.dev/java/docs/api/class-weberror#methods "Direct link to Methods")
-------------------------------------------------------------------------------------------------
### error[](https://playwright.dev/java/docs/api/class-weberror#web-error-error "Direct link to error")
Added in: v1.38 webError.error
Unhandled error that was thrown.
**Usage**
WebError.error();
**Returns**
* [String](https://docs.oracle.com/javase/8/docs/api/java/lang/String.html "String")
[#](https://playwright.dev/java/docs/api/class-weberror#web-error-error-return)
* * *
### page[](https://playwright.dev/java/docs/api/class-weberror#web-error-page "Direct link to page")
Added in: v1.38 webError.page
The page that produced this unhandled exception, if any.
**Usage**
WebError.page();
**Returns**
* [null](https://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#jls-3.10.7 "null")
| [Page](https://playwright.dev/java/docs/api/class-page "Page")
[#](https://playwright.dev/java/docs/api/class-weberror#web-error-page-return)
* [Methods](https://playwright.dev/java/docs/api/class-weberror#methods)
* [error](https://playwright.dev/java/docs/api/class-weberror#web-error-error)
* [page](https://playwright.dev/java/docs/api/class-weberror#web-error-page)
---
# Selectors | Playwright Java
[Skip to main content](https://playwright.dev/java/docs/api/class-selectors#__docusaurus_skipToContent_fallback)
On this page
Selectors can be used to install custom selector engines. See [extensibility](https://playwright.dev/java/docs/extensibility)
for more information.
* * *
Methods[](https://playwright.dev/java/docs/api/class-selectors#methods "Direct link to Methods")
--------------------------------------------------------------------------------------------------
### register[](https://playwright.dev/java/docs/api/class-selectors#selectors-register "Direct link to register")
Added before v1.9 selectors.register
Selectors must be registered before creating the page.
**Usage**
An example of registering selector engine that queries elements based on a tag name:
// Script that evaluates to a selector engine instance. The script is evaluated in the page context.String createTagNameEngine = "{\n" + " // Returns the first element matching given selector in the root's subtree.\n" + " query(root, selector) {\n" + " return root.querySelector(selector);\n" + " },\n" + " // Returns all elements matching given selector in the root's subtree.\n" + " queryAll(root, selector) {\n" + " return Array.from(root.querySelectorAll(selector));\n" + " }\n" + "}";// Register the engine. Selectors will be prefixed with "tag=".playwright.selectors().register("tag", createTagNameEngine);Browser browser = playwright.firefox().launch();Page page = browser.newPage();page.setContent("
");// Use the selector prefixed with its name.Locator button = page.locator("tag=button");// Combine it with built-in locators.page.locator("tag=div").getByText("Click me").click();// Can use it in any methods supporting selectors.int buttonCount = (int) page.locator("tag=button").count();browser.close();
**Arguments**
* `name` [String](https://docs.oracle.com/javase/8/docs/api/java/lang/String.html "String")
[#](https://playwright.dev/java/docs/api/class-selectors#selectors-register-option-name)
Name that is used in selectors as a prefix, e.g. `{name: 'foo'}` enables `foo=myselectorbody` selectors. May only contain `[a-zA-Z0-9_]` characters.
* `script` [String](https://docs.oracle.com/javase/8/docs/api/java/lang/String.html "String")
| [Path](https://docs.oracle.com/javase/8/docs/api/java/nio/file/Path.html "Path")
[#](https://playwright.dev/java/docs/api/class-selectors#selectors-register-option-script)
Script that evaluates to a selector engine instance. The script is evaluated in the page context.
* `options` `Selectors.RegisterOptions` _(optional)_
* `setContentScript` [boolean](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html "boolean")
_(optional)_[#](https://playwright.dev/java/docs/api/class-selectors#selectors-register-option-content-script)
Whether to run this selector engine in isolated JavaScript environment. This environment has access to the same DOM, but not any JavaScript objects from the frame's scripts. Defaults to `false`. Note that running as a content script is not guaranteed when this engine is used together with other registered engines.
**Returns**
* [void](https://docs.oracle.com/javase/tutorial/java/javaOO/methods.html "void")
[#](https://playwright.dev/java/docs/api/class-selectors#selectors-register-return)
* * *
### setTestIdAttribute[](https://playwright.dev/java/docs/api/class-selectors#selectors-set-test-id-attribute "Direct link to setTestIdAttribute")
Added in: v1.27 selectors.setTestIdAttribute
Defines custom attribute name to be used in [Page.getByTestId()](https://playwright.dev/java/docs/api/class-page#page-get-by-test-id)
. `data-testid` is used by default.
**Usage**
Selectors.setTestIdAttribute(attributeName);
**Arguments**
* `attributeName` [String](https://docs.oracle.com/javase/8/docs/api/java/lang/String.html "String")
[#](https://playwright.dev/java/docs/api/class-selectors#selectors-set-test-id-attribute-option-attribute-name)
Test id attribute name.
* [Methods](https://playwright.dev/java/docs/api/class-selectors#methods)
* [register](https://playwright.dev/java/docs/api/class-selectors#selectors-register)
* [setTestIdAttribute](https://playwright.dev/java/docs/api/class-selectors#selectors-set-test-id-attribute)
---
# Download | Playwright .NET
[Skip to main content](https://playwright.dev/dotnet/docs/api/class-download#__docusaurus_skipToContent_fallback)
On this page
[Download](https://playwright.dev/dotnet/docs/api/class-download "Download")
objects are dispatched by page via the [Page.Download](https://playwright.dev/dotnet/docs/api/class-page#page-event-download)
event.
All the downloaded files belonging to the browser context are deleted when the browser context is closed.
Download event is emitted once the download starts. Download path becomes available once download completes.
// Start the task of waiting for the download before clickingvar waitForDownloadTask = page.WaitForDownloadAsync();await page.GetByText("Download file").ClickAsync();var download = await waitForDownloadTask;// Wait for the download process to complete and save the downloaded file somewhereawait download.SaveAsAsync("/path/to/save/at/" + download.SuggestedFilename);
* * *
Methods[](https://playwright.dev/dotnet/docs/api/class-download#methods "Direct link to Methods")
---------------------------------------------------------------------------------------------------
### CancelAsync[](https://playwright.dev/dotnet/docs/api/class-download#download-cancel "Direct link to CancelAsync")
Added in: v1.13 download.CancelAsync
Cancels a download. Will not fail if the download is already finished or canceled. Upon successful cancellations, `download.failure()` would resolve to `'canceled'`.
**Usage**
await Download.CancelAsync();
**Returns**
* [void](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/void "void")
[#](https://playwright.dev/dotnet/docs/api/class-download#download-cancel-return)
* * *
### CreateReadStreamAsync[](https://playwright.dev/dotnet/docs/api/class-download#download-create-read-stream "Direct link to CreateReadStreamAsync")
Added before v1.9 download.CreateReadStreamAsync
Returns a readable stream for a successful download, or throws for a failed/canceled download.
**Usage**
await Download.CreateReadStreamAsync();
**Returns**
* \[Stream\][#](https://playwright.dev/dotnet/docs/api/class-download#download-create-read-stream-return)
* * *
### DeleteAsync[](https://playwright.dev/dotnet/docs/api/class-download#download-delete "Direct link to DeleteAsync")
Added before v1.9 download.DeleteAsync
Deletes the downloaded file. Will wait for the download to finish if necessary.
**Usage**
await Download.DeleteAsync();
**Returns**
* [void](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/void "void")
[#](https://playwright.dev/dotnet/docs/api/class-download#download-delete-return)
* * *
### FailureAsync[](https://playwright.dev/dotnet/docs/api/class-download#download-failure "Direct link to FailureAsync")
Added before v1.9 download.FailureAsync
Returns download error if any. Will wait for the download to finish if necessary.
**Usage**
await Download.FailureAsync();
**Returns**
* [string](https://docs.microsoft.com/en-us/dotnet/api/system.string "string")
?[#](https://playwright.dev/dotnet/docs/api/class-download#download-failure-return)
* * *
### Page[](https://playwright.dev/dotnet/docs/api/class-download#download-page "Direct link to Page")
Added in: v1.12 download.Page
Get the page that the download belongs to.
**Usage**
Download.Page
**Returns**
* [Page](https://playwright.dev/dotnet/docs/api/class-page "Page")
[#](https://playwright.dev/dotnet/docs/api/class-download#download-page-return)
* * *
### PathAsync[](https://playwright.dev/dotnet/docs/api/class-download#download-path "Direct link to PathAsync")
Added before v1.9 download.PathAsync
Returns path to the downloaded file for a successful download, or throws for a failed/canceled download. The method will wait for the download to finish if necessary. The method throws when connected remotely.
Note that the download's file name is a random GUID, use [Download.SuggestedFilename](https://playwright.dev/dotnet/docs/api/class-download#download-suggested-filename)
to get suggested file name.
**Usage**
await Download.PathAsync();
**Returns**
* [string](https://docs.microsoft.com/en-us/dotnet/api/system.string "string")
[#](https://playwright.dev/dotnet/docs/api/class-download#download-path-return)
* * *
### SaveAsAsync[](https://playwright.dev/dotnet/docs/api/class-download#download-save-as "Direct link to SaveAsAsync")
Added before v1.9 download.SaveAsAsync
Copy the download to a user-specified path. It is safe to call this method while the download is still in progress. Will wait for the download to finish if necessary.
**Usage**
await download.SaveAsAsync("/path/to/save/at/" + download.SuggestedFilename);
**Arguments**
* `path` [string](https://docs.microsoft.com/en-us/dotnet/api/system.string "string")
[#](https://playwright.dev/dotnet/docs/api/class-download#download-save-as-option-path)
Path where the download should be copied.
**Returns**
* [void](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/void "void")
[#](https://playwright.dev/dotnet/docs/api/class-download#download-save-as-return)
* * *
### SuggestedFilename[](https://playwright.dev/dotnet/docs/api/class-download#download-suggested-filename "Direct link to SuggestedFilename")
Added before v1.9 download.SuggestedFilename
Returns suggested filename for this download. It is typically computed by the browser from the [`Content-Disposition`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition)
response header or the `download` attribute. See the spec on [whatwg](https://html.spec.whatwg.org/#downloading-resources)
. Different browsers can use different logic for computing it.
**Usage**
Download.SuggestedFilename
**Returns**
* [string](https://docs.microsoft.com/en-us/dotnet/api/system.string "string")
[#](https://playwright.dev/dotnet/docs/api/class-download#download-suggested-filename-return)
* * *
### Url[](https://playwright.dev/dotnet/docs/api/class-download#download-url "Direct link to Url")
Added before v1.9 download.Url
Returns downloaded url.
**Usage**
Download.Url
**Returns**
* [string](https://docs.microsoft.com/en-us/dotnet/api/system.string "string")
[#](https://playwright.dev/dotnet/docs/api/class-download#download-url-return)
* [Methods](https://playwright.dev/dotnet/docs/api/class-download#methods)
* [CancelAsync](https://playwright.dev/dotnet/docs/api/class-download#download-cancel)
* [CreateReadStreamAsync](https://playwright.dev/dotnet/docs/api/class-download#download-create-read-stream)
* [DeleteAsync](https://playwright.dev/dotnet/docs/api/class-download#download-delete)
* [FailureAsync](https://playwright.dev/dotnet/docs/api/class-download#download-failure)
* [Page](https://playwright.dev/dotnet/docs/api/class-download#download-page)
* [PathAsync](https://playwright.dev/dotnet/docs/api/class-download#download-path)
* [SaveAsAsync](https://playwright.dev/dotnet/docs/api/class-download#download-save-as)
* [SuggestedFilename](https://playwright.dev/dotnet/docs/api/class-download#download-suggested-filename)
* [Url](https://playwright.dev/dotnet/docs/api/class-download#download-url)
---
# Dialog | Playwright .NET
[Skip to main content](https://playwright.dev/dotnet/docs/api/class-dialog#__docusaurus_skipToContent_fallback)
On this page
[Dialog](https://playwright.dev/dotnet/docs/api/class-dialog "Dialog")
objects are dispatched by page via the [Page.Dialog](https://playwright.dev/dotnet/docs/api/class-page#page-event-dialog)
event.
An example of using `Dialog` class:
using Microsoft.Playwright;using System.Threading.Tasks;class DialogExample{ public static async Task Run() { using var playwright = await Playwright.CreateAsync(); await using var browser = await playwright.Chromium.LaunchAsync(); var page = await browser.NewPageAsync(); page.Dialog += async (_, dialog) => { System.Console.WriteLine(dialog.Message); await dialog.DismissAsync(); }; await page.EvaluateAsync("alert('1');"); }}
note
Dialogs are dismissed automatically, unless there is a [Page.Dialog](https://playwright.dev/dotnet/docs/api/class-page#page-event-dialog)
listener. When listener is present, it **must** either [Dialog.AcceptAsync()](https://playwright.dev/dotnet/docs/api/class-dialog#dialog-accept)
or [Dialog.DismissAsync()](https://playwright.dev/dotnet/docs/api/class-dialog#dialog-dismiss)
the dialog - otherwise the page will [freeze](https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop#never_blocking)
waiting for the dialog, and actions like click will never finish.
* * *
Methods[](https://playwright.dev/dotnet/docs/api/class-dialog#methods "Direct link to Methods")
-------------------------------------------------------------------------------------------------
### AcceptAsync[](https://playwright.dev/dotnet/docs/api/class-dialog#dialog-accept "Direct link to AcceptAsync")
Added before v1.9 dialog.AcceptAsync
Returns when the dialog has been accepted.
**Usage**
await Dialog.AcceptAsync(promptText);
**Arguments**
* `promptText` [string](https://docs.microsoft.com/en-us/dotnet/api/system.string "string")
? _(optional)_[#](https://playwright.dev/dotnet/docs/api/class-dialog#dialog-accept-option-prompt-text)
A text to enter in prompt. Does not cause any effects if the dialog's `type` is not prompt. Optional.
**Returns**
* [void](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/void "void")
[#](https://playwright.dev/dotnet/docs/api/class-dialog#dialog-accept-return)
* * *
### DefaultValue[](https://playwright.dev/dotnet/docs/api/class-dialog#dialog-default-value "Direct link to DefaultValue")
Added before v1.9 dialog.DefaultValue
If dialog is prompt, returns default prompt value. Otherwise, returns empty string.
**Usage**
Dialog.DefaultValue
**Returns**
* [string](https://docs.microsoft.com/en-us/dotnet/api/system.string "string")
[#](https://playwright.dev/dotnet/docs/api/class-dialog#dialog-default-value-return)
* * *
### DismissAsync[](https://playwright.dev/dotnet/docs/api/class-dialog#dialog-dismiss "Direct link to DismissAsync")
Added before v1.9 dialog.DismissAsync
Returns when the dialog has been dismissed.
**Usage**
await Dialog.DismissAsync();
**Returns**
* [void](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/void "void")
[#](https://playwright.dev/dotnet/docs/api/class-dialog#dialog-dismiss-return)
* * *
### Message[](https://playwright.dev/dotnet/docs/api/class-dialog#dialog-message "Direct link to Message")
Added before v1.9 dialog.Message
A message displayed in the dialog.
**Usage**
Dialog.Message
**Returns**
* [string](https://docs.microsoft.com/en-us/dotnet/api/system.string "string")
[#](https://playwright.dev/dotnet/docs/api/class-dialog#dialog-message-return)
* * *
### Page[](https://playwright.dev/dotnet/docs/api/class-dialog#dialog-page "Direct link to Page")
Added in: v1.34 dialog.Page
The page that initiated this dialog, if available.
**Usage**
Dialog.Page
**Returns**
* [Page](https://playwright.dev/dotnet/docs/api/class-page "Page")
?[#](https://playwright.dev/dotnet/docs/api/class-dialog#dialog-page-return)
* * *
### Type[](https://playwright.dev/dotnet/docs/api/class-dialog#dialog-type "Direct link to Type")
Added before v1.9 dialog.Type
Returns dialog's type, can be one of `alert`, `beforeunload`, `confirm` or `prompt`.
**Usage**
Dialog.Type
**Returns**
* [string](https://docs.microsoft.com/en-us/dotnet/api/system.string "string")
[#](https://playwright.dev/dotnet/docs/api/class-dialog#dialog-type-return)
* [Methods](https://playwright.dev/dotnet/docs/api/class-dialog#methods)
* [AcceptAsync](https://playwright.dev/dotnet/docs/api/class-dialog#dialog-accept)
* [DefaultValue](https://playwright.dev/dotnet/docs/api/class-dialog#dialog-default-value)
* [DismissAsync](https://playwright.dev/dotnet/docs/api/class-dialog#dialog-dismiss)
* [Message](https://playwright.dev/dotnet/docs/api/class-dialog#dialog-message)
* [Page](https://playwright.dev/dotnet/docs/api/class-dialog#dialog-page)
* [Type](https://playwright.dev/dotnet/docs/api/class-dialog#dialog-type)
---
# Snapshot testing | Playwright .NET
[Skip to main content](https://playwright.dev/dotnet/docs/aria-snapshots#__docusaurus_skipToContent_fallback)
On this page
Overview[](https://playwright.dev/dotnet/docs/aria-snapshots#overview "Direct link to Overview")
--------------------------------------------------------------------------------------------------
With Playwright's Snapshot testing you can assert the accessibility tree of a page against a predefined snapshot template.
await page.GotoAsync("https://playwright.dev/");await Expect(page.Locator("banner")).ToMatchAriaSnapshotAsync(@" - banner: - heading ""Playwright enables reliable end-to-end testing for modern web apps."" [level=1] - link ""Get started"" - link ""Star microsoft/playwright on GitHub"" - link /[\\d]+k\\+ stargazers on GitHub/");
Assertion testing vs Snapshot testing[](https://playwright.dev/dotnet/docs/aria-snapshots#assertion-testing-vs-snapshot-testing "Direct link to Assertion testing vs Snapshot testing")
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Snapshot testing and assertion testing serve different purposes in test automation:
### Assertion testing[](https://playwright.dev/dotnet/docs/aria-snapshots#assertion-testing "Direct link to Assertion testing")
Assertion testing is a targeted approach where you assert specific values or conditions about elements or components. For instance, with Playwright, [Expect(Locator).ToHaveTextAsync()](https://playwright.dev/dotnet/docs/api/class-locatorassertions#locator-assertions-to-have-text)
verifies that an element contains the expected text, and [Expect(Locator).ToHaveValueAsync()](https://playwright.dev/dotnet/docs/api/class-locatorassertions#locator-assertions-to-have-value)
confirms that an input field has the expected value. Assertion tests are specific and generally check the current state of an element or property against an expected, predefined state. They work well for predictable, single-value checks but are limited in scope when testing the broader structure or variations.
**Advantages**
* **Clarity**: The intent of the test is explicit and easy to understand.
* **Specificity**: Tests focus on particular aspects of functionality, making them more robust against unrelated changes.
* **Debugging**: Failures provide targeted feedback, pointing directly to the problematic aspect.
**Disadvantages**
* **Verbose for complex outputs**: Writing assertions for complex data structures or large outputs can be cumbersome and error-prone.
* **Maintenance overhead**: As code evolves, manually updating assertions can be time-consuming.
### Snapshot testing[](https://playwright.dev/dotnet/docs/aria-snapshots#snapshot-testing "Direct link to Snapshot testing")
Snapshot testing captures a “snapshot” or representation of the entire state of an element, component, or data at a given moment, which is then saved for future comparisons. When re-running tests, the current state is compared to the snapshot, and if there are differences, the test fails. This approach is especially useful for complex or dynamic structures, where manually asserting each detail would be too time-consuming. Snapshot testing is broader and more holistic than assertion testing, allowing you to track more complex changes over time.
**Advantages**
* **Simplifies complex outputs**: For example, testing a UI component's rendered output can be tedious with traditional assertions. Snapshots capture the entire output for easy comparison.
* **Quick Feedback loop**: Developers can easily spot unintended changes in the output.
* **Encourages consistency**: Helps maintain consistent output as code evolves.
**Disadvantages**
* **Over-Reliance**: It can be tempting to accept changes to snapshots without fully understanding them, potentially hiding bugs.
* **Granularity**: Large snapshots may be hard to interpret when differences arise, especially if minor changes affect large portions of the output.
* **Suitability**: Not ideal for highly dynamic content where outputs change frequently or unpredictably.
### When to use[](https://playwright.dev/dotnet/docs/aria-snapshots#when-to-use "Direct link to When to use")
* **Snapshot testing** is ideal for:
* UI testing of whole pages and components.
* Broad structural checks for complex UI components.
* Regression testing for outputs that rarely change structure.
* **Assertion testing** is ideal for:
* Core logic validation.
* Computed value testing.
* Fine-grained tests requiring precise conditions.
By combining snapshot testing for broad, structural checks and assertion testing for specific functionality, you can achieve a well-rounded testing strategy.
Aria snapshots[](https://playwright.dev/dotnet/docs/aria-snapshots#aria-snapshots "Direct link to Aria snapshots")
--------------------------------------------------------------------------------------------------------------------
In Playwright, aria snapshots provide a YAML representation of the accessibility tree of a page. These snapshots can be stored and compared later to verify if the page structure remains consistent or meets defined expectations.
The YAML format describes the hierarchical structure of accessible elements on the page, detailing **roles**, **attributes**, **values**, and **text content**. The structure follows a tree-like syntax, where each node represents an accessible element, and indentation indicates nested elements.
Each accessible element in the tree is represented as a YAML node:
- role "name" [attribute=value]
* **role**: Specifies the ARIA or HTML role of the element (e.g., `heading`, `list`, `listitem`, `button`).
* **"name"**: Accessible name of the element. Quoted strings indicate exact values, `/patterns/` are used for regular expression.
* **\[attribute=value\]**: Attributes and values, in square brackets, represent specific ARIA attributes, such as `checked`, `disabled`, `expanded`, `level`, `pressed`, or `selected`.
These values are derived from ARIA attributes or calculated based on HTML semantics. To inspect the accessibility tree structure of a page, use the [Chrome DevTools Accessibility Tab](https://developer.chrome.com/docs/devtools/accessibility/reference#tab)
.
Snapshot matching[](https://playwright.dev/dotnet/docs/aria-snapshots#snapshot-matching "Direct link to Snapshot matching")
-----------------------------------------------------------------------------------------------------------------------------
The [Expect(Locator).ToMatchAriaSnapshotAsync()](https://playwright.dev/dotnet/docs/api/class-locatorassertions#locator-assertions-to-match-aria-snapshot)
assertion method in Playwright compares the accessible structure of the locator scope with a predefined aria snapshot template, helping validate the page's state against testing requirements.
For the following DOM:
title
You can match it using the following snapshot template:
await Expect(page.Locator("body")).ToMatchAriaSnapshotAsync(@" - heading ""title""");
When matching, the snapshot template is compared to the current accessibility tree of the page:
* If the tree structure matches the template, the test passes; otherwise, it fails, indicating a mismatch between expected and actual accessibility states.
* The comparison is case-sensitive and collapses whitespace, so indentation and line breaks are ignored.
* The comparison is order-sensitive, meaning the order of elements in the snapshot template must match the order in the page's accessibility tree.
### Partial matching[](https://playwright.dev/dotnet/docs/aria-snapshots#partial-matching "Direct link to Partial matching")
You can perform partial matches on nodes by omitting attributes or accessible names, enabling verification of specific parts of the accessibility tree without requiring exact matches. This flexibility is helpful for dynamic or irrelevant attributes.
_aria snapshot_
- button
In this example, the button role is matched, but the accessible name ("Submit") is not specified, allowing the test to pass regardless of the button's label.
* * *
For elements with ARIA attributes like `checked` or `disabled`, omitting these attributes allows partial matching, focusing solely on role and hierarchy.
_aria snapshot for partial match_
- checkbox
In this partial match, the `checked` attribute is ignored, so the test will pass regardless of the checkbox state.
* * *
Similarly, you can partially match children in lists or groups by omitting specific list items or nested elements.
Feature A
Feature B
Feature C
_aria snapshot for partial match_
- list - listitem: Feature B
Partial matches let you create flexible snapshot tests that verify essential page structure without enforcing specific content or attributes.
### Strict matching[](https://playwright.dev/dotnet/docs/aria-snapshots#strict-matching "Direct link to Strict matching")
By default, a template containing the subset of children will be matched:
Feature A
Feature B
Feature C
_aria snapshot for partial match_
- list - listitem: Feature B
The `/children` property can be used to control how child elements are matched:
* `contain` (default): Matches if all specified children are present in order
* `equal`: Matches if the children exactly match the specified list in order
* `deep-equal`: Matches if the children exactly match the specified list in order, including nested children
Feature A
Feature B
Feature C
_aria snapshot will fail due to Feature C not being in the template_
- list - /children: equal - listitem: Feature A - listitem: Feature B
### Matching with regular expressions[](https://playwright.dev/dotnet/docs/aria-snapshots#matching-with-regular-expressions "Direct link to Matching with regular expressions")
Regular expressions allow flexible matching for elements with dynamic or variable text. Accessible names and text can support regex patterns.
Issues 12
_aria snapshot with regular expression_
- heading /Issues \d+/
Generating snapshots[](https://playwright.dev/dotnet/docs/aria-snapshots#generating-snapshots "Direct link to Generating snapshots")
--------------------------------------------------------------------------------------------------------------------------------------
Creating aria snapshots in Playwright helps ensure and maintain your application's structure. You can generate snapshots in various ways depending on your testing setup and workflow.
### Generating snapshots with the Playwright code generator[](https://playwright.dev/dotnet/docs/aria-snapshots#generating-snapshots-with-the-playwright-code-generator "Direct link to Generating snapshots with the Playwright code generator")
If you're using Playwright's [Code Generator](https://playwright.dev/dotnet/docs/codegen)
, generating aria snapshots is streamlined with its interactive interface:
* **"Assert snapshot" Action**: In the code generator, you can use the "Assert snapshot" action to automatically create a snapshot assertion for the selected elements. This is a quick way to capture the aria snapshot as part of your recorded test flow.
* **"Aria snapshot" Tab**: The "Aria snapshot" tab within the code generator interface visually represents the aria snapshot for a selected locator, letting you explore, inspect, and verify element roles, attributes, and accessible names to aid snapshot creation and review.
### Using the `Locator.ariaSnapshot` method[](https://playwright.dev/dotnet/docs/aria-snapshots#using-the-locatorariasnapshot-method "Direct link to using-the-locatorariasnapshot-method")
The [Locator.AriaSnapshotAsync()](https://playwright.dev/dotnet/docs/api/class-locator#locator-aria-snapshot)
method allows you to programmatically create a YAML representation of accessible elements within a locator's scope, especially helpful for generating snapshots dynamically during test execution.
**Example**:
var snapshot = await page.Locator("body").AriaSnapshotAsync();Console.WriteLine(snapshot);
This command outputs the aria snapshot within the specified locator's scope in YAML format, which you can validate or store as needed.
Accessibility tree examples[](https://playwright.dev/dotnet/docs/aria-snapshots#accessibility-tree-examples "Direct link to Accessibility tree examples")
-----------------------------------------------------------------------------------------------------------------------------------------------------------
### Headings with level attributes[](https://playwright.dev/dotnet/docs/aria-snapshots#headings-with-level-attributes "Direct link to Headings with level attributes")
Headings can include a `level` attribute indicating their heading level.
Title
Subtitle
_aria snapshot_
- heading "Title" [level=1]- heading "Subtitle" [level=2]
### Text nodes[](https://playwright.dev/dotnet/docs/aria-snapshots#text-nodes "Direct link to Text nodes")
Standalone or descriptive text elements appear as text nodes.
Sample accessible name
_aria snapshot_
- text: Sample accessible name
### Inline multiline text[](https://playwright.dev/dotnet/docs/aria-snapshots#inline-multiline-text "Direct link to Inline multiline text")
Multiline text, such as paragraphs, is normalized in the aria snapshot.
Line 1 Line 2
_aria snapshot_
- paragraph: Line 1 Line 2
### Links[](https://playwright.dev/dotnet/docs/aria-snapshots#links "Direct link to Links")
Links display their text or composed content from pseudo-elements.
Read more about Accessibility
_aria snapshot_
- link "Read more about Accessibility"
### Text boxes[](https://playwright.dev/dotnet/docs/aria-snapshots#text-boxes "Direct link to Text boxes")
Input elements of type `text` show their `value` attribute content.
_aria snapshot_
- textbox: Enter your name
### Lists with items[](https://playwright.dev/dotnet/docs/aria-snapshots#lists-with-items "Direct link to Lists with items")
Ordered and unordered lists include their list items.
Feature 1
Feature 2
_aria snapshot_
- list "Main Features": - listitem: Feature 1 - listitem: Feature 2
### Grouped elements[](https://playwright.dev/dotnet/docs/aria-snapshots#grouped-elements "Direct link to Grouped elements")
Groups capture nested elements, such as `` elements with summary content.
Summary
Detail content here
_aria snapshot_
- group: Summary
### Attributes and states[](https://playwright.dev/dotnet/docs/aria-snapshots#attributes-and-states "Direct link to Attributes and states")
Commonly used ARIA attributes, like `checked`, `disabled`, `expanded`, `level`, `pressed`, and `selected`, represent control states.
#### Checkbox with `checked` attribute[](https://playwright.dev/dotnet/docs/aria-snapshots#checkbox-with-checked-attribute "Direct link to checkbox-with-checked-attribute")
_aria snapshot_
- checkbox [checked]
#### Button with `pressed` attribute[](https://playwright.dev/dotnet/docs/aria-snapshots#button-with-pressed-attribute "Direct link to button-with-pressed-attribute")
_aria snapshot_
- button "Toggle" [pressed=true]
* [Overview](https://playwright.dev/dotnet/docs/aria-snapshots#overview)
* [Assertion testing vs Snapshot testing](https://playwright.dev/dotnet/docs/aria-snapshots#assertion-testing-vs-snapshot-testing)
* [Assertion testing](https://playwright.dev/dotnet/docs/aria-snapshots#assertion-testing)
* [Snapshot testing](https://playwright.dev/dotnet/docs/aria-snapshots#snapshot-testing)
* [When to use](https://playwright.dev/dotnet/docs/aria-snapshots#when-to-use)
* [Aria snapshots](https://playwright.dev/dotnet/docs/aria-snapshots#aria-snapshots)
* [Snapshot matching](https://playwright.dev/dotnet/docs/aria-snapshots#snapshot-matching)
* [Partial matching](https://playwright.dev/dotnet/docs/aria-snapshots#partial-matching)
* [Strict matching](https://playwright.dev/dotnet/docs/aria-snapshots#strict-matching)
* [Matching with regular expressions](https://playwright.dev/dotnet/docs/aria-snapshots#matching-with-regular-expressions)
* [Generating snapshots](https://playwright.dev/dotnet/docs/aria-snapshots#generating-snapshots)
* [Generating snapshots with the Playwright code generator](https://playwright.dev/dotnet/docs/aria-snapshots#generating-snapshots-with-the-playwright-code-generator)
* [Using the `Locator.ariaSnapshot` method](https://playwright.dev/dotnet/docs/aria-snapshots#using-the-locatorariasnapshot-method)
* [Accessibility tree examples](https://playwright.dev/dotnet/docs/aria-snapshots#accessibility-tree-examples)
* [Headings with level attributes](https://playwright.dev/dotnet/docs/aria-snapshots#headings-with-level-attributes)
* [Text nodes](https://playwright.dev/dotnet/docs/aria-snapshots#text-nodes)
* [Inline multiline text](https://playwright.dev/dotnet/docs/aria-snapshots#inline-multiline-text)
* [Links](https://playwright.dev/dotnet/docs/aria-snapshots#links)
* [Text boxes](https://playwright.dev/dotnet/docs/aria-snapshots#text-boxes)
* [Lists with items](https://playwright.dev/dotnet/docs/aria-snapshots#lists-with-items)
* [Grouped elements](https://playwright.dev/dotnet/docs/aria-snapshots#grouped-elements)
* [Attributes and states](https://playwright.dev/dotnet/docs/aria-snapshots#attributes-and-states)
---
# Clock | Playwright .NET
[Skip to main content](https://playwright.dev/dotnet/docs/api/class-clock#__docusaurus_skipToContent_fallback)
On this page
Accurately simulating time-dependent behavior is essential for verifying the correctness of applications. Learn more about [clock emulation](https://playwright.dev/dotnet/docs/clock)
.
Note that clock is installed for the entire [BrowserContext](https://playwright.dev/dotnet/docs/api/class-browsercontext "BrowserContext")
, so the time in all the pages and iframes is controlled by the same clock.
* * *
Methods[](https://playwright.dev/dotnet/docs/api/class-clock#methods "Direct link to Methods")
------------------------------------------------------------------------------------------------
### FastForwardAsync[](https://playwright.dev/dotnet/docs/api/class-clock#clock-fast-forward "Direct link to FastForwardAsync")
Added in: v1.45 clock.FastForwardAsync
Advance the clock by jumping forward in time. Only fires due timers at most once. This is equivalent to user closing the laptop lid for a while and reopening it later, after given time.
**Usage**
await page.Clock.FastForwardAsync(1000);await page.Clock.FastForwardAsync("30:00");
**Arguments**
* `ticks` [long](https://docs.microsoft.com/en-us/dotnet/api/system.int64 "long")
| [string](https://docs.microsoft.com/en-us/dotnet/api/system.string "string")
[#](https://playwright.dev/dotnet/docs/api/class-clock#clock-fast-forward-option-ticks)
Time may be the number of milliseconds to advance the clock by or a human-readable string. Valid string formats are "08" for eight seconds, "01:00" for one minute and "02:34:10" for two hours, 34 minutes and ten seconds.
**Returns**
* [void](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/void "void")
[#](https://playwright.dev/dotnet/docs/api/class-clock#clock-fast-forward-return)
* * *
### InstallAsync[](https://playwright.dev/dotnet/docs/api/class-clock#clock-install "Direct link to InstallAsync")
Added in: v1.45 clock.InstallAsync
Install fake implementations for the following time-related functions:
* `Date`
* `setTimeout`
* `clearTimeout`
* `setInterval`
* `clearInterval`
* `requestAnimationFrame`
* `cancelAnimationFrame`
* `requestIdleCallback`
* `cancelIdleCallback`
* `performance`
Fake timers are used to manually control the flow of time in tests. They allow you to advance time, fire timers, and control the behavior of time-dependent functions. See [Clock.RunForAsync()](https://playwright.dev/dotnet/docs/api/class-clock#clock-run-for)
and [Clock.FastForwardAsync()](https://playwright.dev/dotnet/docs/api/class-clock#clock-fast-forward)
for more information.
**Usage**
await Clock.InstallAsync(options);
**Arguments**
* `options` `ClockInstallOptions?` _(optional)_
* `Time|TimeDate` [string](https://docs.microsoft.com/en-us/dotnet/api/system.string "string")
? | [Date](https://learn.microsoft.com/en-us/dotnet/api/system.datetime "DateTime")
? _(optional)_[#](https://playwright.dev/dotnet/docs/api/class-clock#clock-install-option-time)
Time to initialize with, current system time by default.
**Returns**
* [void](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/void "void")
[#](https://playwright.dev/dotnet/docs/api/class-clock#clock-install-return)
* * *
### PauseAtAsync[](https://playwright.dev/dotnet/docs/api/class-clock#clock-pause-at "Direct link to PauseAtAsync")
Added in: v1.45 clock.PauseAtAsync
Advance the clock by jumping forward in time and pause the time. Once this method is called, no timers are fired unless [Clock.RunForAsync()](https://playwright.dev/dotnet/docs/api/class-clock#clock-run-for)
, [Clock.FastForwardAsync()](https://playwright.dev/dotnet/docs/api/class-clock#clock-fast-forward)
, [Clock.PauseAtAsync()](https://playwright.dev/dotnet/docs/api/class-clock#clock-pause-at)
or [Clock.ResumeAsync()](https://playwright.dev/dotnet/docs/api/class-clock#clock-resume)
is called.
Only fires due timers at most once. This is equivalent to user closing the laptop lid for a while and reopening it at the specified time and pausing.
**Usage**
await page.Clock.PauseAtAsync(DateTime.Parse("2020-02-02"));await page.Clock.PauseAtAsync("2020-02-02");
For best results, install the clock before navigating the page and set it to a time slightly before the intended test time. This ensures that all timers run normally during page loading, preventing the page from getting stuck. Once the page has fully loaded, you can safely use [Clock.PauseAtAsync()](https://playwright.dev/dotnet/docs/api/class-clock#clock-pause-at)
to pause the clock.
**Arguments**
* `time` [Date](https://learn.microsoft.com/en-us/dotnet/api/system.datetime "DateTime")
| [string](https://docs.microsoft.com/en-us/dotnet/api/system.string "string")
[#](https://playwright.dev/dotnet/docs/api/class-clock#clock-pause-at-option-time)
Time to pause at.
**Returns**
* [void](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/void "void")
[#](https://playwright.dev/dotnet/docs/api/class-clock#clock-pause-at-return)
* * *
### ResumeAsync[](https://playwright.dev/dotnet/docs/api/class-clock#clock-resume "Direct link to ResumeAsync")
Added in: v1.45 clock.ResumeAsync
Resumes timers. Once this method is called, time resumes flowing, timers are fired as usual.
**Usage**
await Clock.ResumeAsync();
**Returns**
* [void](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/void "void")
[#](https://playwright.dev/dotnet/docs/api/class-clock#clock-resume-return)
* * *
### RunForAsync[](https://playwright.dev/dotnet/docs/api/class-clock#clock-run-for "Direct link to RunForAsync")
Added in: v1.45 clock.RunForAsync
Advance the clock, firing all the time-related callbacks.
**Usage**
await page.Clock.RunForAsync(1000);await page.Clock.RunForAsync("30:00");
**Arguments**
* `ticks` [long](https://docs.microsoft.com/en-us/dotnet/api/system.int64 "long")
| [string](https://docs.microsoft.com/en-us/dotnet/api/system.string "string")
[#](https://playwright.dev/dotnet/docs/api/class-clock#clock-run-for-option-ticks)
Time may be the number of milliseconds to advance the clock by or a human-readable string. Valid string formats are "08" for eight seconds, "01:00" for one minute and "02:34:10" for two hours, 34 minutes and ten seconds.
**Returns**
* [void](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/void "void")
[#](https://playwright.dev/dotnet/docs/api/class-clock#clock-run-for-return)
* * *
### SetFixedTimeAsync[](https://playwright.dev/dotnet/docs/api/class-clock#clock-set-fixed-time "Direct link to SetFixedTimeAsync")
Added in: v1.45 clock.SetFixedTimeAsync
Makes `Date.now` and `new Date()` return fixed fake time at all times, keeps all the timers running.
Use this method for simple scenarios where you only need to test with a predefined time. For more advanced scenarios, use [Clock.InstallAsync()](https://playwright.dev/dotnet/docs/api/class-clock#clock-install)
instead. Read docs on [clock emulation](https://playwright.dev/dotnet/docs/clock)
to learn more.
**Usage**
await page.Clock.SetFixedTimeAsync(DateTime.Now);await page.Clock.SetFixedTimeAsync(new DateTime(2020, 2, 2));await page.Clock.SetFixedTimeAsync("2020-02-02");
**Arguments**
* `time` [string](https://docs.microsoft.com/en-us/dotnet/api/system.string "string")
| [Date](https://learn.microsoft.com/en-us/dotnet/api/system.datetime "DateTime")
[#](https://playwright.dev/dotnet/docs/api/class-clock#clock-set-fixed-time-option-time)
Time to be set.
**Returns**
* [void](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/void "void")
[#](https://playwright.dev/dotnet/docs/api/class-clock#clock-set-fixed-time-return)
* * *
### SetSystemTimeAsync[](https://playwright.dev/dotnet/docs/api/class-clock#clock-set-system-time "Direct link to SetSystemTimeAsync")
Added in: v1.45 clock.SetSystemTimeAsync
Sets system time, but does not trigger any timers. Use this to test how the web page reacts to a time shift, for example switching from summer to winter time, or changing time zones.
**Usage**
await page.Clock.SetSystemTimeAsync(DateTime.Now);await page.Clock.SetSystemTimeAsync(new DateTime(2020, 2, 2));await page.Clock.SetSystemTimeAsync("2020-02-02");
**Arguments**
* `time` [string](https://docs.microsoft.com/en-us/dotnet/api/system.string "string")
| [Date](https://learn.microsoft.com/en-us/dotnet/api/system.datetime "DateTime")
[#](https://playwright.dev/dotnet/docs/api/class-clock#clock-set-system-time-option-time)
Time to be set.
**Returns**
* [void](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/void "void")
[#](https://playwright.dev/dotnet/docs/api/class-clock#clock-set-system-time-return)
* [Methods](https://playwright.dev/dotnet/docs/api/class-clock#methods)
* [FastForwardAsync](https://playwright.dev/dotnet/docs/api/class-clock#clock-fast-forward)
* [InstallAsync](https://playwright.dev/dotnet/docs/api/class-clock#clock-install)
* [PauseAtAsync](https://playwright.dev/dotnet/docs/api/class-clock#clock-pause-at)
* [ResumeAsync](https://playwright.dev/dotnet/docs/api/class-clock#clock-resume)
* [RunForAsync](https://playwright.dev/dotnet/docs/api/class-clock#clock-run-for)
* [SetFixedTimeAsync](https://playwright.dev/dotnet/docs/api/class-clock#clock-set-fixed-time)
* [SetSystemTimeAsync](https://playwright.dev/dotnet/docs/api/class-clock#clock-set-system-time)
---
# Mouse | Playwright Java
[Skip to main content](https://playwright.dev/java/docs/api/class-mouse#__docusaurus_skipToContent_fallback)
On this page
The Mouse class operates in main-frame CSS pixels relative to the top-left corner of the viewport.
tip
If you want to debug where the mouse moved, you can use the [Trace viewer](https://playwright.dev/java/docs/trace-viewer-intro)
or [Playwright Inspector](https://playwright.dev/java/docs/running-tests)
. A red dot showing the location of the mouse will be shown for every mouse action.
Every `page` object has its own Mouse, accessible with [Page.mouse()](https://playwright.dev/java/docs/api/class-page#page-mouse)
.
// Using ‘page.mouse’ to trace a 100x100 square.page.mouse().move(0, 0);page.mouse().down();page.mouse().move(0, 100);page.mouse().move(100, 100);page.mouse().move(100, 0);page.mouse().move(0, 0);page.mouse().up();
* * *
Methods[](https://playwright.dev/java/docs/api/class-mouse#methods "Direct link to Methods")
----------------------------------------------------------------------------------------------
### click[](https://playwright.dev/java/docs/api/class-mouse#mouse-click "Direct link to click")
Added before v1.9 mouse.click
Shortcut for [Mouse.move()](https://playwright.dev/java/docs/api/class-mouse#mouse-move)
, [Mouse.down()](https://playwright.dev/java/docs/api/class-mouse#mouse-down)
, [Mouse.up()](https://playwright.dev/java/docs/api/class-mouse#mouse-up)
.
**Usage**
Mouse.click(x, y);Mouse.click(x, y, options);
**Arguments**
* `x` [double](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html "double")
[#](https://playwright.dev/java/docs/api/class-mouse#mouse-click-option-x)
X coordinate relative to the main frame's viewport in CSS pixels.
* `y` [double](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html "double")
[#](https://playwright.dev/java/docs/api/class-mouse#mouse-click-option-y)
Y coordinate relative to the main frame's viewport in CSS pixels.
* `options` `Mouse.ClickOptions` _(optional)_
* `setButton` `enum MouseButton { LEFT, RIGHT, MIDDLE }` _(optional)_[#](https://playwright.dev/java/docs/api/class-mouse#mouse-click-option-button)
Defaults to `left`.
* `setClickCount` [int](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html "int")
_(optional)_[#](https://playwright.dev/java/docs/api/class-mouse#mouse-click-option-click-count)
defaults to 1. See [UIEvent.detail](https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/detail "UIEvent.detail")
.
* `setDelay` [double](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html "double")
_(optional)_[#](https://playwright.dev/java/docs/api/class-mouse#mouse-click-option-delay)
Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0.
**Returns**
* [void](https://docs.oracle.com/javase/tutorial/java/javaOO/methods.html "void")
[#](https://playwright.dev/java/docs/api/class-mouse#mouse-click-return)
* * *
### dblclick[](https://playwright.dev/java/docs/api/class-mouse#mouse-dblclick "Direct link to dblclick")
Added before v1.9 mouse.dblclick
Shortcut for [Mouse.move()](https://playwright.dev/java/docs/api/class-mouse#mouse-move)
, [Mouse.down()](https://playwright.dev/java/docs/api/class-mouse#mouse-down)
, [Mouse.up()](https://playwright.dev/java/docs/api/class-mouse#mouse-up)
, [Mouse.down()](https://playwright.dev/java/docs/api/class-mouse#mouse-down)
and [Mouse.up()](https://playwright.dev/java/docs/api/class-mouse#mouse-up)
.
**Usage**
Mouse.dblclick(x, y);Mouse.dblclick(x, y, options);
**Arguments**
* `x` [double](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html "double")
[#](https://playwright.dev/java/docs/api/class-mouse#mouse-dblclick-option-x)
X coordinate relative to the main frame's viewport in CSS pixels.
* `y` [double](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html "double")
[#](https://playwright.dev/java/docs/api/class-mouse#mouse-dblclick-option-y)
Y coordinate relative to the main frame's viewport in CSS pixels.
* `options` `Mouse.DblclickOptions` _(optional)_
* `setButton` `enum MouseButton { LEFT, RIGHT, MIDDLE }` _(optional)_[#](https://playwright.dev/java/docs/api/class-mouse#mouse-dblclick-option-button)
Defaults to `left`.
* `setDelay` [double](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html "double")
_(optional)_[#](https://playwright.dev/java/docs/api/class-mouse#mouse-dblclick-option-delay)
Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0.
**Returns**
* [void](https://docs.oracle.com/javase/tutorial/java/javaOO/methods.html "void")
[#](https://playwright.dev/java/docs/api/class-mouse#mouse-dblclick-return)
* * *
### down[](https://playwright.dev/java/docs/api/class-mouse#mouse-down "Direct link to down")
Added before v1.9 mouse.down
Dispatches a `mousedown` event.
**Usage**
Mouse.down();Mouse.down(options);
**Arguments**
* `options` `Mouse.DownOptions` _(optional)_
* `setButton` `enum MouseButton { LEFT, RIGHT, MIDDLE }` _(optional)_[#](https://playwright.dev/java/docs/api/class-mouse#mouse-down-option-button)
Defaults to `left`.
* `setClickCount` [int](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html "int")
_(optional)_[#](https://playwright.dev/java/docs/api/class-mouse#mouse-down-option-click-count)
defaults to 1. See [UIEvent.detail](https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/detail "UIEvent.detail")
.
**Returns**
* [void](https://docs.oracle.com/javase/tutorial/java/javaOO/methods.html "void")
[#](https://playwright.dev/java/docs/api/class-mouse#mouse-down-return)
* * *
### move[](https://playwright.dev/java/docs/api/class-mouse#mouse-move "Direct link to move")
Added before v1.9 mouse.move
Dispatches a `mousemove` event.
**Usage**
Mouse.move(x, y);Mouse.move(x, y, options);
**Arguments**
* `x` [double](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html "double")
[#](https://playwright.dev/java/docs/api/class-mouse#mouse-move-option-x)
X coordinate relative to the main frame's viewport in CSS pixels.
* `y` [double](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html "double")
[#](https://playwright.dev/java/docs/api/class-mouse#mouse-move-option-y)
Y coordinate relative to the main frame's viewport in CSS pixels.
* `options` `Mouse.MoveOptions` _(optional)_
* `setSteps` [int](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html "int")
_(optional)_[#](https://playwright.dev/java/docs/api/class-mouse#mouse-move-option-steps)
Defaults to 1. Sends intermediate `mousemove` events.
**Returns**
* [void](https://docs.oracle.com/javase/tutorial/java/javaOO/methods.html "void")
[#](https://playwright.dev/java/docs/api/class-mouse#mouse-move-return)
* * *
### up[](https://playwright.dev/java/docs/api/class-mouse#mouse-up "Direct link to up")
Added before v1.9 mouse.up
Dispatches a `mouseup` event.
**Usage**
Mouse.up();Mouse.up(options);
**Arguments**
* `options` `Mouse.UpOptions` _(optional)_
* `setButton` `enum MouseButton { LEFT, RIGHT, MIDDLE }` _(optional)_[#](https://playwright.dev/java/docs/api/class-mouse#mouse-up-option-button)
Defaults to `left`.
* `setClickCount` [int](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html "int")
_(optional)_[#](https://playwright.dev/java/docs/api/class-mouse#mouse-up-option-click-count)
defaults to 1. See [UIEvent.detail](https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/detail "UIEvent.detail")
.
**Returns**
* [void](https://docs.oracle.com/javase/tutorial/java/javaOO/methods.html "void")
[#](https://playwright.dev/java/docs/api/class-mouse#mouse-up-return)
* * *
### wheel[](https://playwright.dev/java/docs/api/class-mouse#mouse-wheel "Direct link to wheel")
Added in: v1.15 mouse.wheel
Dispatches a `wheel` event. This method is usually used to manually scroll the page. See [scrolling](https://playwright.dev/java/docs/input#scrolling)
for alternative ways to scroll.
note
Wheel events may cause scrolling if they are not handled, and this method does not wait for the scrolling to finish before returning.
**Usage**
Mouse.wheel(deltaX, deltaY);
**Arguments**
* `deltaX` [double](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html "double")
[#](https://playwright.dev/java/docs/api/class-mouse#mouse-wheel-option-delta-x)
Pixels to scroll horizontally.
* `deltaY` [double](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html "double")
[#](https://playwright.dev/java/docs/api/class-mouse#mouse-wheel-option-delta-y)
Pixels to scroll vertically.
**Returns**
* [void](https://docs.oracle.com/javase/tutorial/java/javaOO/methods.html "void")
[#](https://playwright.dev/java/docs/api/class-mouse#mouse-wheel-return)
* [Methods](https://playwright.dev/java/docs/api/class-mouse#methods)
* [click](https://playwright.dev/java/docs/api/class-mouse#mouse-click)
* [dblclick](https://playwright.dev/java/docs/api/class-mouse#mouse-dblclick)
* [down](https://playwright.dev/java/docs/api/class-mouse#mouse-down)
* [move](https://playwright.dev/java/docs/api/class-mouse#mouse-move)
* [up](https://playwright.dev/java/docs/api/class-mouse#mouse-up)
* [wheel](https://playwright.dev/java/docs/api/class-mouse#mouse-wheel)
---
# WebError | Playwright .NET
[Skip to main content](https://playwright.dev/dotnet/docs/api/class-weberror#__docusaurus_skipToContent_fallback)
On this page
[WebError](https://playwright.dev/dotnet/docs/api/class-weberror "WebError")
class represents an unhandled exception thrown in the page. It is dispatched via the [BrowserContext.WebError](https://playwright.dev/dotnet/docs/api/class-browsercontext#browser-context-event-web-error)
event.
// Log all uncaught errors to the terminalcontext.WebError += (_, webError) =>{ Console.WriteLine("Uncaught exception: " + webError.Error);};
* * *
Methods[](https://playwright.dev/dotnet/docs/api/class-weberror#methods "Direct link to Methods")
---------------------------------------------------------------------------------------------------
### Error[](https://playwright.dev/dotnet/docs/api/class-weberror#web-error-error "Direct link to Error")
Added in: v1.38 webError.Error
Unhandled error that was thrown.
**Usage**
WebError.Error
**Returns**
* [string](https://docs.microsoft.com/en-us/dotnet/api/system.string "string")
[#](https://playwright.dev/dotnet/docs/api/class-weberror#web-error-error-return)
* * *
### Page[](https://playwright.dev/dotnet/docs/api/class-weberror#web-error-page "Direct link to Page")
Added in: v1.38 webError.Page
The page that produced this unhandled exception, if any.
**Usage**
WebError.Page
**Returns**
* [Page](https://playwright.dev/dotnet/docs/api/class-page "Page")
?[#](https://playwright.dev/dotnet/docs/api/class-weberror#web-error-page-return)
* [Methods](https://playwright.dev/dotnet/docs/api/class-weberror#methods)
* [Error](https://playwright.dev/dotnet/docs/api/class-weberror#web-error-error)
* [Page](https://playwright.dev/dotnet/docs/api/class-weberror#web-error-page)
---
# Running and debugging tests | Playwright .NET
[Skip to main content](https://playwright.dev/dotnet/docs/running-tests#__docusaurus_skipToContent_fallback)
On this page
Introduction[](https://playwright.dev/dotnet/docs/running-tests#introduction "Direct link to Introduction")
-------------------------------------------------------------------------------------------------------------
You can run a single test, a set of tests or all tests. Tests can be run on different browsers. By default, tests are run in a headless manner, meaning no browser window will be opened while running the tests and results will be seen in the terminal. If you prefer, you can run your tests in headed mode by using the `headless` test run parameter.
**You will learn**
* [How to run tests](https://playwright.dev/dotnet/docs/running-tests#running-tests)
* [How to debug tests](https://playwright.dev/dotnet/docs/running-tests#debugging-tests)
Running tests[](https://playwright.dev/dotnet/docs/running-tests#running-tests "Direct link to Running tests")
----------------------------------------------------------------------------------------------------------------
### Run all tests[](https://playwright.dev/dotnet/docs/running-tests#run-all-tests "Direct link to Run all tests")
Use the following command to run all tests.
dotnet test
### Run tests in headed mode[](https://playwright.dev/dotnet/docs/running-tests#run-tests-in-headed-mode "Direct link to Run tests in headed mode")
Use the following command to run your tests in headed mode opening a browser window for each test.
* Bash
* PowerShell
* Batch
HEADED=1 dotnet test
$env:HEADED="1"dotnet test
set HEADED=1dotnet test
### Run tests on different browsers: Browser env[](https://playwright.dev/dotnet/docs/running-tests#run-tests-on-different-browsers-browser-env "Direct link to Run tests on different browsers: Browser env")
Specify which browser you would like to run your tests on via the `BROWSER` environment variable.
* Bash
* PowerShell
* Batch
BROWSER=webkit dotnet test
$env:BROWSER="webkit"dotnet test
set BROWSER=webkitdotnet test
### Run tests on different browsers: launch configuration[](https://playwright.dev/dotnet/docs/running-tests#run-tests-on-different-browsers-launch-configuration "Direct link to Run tests on different browsers: launch configuration")
Specify which browser you would like to run your tests on by adjusting the launch configuration options:
dotnet test -- Playwright.BrowserName=webkit
To run your test on multiple browsers or configurations, you need to invoke the `dotnet test` command multiple times. There you can then either specify the `BROWSER` environment variable or set the `Playwright.BrowserName` via the runsettings file:
dotnet test --settings:chromium.runsettingsdotnet test --settings:firefox.runsettingsdotnet test --settings:webkit.runsettings
chromium
For more information see [selective unit tests](https://docs.microsoft.com/en-us/dotnet/core/testing/selective-unit-tests?pivots=mstest)
in the Microsoft docs.
### Run specific tests[](https://playwright.dev/dotnet/docs/running-tests#run-specific-tests "Direct link to Run specific tests")
To run a single test file, use the filter flag followed by the class name of the test you want to run.
dotnet test --filter "ExampleTest"
To run a set of test files, use the filter flag followed by the class names of the tests you want to run.
dotnet test --filter "ExampleTest1|ExampleTest2"
To run a test with a specific title use the filter flag followed by _Name~_ and the title of the test.
dotnet test --filter "Name~GetStartedLink"
### Run tests with multiple workers:[](https://playwright.dev/dotnet/docs/running-tests#run-tests-with-multiple-workers "Direct link to Run tests with multiple workers:")
* MSTest
* NUnit
* xUnit
* xUnit v3
dotnet test -- NUnit.NumberOfTestWorkers=5
dotnet test -- MSTest.Parallelize.Workers=5
dotnet test -- xUnit.MaxParallelThreads=5
See [here](https://xunit.net/docs/running-tests-in-parallel.html)
for more information to run tests in parallel with xUnit.
note
We recommend xUnit 2.8+ which uses the [`conservative` parallelism algorithm](https://xunit.net/docs/running-tests-in-parallel.html#algorithms)
by default.
dotnet test -- xUnit.MaxParallelThreads=5
See [here](https://xunit.net/docs/running-tests-in-parallel.html)
for more information to run tests in parallel with xUnit v3.
note
xUnit v3 uses the [`conservative` parallelism algorithm](https://xunit.net/docs/running-tests-in-parallel.html#algorithms)
by default.
Debugging Tests[](https://playwright.dev/dotnet/docs/running-tests#debugging-tests "Direct link to Debugging Tests")
----------------------------------------------------------------------------------------------------------------------
Since Playwright runs in .NET, you can debug it with your debugger of choice in e.g. Visual Studio Code or Visual Studio. Playwright comes with the Playwright Inspector which allows you to step through Playwright API calls, see their debug logs and explore [locators](https://playwright.dev/dotnet/docs/locators)
.
* Bash
* PowerShell
* Batch
PWDEBUG=1 dotnet test
$env:PWDEBUG=1dotnet test
set PWDEBUG=1dotnet test

Check out our [debugging guide](https://playwright.dev/dotnet/docs/debug)
to learn more about the [Playwright Inspector](https://playwright.dev/dotnet/docs/debug#playwright-inspector)
as well as debugging with [Browser Developer tools](https://playwright.dev/dotnet/docs/debug#browser-developer-tools)
.
What's Next[](https://playwright.dev/dotnet/docs/running-tests#whats-next "Direct link to What's Next")
---------------------------------------------------------------------------------------------------------
* [Generate tests with Codegen](https://playwright.dev/dotnet/docs/codegen-intro)
* [See a trace of your tests](https://playwright.dev/dotnet/docs/trace-viewer-intro)
* [Run tests on CI](https://playwright.dev/dotnet/docs/ci-intro)
* [Learn more about the MSTest, NUnit, xUnit and xUnit v3 base classes](https://playwright.dev/dotnet/docs/test-runners)
* [Introduction](https://playwright.dev/dotnet/docs/running-tests#introduction)
* [Running tests](https://playwright.dev/dotnet/docs/running-tests#running-tests)
* [Run all tests](https://playwright.dev/dotnet/docs/running-tests#run-all-tests)
* [Run tests in headed mode](https://playwright.dev/dotnet/docs/running-tests#run-tests-in-headed-mode)
* [Run tests on different browsers: Browser env](https://playwright.dev/dotnet/docs/running-tests#run-tests-on-different-browsers-browser-env)
* [Run tests on different browsers: launch configuration](https://playwright.dev/dotnet/docs/running-tests#run-tests-on-different-browsers-launch-configuration)
* [Run specific tests](https://playwright.dev/dotnet/docs/running-tests#run-specific-tests)
* [Run tests with multiple workers:](https://playwright.dev/dotnet/docs/running-tests#run-tests-with-multiple-workers)
* [Debugging Tests](https://playwright.dev/dotnet/docs/running-tests#debugging-tests)
* [What's Next](https://playwright.dev/dotnet/docs/running-tests#whats-next)
---
# Debugging Tests | Playwright .NET
[Skip to main content](https://playwright.dev/dotnet/docs/debug#__docusaurus_skipToContent_fallback)
On this page
Playwright Inspector[](https://playwright.dev/dotnet/docs/debug#playwright-inspector "Direct link to Playwright Inspector")
-----------------------------------------------------------------------------------------------------------------------------
The Playwright Inspector is a GUI tool to help you debug your Playwright tests. It allows you to step through your tests, live edit locators, pick locators and see actionability logs.

### Run in debug mode[](https://playwright.dev/dotnet/docs/debug#run-in-debug-mode "Direct link to Run in debug mode")
Set the `PWDEBUG` environment variable to run your Playwright tests in debug mode. This configures Playwright for debugging and opens the inspector. Additional useful defaults are configured when `PWDEBUG=1` is set:
* Browsers launch in headed mode
* Default timeout is set to 0 (= no timeout)
* Bash
* PowerShell
* Batch
PWDEBUG=1 dotnet test
$env:PWDEBUG=1dotnet test
set PWDEBUG=1dotnet test
### Stepping through your tests[](https://playwright.dev/dotnet/docs/debug#stepping-through-your-tests "Direct link to Stepping through your tests")
You can play, pause or step through each action of your test using the toolbar at the top of the Inspector. You can see the current action highlighted in the test code, and matching elements highlighted in the browser window.

### Run a test from a specific breakpoint[](https://playwright.dev/dotnet/docs/debug#run-a-test-from-a-specific-breakpoint "Direct link to Run a test from a specific breakpoint")
To speed up the debugging process you can add a [Page.PauseAsync()](https://playwright.dev/dotnet/docs/api/class-page#page-pause)
method to your test. This way you won't have to step through each action of your test to get to the point where you want to debug.
await page.PauseAsync();
Once you add a `page.pause()` call, run your tests in debug mode. Clicking the "Resume" button in the Inspector will run the test and only stop on the `page.pause()`.

### Live editing locators[](https://playwright.dev/dotnet/docs/debug#live-editing-locators "Direct link to Live editing locators")
While running in debug mode you can live edit the locators. Next to the 'Pick Locator' button there is a field showing the [locator](https://playwright.dev/dotnet/docs/locators)
that the test is paused on. You can edit this locator directly in the **Pick Locator** field, and matching elements will be highlighted in the browser window.

### Picking locators[](https://playwright.dev/dotnet/docs/debug#picking-locators "Direct link to Picking locators")
While debugging, you might need to choose a more resilient locator. You can do this by clicking on the **Pick Locator** button and hovering over any element in the browser window. While hovering over an element you will see the code needed to locate this element highlighted below. Clicking an element in the browser will add the locator into the field where you can then either tweak it or copy it into your code.

Playwright will look at your page and figure out the best locator, prioritizing [role, text and test id locators](https://playwright.dev/dotnet/docs/locators)
. If Playwright finds multiple elements matching the locator, it will improve the locator to make it resilient and uniquely identify the target element, so you don't have to worry about failing tests due to locators.
### Actionability logs[](https://playwright.dev/dotnet/docs/debug#actionability-logs "Direct link to Actionability logs")
By the time Playwright has paused on a click action, it has already performed [actionability checks](https://playwright.dev/dotnet/docs/actionability)
that can be found in the log. This can help you understand what happened during your test and what Playwright did or tried to do. The log tells you if the element was visible, enabled and stable, if the locator resolved to an element, scrolled into view, and so much more. If actionability can't be reached, it will show the action as pending.

Trace Viewer[](https://playwright.dev/dotnet/docs/debug#trace-viewer "Direct link to Trace Viewer")
-----------------------------------------------------------------------------------------------------
Playwright [Trace Viewer](https://playwright.dev/dotnet/docs/trace-viewer)
is a GUI tool that lets you explore recorded Playwright traces of your tests. You can go back and forward through each action on the left side, and visually see what was happening during the action. In the middle of the screen, you can see a DOM snapshot for the action. On the right side you can see action details, such as time, parameters, return value and log. You can also explore console messages, network requests and the source code.
To learn more about how to record traces and use the Trace Viewer, check out the [Trace Viewer](https://playwright.dev/dotnet/docs/trace-viewer)
guide.
Browser Developer Tools[](https://playwright.dev/dotnet/docs/debug#browser-developer-tools "Direct link to Browser Developer Tools")
--------------------------------------------------------------------------------------------------------------------------------------
When running in Debug Mode with `PWDEBUG=console`, a `playwright` object is available in the Developer tools console. Developer tools can help you to:
* Inspect the DOM tree and **find element selectors**
* **See console logs** during execution (or learn how to [read logs via API](https://playwright.dev/dotnet/docs/api/class-page#page-event-console)
)
* Check **network activity** and other developer tools features
This will also set the default timeouts of Playwright to 0 (= no timeout).

To debug your tests using the browser developer tools, start by setting a breakpoint in your test to pause the execution using the [Page.PauseAsync()](https://playwright.dev/dotnet/docs/api/class-page#page-pause)
method.
await page.PauseAsync();
Once you have set a breakpoint in your test, you can then run your test with `PWDEBUG=console`.
* Bash
* PowerShell
* Batch
PWDEBUG=console dotnet test
$env:PWDEBUG=consoledotnet test
set PWDEBUG=consoledotnet test
Once Playwright launches the browser window, you can open the developer tools. The `playwright` object will be available in the console panel.
#### playwright.$(selector)[](https://playwright.dev/dotnet/docs/debug#playwrightselector "Direct link to playwright.$(selector)")
Query the Playwright selector, using the actual Playwright query engine, for example:
playwright.$('.auth-form >> text=Log in');
#### playwright.$$(selector)[](https://playwright.dev/dotnet/docs/debug#playwrightselector-1 "Direct link to playwright.$$(selector)")
Same as `playwright.$`, but returns all matching elements.
playwright.$$('li >> text=John')[
,
,
,
]
#### playwright.inspect(selector)[](https://playwright.dev/dotnet/docs/debug#playwrightinspectselector "Direct link to playwright.inspect(selector)")
Reveal element in the Elements panel.
playwright.inspect('text=Log in')
#### playwright.locator(selector)[](https://playwright.dev/dotnet/docs/debug#playwrightlocatorselector "Direct link to playwright.locator(selector)")
Create a locator and query matching elements, for example:
playwright.locator('.auth-form', { hasText: 'Log in' });Locator () - element: button - elements: [button]
#### playwright.selector(element)[](https://playwright.dev/dotnet/docs/debug#playwrightselectorelement "Direct link to playwright.selector(element)")
Generates selector for the given element. For example, select an element in the Elements panel and pass `$0`:
playwright.selector($0)"div[id="glow-ingress-block"] >> text=/.*Hello.*/"
Verbose API logs[](https://playwright.dev/dotnet/docs/debug#verbose-api-logs "Direct link to Verbose API logs")
-----------------------------------------------------------------------------------------------------------------
Playwright supports verbose logging with the `DEBUG` environment variable.
* Bash
* PowerShell
* Batch
DEBUG=pw:api dotnet run
$env:DEBUG="pw:api"dotnet run
set DEBUG=pw:apidotnet run
note
**For WebKit**: launching WebKit Inspector during the execution will prevent the Playwright script from executing any further and will reset pre-configured user agent and device emulation.
Headed mode[](https://playwright.dev/dotnet/docs/debug#headed-mode "Direct link to Headed mode")
--------------------------------------------------------------------------------------------------
Playwright runs browsers in headless mode by default. To change this behavior, use `headless: false` as a launch option.
You can also use the [SlowMo](https://playwright.dev/dotnet/docs/api/class-browsertype#browser-type-launch-option-slow-mo)
option to slow down execution (by N milliseconds per operation) and follow along while debugging.
// Chromium, Firefox, or WebKitawait using var browser = await playwright.Chromium.LaunchAsync(new(){ Headless = false, SlowMo = 100});
* [Playwright Inspector](https://playwright.dev/dotnet/docs/debug#playwright-inspector)
* [Run in debug mode](https://playwright.dev/dotnet/docs/debug#run-in-debug-mode)
* [Stepping through your tests](https://playwright.dev/dotnet/docs/debug#stepping-through-your-tests)
* [Run a test from a specific breakpoint](https://playwright.dev/dotnet/docs/debug#run-a-test-from-a-specific-breakpoint)
* [Live editing locators](https://playwright.dev/dotnet/docs/debug#live-editing-locators)
* [Picking locators](https://playwright.dev/dotnet/docs/debug#picking-locators)
* [Actionability logs](https://playwright.dev/dotnet/docs/debug#actionability-logs)
* [Trace Viewer](https://playwright.dev/dotnet/docs/debug#trace-viewer)
* [Browser Developer Tools](https://playwright.dev/dotnet/docs/debug#browser-developer-tools)
* [Verbose API logs](https://playwright.dev/dotnet/docs/debug#verbose-api-logs)
* [Headed mode](https://playwright.dev/dotnet/docs/debug#headed-mode)
---
# TimeoutError | Playwright .NET
[Skip to main content](https://playwright.dev/dotnet/docs/api/class-timeouterror#__docusaurus_skipToContent_fallback)
* extends: \[Error\]
TimeoutError is emitted whenever certain operations are terminated due to timeout, e.g. [Locator.WaitForAsync()](https://playwright.dev/dotnet/docs/api/class-locator#locator-wait-for)
or [BrowserType.LaunchAsync()](https://playwright.dev/dotnet/docs/api/class-browsertype#browser-type-launch)
.
using Microsoft.Playwright;using var playwright = await Playwright.CreateAsync();await using var browser = await playwright.Chromium.LaunchAsync();var page = await browser.NewPageAsync();try{ await page.ClickAsync("text=Example", new() { Timeout = 100 });}catch (TimeoutException){ Console.WriteLine("Timeout!");}
---
# JSHandle | Playwright Java
[Skip to main content](https://playwright.dev/java/docs/api/class-jshandle#__docusaurus_skipToContent_fallback)
On this page
JSHandle represents an in-page JavaScript object. JSHandles can be created with the [Page.evaluateHandle()](https://playwright.dev/java/docs/api/class-page#page-evaluate-handle)
method.
JSHandle windowHandle = page.evaluateHandle("() => window");// ...
JSHandle prevents the referenced JavaScript object being garbage collected unless the handle is exposed with [JSHandle.dispose()](https://playwright.dev/java/docs/api/class-jshandle#js-handle-dispose)
. JSHandles are auto-disposed when their origin frame gets navigated or the parent context gets destroyed.
JSHandle instances can be used as an argument in [Page.evalOnSelector()](https://playwright.dev/java/docs/api/class-page#page-eval-on-selector)
, [Page.evaluate()](https://playwright.dev/java/docs/api/class-page#page-evaluate)
and [Page.evaluateHandle()](https://playwright.dev/java/docs/api/class-page#page-evaluate-handle)
methods.
* * *
Methods[](https://playwright.dev/java/docs/api/class-jshandle#methods "Direct link to Methods")
-------------------------------------------------------------------------------------------------
### asElement[](https://playwright.dev/java/docs/api/class-jshandle#js-handle-as-element "Direct link to asElement")
Added before v1.9 jsHandle.asElement
Returns either `null` or the object handle itself, if the object handle is an instance of [ElementHandle](https://playwright.dev/java/docs/api/class-elementhandle "ElementHandle")
.
**Usage**
JSHandle.asElement();
**Returns**
* [null](https://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#jls-3.10.7 "null")
| [ElementHandle](https://playwright.dev/java/docs/api/class-elementhandle "ElementHandle")
[#](https://playwright.dev/java/docs/api/class-jshandle#js-handle-as-element-return)
* * *
### dispose[](https://playwright.dev/java/docs/api/class-jshandle#js-handle-dispose "Direct link to dispose")
Added before v1.9 jsHandle.dispose
The `jsHandle.dispose` method stops referencing the element handle.
**Usage**
JSHandle.dispose();
**Returns**
* [void](https://docs.oracle.com/javase/tutorial/java/javaOO/methods.html "void")
[#](https://playwright.dev/java/docs/api/class-jshandle#js-handle-dispose-return)
* * *
### evaluate[](https://playwright.dev/java/docs/api/class-jshandle#js-handle-evaluate "Direct link to evaluate")
Added before v1.9 jsHandle.evaluate
Returns the return value of [expression](https://playwright.dev/java/docs/api/class-jshandle#js-handle-evaluate-option-expression)
.
This method passes this handle as the first argument to [expression](https://playwright.dev/java/docs/api/class-jshandle#js-handle-evaluate-option-expression)
.
If [expression](https://playwright.dev/java/docs/api/class-jshandle#js-handle-evaluate-option-expression)
returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")
, then `handle.evaluate` would wait for the promise to resolve and return its value.
**Usage**
ElementHandle tweetHandle = page.querySelector(".tweet .retweets");assertEquals("10 retweets", tweetHandle.evaluate("node => node.innerText"));
**Arguments**
* `expression` [String](https://docs.oracle.com/javase/8/docs/api/java/lang/String.html "String")
[#](https://playwright.dev/java/docs/api/class-jshandle#js-handle-evaluate-option-expression)
JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the function is automatically invoked.
* `arg` [EvaluationArgument](https://playwright.dev/java/docs/evaluating#evaluation-argument "EvaluationArgument")
_(optional)_[#](https://playwright.dev/java/docs/api/class-jshandle#js-handle-evaluate-option-arg)
Optional argument to pass to [expression](https://playwright.dev/java/docs/api/class-jshandle#js-handle-evaluate-option-expression)
.
**Returns**
* [Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html "Object")
[#](https://playwright.dev/java/docs/api/class-jshandle#js-handle-evaluate-return)
* * *
### evaluateHandle[](https://playwright.dev/java/docs/api/class-jshandle#js-handle-evaluate-handle "Direct link to evaluateHandle")
Added before v1.9 jsHandle.evaluateHandle
Returns the return value of [expression](https://playwright.dev/java/docs/api/class-jshandle#js-handle-evaluate-handle-option-expression)
as a [JSHandle](https://playwright.dev/java/docs/api/class-jshandle "JSHandle")
.
This method passes this handle as the first argument to [expression](https://playwright.dev/java/docs/api/class-jshandle#js-handle-evaluate-handle-option-expression)
.
The only difference between `jsHandle.evaluate` and `jsHandle.evaluateHandle` is that `jsHandle.evaluateHandle` returns [JSHandle](https://playwright.dev/java/docs/api/class-jshandle "JSHandle")
.
If the function passed to the `jsHandle.evaluateHandle` returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")
, then `jsHandle.evaluateHandle` would wait for the promise to resolve and return its value.
See [Page.evaluateHandle()](https://playwright.dev/java/docs/api/class-page#page-evaluate-handle)
for more details.
**Usage**
JSHandle.evaluateHandle(expression);JSHandle.evaluateHandle(expression, arg);
**Arguments**
* `expression` [String](https://docs.oracle.com/javase/8/docs/api/java/lang/String.html "String")
[#](https://playwright.dev/java/docs/api/class-jshandle#js-handle-evaluate-handle-option-expression)
JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the function is automatically invoked.
* `arg` [EvaluationArgument](https://playwright.dev/java/docs/evaluating#evaluation-argument "EvaluationArgument")
_(optional)_[#](https://playwright.dev/java/docs/api/class-jshandle#js-handle-evaluate-handle-option-arg)
Optional argument to pass to [expression](https://playwright.dev/java/docs/api/class-jshandle#js-handle-evaluate-handle-option-expression)
.
**Returns**
* [JSHandle](https://playwright.dev/java/docs/api/class-jshandle "JSHandle")
[#](https://playwright.dev/java/docs/api/class-jshandle#js-handle-evaluate-handle-return)
* * *
### getProperties[](https://playwright.dev/java/docs/api/class-jshandle#js-handle-get-properties "Direct link to getProperties")
Added before v1.9 jsHandle.getProperties
The method returns a map with **own property names** as keys and JSHandle instances for the property values.
**Usage**
JSHandle handle = page.evaluateHandle("() => ({ window, document })");Map properties = handle.getProperties();JSHandle windowHandle = properties.get("window");JSHandle documentHandle = properties.get("document");handle.dispose();
**Returns**
* [Map](https://docs.oracle.com/javase/8/docs/api/java/util/Map.html "Map")
<[String](https://docs.oracle.com/javase/8/docs/api/java/lang/String.html "String")
, [JSHandle](https://playwright.dev/java/docs/api/class-jshandle "JSHandle")
\>[#](https://playwright.dev/java/docs/api/class-jshandle#js-handle-get-properties-return)
* * *
### getProperty[](https://playwright.dev/java/docs/api/class-jshandle#js-handle-get-property "Direct link to getProperty")
Added before v1.9 jsHandle.getProperty
Fetches a single property from the referenced object.
**Usage**
JSHandle.getProperty(propertyName);
**Arguments**
* `propertyName` [String](https://docs.oracle.com/javase/8/docs/api/java/lang/String.html "String")
[#](https://playwright.dev/java/docs/api/class-jshandle#js-handle-get-property-option-property-name)
property to get
**Returns**
* [JSHandle](https://playwright.dev/java/docs/api/class-jshandle "JSHandle")
[#](https://playwright.dev/java/docs/api/class-jshandle#js-handle-get-property-return)
* * *
### jsonValue[](https://playwright.dev/java/docs/api/class-jshandle#js-handle-json-value "Direct link to jsonValue")
Added before v1.9 jsHandle.jsonValue
Returns a JSON representation of the object. If the object has a `toJSON` function, it **will not be called**.
note
The method will return an empty JSON object if the referenced object is not stringifiable. It will throw an error if the object has circular references.
**Usage**
JSHandle.jsonValue();
**Returns**
* [Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html "Object")
[#](https://playwright.dev/java/docs/api/class-jshandle#js-handle-json-value-return)
* [Methods](https://playwright.dev/java/docs/api/class-jshandle#methods)
* [asElement](https://playwright.dev/java/docs/api/class-jshandle#js-handle-as-element)
* [dispose](https://playwright.dev/java/docs/api/class-jshandle#js-handle-dispose)
* [evaluate](https://playwright.dev/java/docs/api/class-jshandle#js-handle-evaluate)
* [evaluateHandle](https://playwright.dev/java/docs/api/class-jshandle#js-handle-evaluate-handle)
* [getProperties](https://playwright.dev/java/docs/api/class-jshandle#js-handle-get-properties)
* [getProperty](https://playwright.dev/java/docs/api/class-jshandle#js-handle-get-property)
* [jsonValue](https://playwright.dev/java/docs/api/class-jshandle#js-handle-json-value)
---
# Page object models | Playwright .NET
[Skip to main content](https://playwright.dev/dotnet/docs/pom#__docusaurus_skipToContent_fallback)
On this page
Introduction[](https://playwright.dev/dotnet/docs/pom#introduction "Direct link to Introduction")
---------------------------------------------------------------------------------------------------
Large test suites can be structured to optimize ease of authoring and maintenance. Page object models are one such approach to structure your test suite.
A page object represents a part of your web application. An e-commerce web application might have a home page, a listings page and a checkout page. Each of them can be represented by page object models.
Page objects **simplify authoring** by creating a higher-level API which suits your application and **simplify maintenance** by capturing element selectors in one place and create reusable code to avoid repetition.
Implementation[](https://playwright.dev/dotnet/docs/pom#implementation "Direct link to Implementation")
---------------------------------------------------------------------------------------------------------
Page object models wrap over a Playwright [Page](https://playwright.dev/dotnet/docs/api/class-page "Page")
.
using System.Threading.Tasks;using Microsoft.Playwright;namespace BigEcommerceApp.Tests.Models;public class SearchPage{ private readonly IPage _page; private readonly ILocator _searchTermInput; public SearchPage(IPage page) { _page = page; _searchTermInput = page.Locator("[aria-label='Enter your search term']"); } public async Task GotoAsync() { await _page.GotoAsync("https://bing.com"); } public async Task SearchAsync(string text) { await _searchTermInput.FillAsync(text); await _searchTermInput.PressAsync("Enter"); }}
Page objects can then be used inside a test.
using BigEcommerceApp.Tests.Models;// in the testvar page = new SearchPage(await browser.NewPageAsync());await page.GotoAsync();await page.SearchAsync("search query");
* [Introduction](https://playwright.dev/dotnet/docs/pom#introduction)
* [Implementation](https://playwright.dev/dotnet/docs/pom#implementation)
---
# Evaluating JavaScript | Playwright .NET
[Skip to main content](https://playwright.dev/dotnet/docs/evaluating#__docusaurus_skipToContent_fallback)
On this page
Introduction[](https://playwright.dev/dotnet/docs/evaluating#introduction "Direct link to Introduction")
----------------------------------------------------------------------------------------------------------
Playwright scripts run in your Playwright environment. Your page scripts run in the browser page environment. Those environments don't intersect, they are running in different virtual machines in different processes and even potentially on different computers.
The [Page.EvaluateAsync()](https://playwright.dev/dotnet/docs/api/class-page#page-evaluate)
API can run a JavaScript function in the context of the web page and bring results back to the Playwright environment. Browser globals like `window` and `document` can be used in `evaluate`.
var href = await page.EvaluateAsync("document.location.href");
If the result is a Promise or if the function is asynchronous evaluate will automatically wait until it's resolved:
int status = await page.EvaluateAsync(@"async () => { const response = await fetch(location.href); return response.status;}");
Different environments[](https://playwright.dev/dotnet/docs/evaluating#different-environments "Direct link to Different environments")
----------------------------------------------------------------------------------------------------------------------------------------
Evaluated scripts run in the browser environment, while your test runs in a testing environments. This means you cannot use variables from your test in the page and vice versa. Instead, you should pass them explicitly as an argument.
The following snippet is **WRONG** because it uses the variable directly:
var data = "some data";var result = await page.EvaluateAsync(@"() => { // WRONG: there is no 'data' in the web page. window.myApp.use(data);}");
The following snippet is **CORRECT** because it passes the value explicitly as an argument:
var data = "some data";// Pass |data| as a parameter.var result = await page.EvaluateAsync("data => { window.myApp.use(data); }", data);
Evaluation Argument[](https://playwright.dev/dotnet/docs/evaluating#evaluation-argument "Direct link to Evaluation Argument")
-------------------------------------------------------------------------------------------------------------------------------
Playwright evaluation methods like [Page.EvaluateAsync()](https://playwright.dev/dotnet/docs/api/class-page#page-evaluate)
take a single optional argument. This argument can be a mix of [Serializable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable")
values and [JSHandle](https://playwright.dev/dotnet/docs/api/class-jshandle "JSHandle")
instances. Handles are automatically converted to the value they represent.
// A primitive value.await page.EvaluateAsync("num => num", 42);// An array.await page.EvaluateAsync("array => array.length", new[] { 1, 2, 3 });// An object.await page.EvaluateAsync