diff --git a/dotnet/versioned_docs/version-stable/actionability.mdx b/dotnet/versioned_docs/version-stable/actionability.mdx index 7049573549f..a8f40510cc0 100644 --- a/dotnet/versioned_docs/version-stable/actionability.mdx +++ b/dotnet/versioned_docs/version-stable/actionability.mdx @@ -11,7 +11,7 @@ import HTMLCard from '@site/src/components/HTMLCard'; Playwright performs a range of actionability checks on the elements before making actions to ensure these actions behave as expected. It auto-waits for all the relevant checks to pass and only then performs the requested action. If the required checks do not pass within the given `timeout`, action fails with the `TimeoutError`. For example, for [Locator.ClickAsync()](/api/class-locator.mdx#locator-click), Playwright will ensure that: -- locator resolves to an exactly one element +- locator resolves to exactly one element - element is [Visible] - element is [Stable], as in not animating or completed animation - element [Receives Events], as in not obscured by other elements @@ -124,6 +124,7 @@ For example, consider a scenario where Playwright will click `Sign Up` button re [BrowserType]: /api/class-browsertype.mdx "BrowserType" [CDPSession]: /api/class-cdpsession.mdx "CDPSession" [CDPSessionEvent]: /api/class-cdpsessionevent.mdx "CDPSessionEvent" +[Clock]: /api/class-clock.mdx "Clock" [ConsoleMessage]: /api/class-consolemessage.mdx "ConsoleMessage" [Dialog]: /api/class-dialog.mdx "Dialog" [Download]: /api/class-download.mdx "Download" @@ -165,9 +166,11 @@ For example, consider a scenario where Playwright will click `Sign Up` button re [xpath]: https://developer.mozilla.org/en-US/docs/Web/XPath "xpath" [bool]: https://docs.microsoft.com/en-us/dotnet/api/system.boolean "bool" +[Date]: https://learn.microsoft.com/en-us/dotnet/api/system.datetime "DateTime" [double]: https://docs.microsoft.com/en-us/dotnet/api/system.double "double" [byte]: https://docs.microsoft.com/en-us/dotnet/api/system.byte "byte" [int]: https://docs.microsoft.com/en-us/dotnet/api/system.int32 "int" +[long]: https://docs.microsoft.com/en-us/dotnet/api/system.int64 "long" [void]: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/void "void" [string]: https://docs.microsoft.com/en-us/dotnet/api/system.string "string" [URL]: https://nodejs.org/api/url.html "URL" diff --git a/dotnet/versioned_docs/version-stable/api-testing.mdx b/dotnet/versioned_docs/version-stable/api-testing.mdx index eccde5ad687..65a0e4b90df 100644 --- a/dotnet/versioned_docs/version-stable/api-testing.mdx +++ b/dotnet/versioned_docs/version-stable/api-testing.mdx @@ -17,7 +17,7 @@ Sometimes you may want to send requests to the server directly from .NET without All of that could be achieved via [APIRequestContext] methods. -The following examples rely on the [`Microsoft.Playwright.NUnit`](./test-runners.mdx) package which creates a Playwright and Page instance for each test. +The following examples rely on the [`Microsoft.Playwright.MSTest`](./test-runners.mdx) package which creates a Playwright and Page instance for each test. @@ -35,22 +35,19 @@ The following example demonstrates how to use Playwright to test issues creation GitHub API requires authorization, so we'll configure the token once for all tests. While at it, we'll also set the `baseURL` to simplify the tests. ```csharp -using System; -using System.Collections.Generic; -using System.Threading.Tasks; -using Microsoft.Playwright.NUnit; using Microsoft.Playwright; -using NUnit.Framework; +using Microsoft.Playwright.MSTest; namespace PlaywrightTests; +[TestClass] public class TestGitHubAPI : PlaywrightTest { - static string API_TOKEN = Environment.GetEnvironmentVariable("GITHUB_API_TOKEN"); + static string? API_TOKEN = Environment.GetEnvironmentVariable("GITHUB_API_TOKEN"); - private IAPIRequestContext Request = null; + private IAPIRequestContext Request = null!; - [SetUp] + [TestInitialize] public async Task SetUpAPITesting() { await CreateAPIRequestContext(); @@ -72,7 +69,7 @@ public class TestGitHubAPI : PlaywrightTest }); } - [TearDown] + [TestCleanup] public async Task TearDownAPITesting() { await Request.DisposeAsync(); @@ -85,36 +82,34 @@ public class TestGitHubAPI : PlaywrightTest Now that we initialized request object we can add a few tests that will create new issues in the repository. ```csharp -using System; -using System.Collections.Generic; -using System.Threading.Tasks; using System.Text.Json; -using Microsoft.Playwright.NUnit; using Microsoft.Playwright; -using NUnit.Framework; +using Microsoft.Playwright.MSTest; namespace PlaywrightTests; -[TestFixture] +[TestClass] public class TestGitHubAPI : PlaywrightTest { - static string REPO = "test-repo-2"; + static string REPO = "test"; static string USER = Environment.GetEnvironmentVariable("GITHUB_USER"); - static string API_TOKEN = Environment.GetEnvironmentVariable("GITHUB_API_TOKEN"); + static string? API_TOKEN = Environment.GetEnvironmentVariable("GITHUB_API_TOKEN"); - private IAPIRequestContext Request = null; + private IAPIRequestContext Request = null!; - [Test] + [TestMethod] public async Task ShouldCreateBugReport() { - var data = new Dictionary(); - data.Add("title", "[Bug] report 1"); - data.Add("body", "Bug description"); + var data = new Dictionary + { + { "title", "[Bug] report 1" }, + { "body", "Bug description" } + }; var newIssue = await Request.PostAsync("/repos/" + USER + "/" + REPO + "/issues", new() { DataObject = data }); - Assert.True(newIssue.Ok); + await Expect(newIssue).ToBeOKAsync(); var issues = await Request.GetAsync("/repos/" + USER + "/" + REPO + "/issues"); - Assert.True(issues.Ok); + await Expect(newIssue).ToBeOKAsync(); var issuesJsonResponse = await issues.JsonAsync(); JsonElement? issue = null; foreach (JsonElement issueObj in issuesJsonResponse?.EnumerateArray()) @@ -127,23 +122,24 @@ public class TestGitHubAPI : PlaywrightTest } } } - Assert.NotNull(issue); + Assert.IsNotNull(issue); Assert.AreEqual("Bug description", issue?.GetProperty("body").GetString()); } - [Test] + [TestMethod] public async Task ShouldCreateFeatureRequests() { - var data = new Dictionary(); - data.Add("title", "[Feature] request 1"); - data.Add("body", "Feature description"); + var data = new Dictionary + { + { "title", "[Feature] request 1" }, + { "body", "Feature description" } + }; var newIssue = await Request.PostAsync("/repos/" + USER + "/" + REPO + "/issues", new() { DataObject = data }); - Assert.True(newIssue.Ok); + await Expect(newIssue).ToBeOKAsync(); var issues = await Request.GetAsync("/repos/" + USER + "/" + REPO + "/issues"); - Assert.True(issues.Ok); + await Expect(newIssue).ToBeOKAsync(); var issuesJsonResponse = await issues.JsonAsync(); - var issuesJson = (await issues.JsonAsync())?.EnumerateArray(); JsonElement? issue = null; foreach (JsonElement issueObj in issuesJsonResponse?.EnumerateArray()) @@ -156,7 +152,7 @@ public class TestGitHubAPI : PlaywrightTest } } } - Assert.NotNull(issue); + Assert.IsNotNull(issue); Assert.AreEqual("Feature description", issue?.GetProperty("body").GetString()); } @@ -169,41 +165,47 @@ public class TestGitHubAPI : PlaywrightTest These tests assume that repository exists. You probably want to create a new one before running tests and delete it afterwards. Use `[SetUp]` and `[TearDown]` hooks for that. ```csharp +using System.Text.Json; +using Microsoft.Playwright; +using Microsoft.Playwright.MSTest; + +namespace PlaywrightTests; + +[TestClass] public class TestGitHubAPI : PlaywrightTest { - // ... - - [SetUp] - public async Task SetUpAPITesting() - { - await CreateAPIRequestContext(); - await CreateTestRepository(); - } - - private async Task CreateTestRepository() - { - var resp = await Request.PostAsync("/user/repos", new() - { - DataObject = new Dictionary() - { - ["name"] = REPO, - }, - }); - Assert.True(resp.Ok); - } - - [TearDown] - public async Task TearDownAPITesting() - { - await DeleteTestRepository(); - await Request.DisposeAsync(); - } - - private async Task DeleteTestRepository() - { - var resp = await Request.DeleteAsync("/repos/" + USER + "/" + REPO); - Assert.True(resp.Ok); - } + // ... + [TestInitialize] + public async Task SetUpAPITesting() + { + await CreateAPIRequestContext(); + await CreateTestRepository(); + } + + private async Task CreateTestRepository() + { + var resp = await Request.PostAsync("/user/repos", new() + { + DataObject = new Dictionary() + { + ["name"] = REPO, + }, + }); + await Expect(resp).ToBeOKAsync(); + } + + [TestCleanup] + public async Task TearDownAPITesting() + { + await DeleteTestRepository(); + await Request.DisposeAsync(); + } + + private async Task DeleteTestRepository() + { + var resp = await Request.DeleteAsync("/repos/" + USER + "/" + REPO); + await Expect(resp).ToBeOKAsync(); + } } ``` @@ -212,36 +214,34 @@ public class TestGitHubAPI : PlaywrightTest Here is the complete example of an API test: ```csharp -using System; -using System.Collections.Generic; -using System.Threading.Tasks; using System.Text.Json; -using Microsoft.Playwright.NUnit; using Microsoft.Playwright; -using NUnit.Framework; +using Microsoft.Playwright.MSTest; namespace PlaywrightTests; -[TestFixture] +[TestClass] public class TestGitHubAPI : PlaywrightTest { static string REPO = "test-repo-2"; static string USER = Environment.GetEnvironmentVariable("GITHUB_USER"); - static string API_TOKEN = Environment.GetEnvironmentVariable("GITHUB_API_TOKEN"); + static string? API_TOKEN = Environment.GetEnvironmentVariable("GITHUB_API_TOKEN"); - private IAPIRequestContext Request = null; + private IAPIRequestContext Request = null!; - [Test] + [TestMethod] public async Task ShouldCreateBugReport() { - var data = new Dictionary(); - data.Add("title", "[Bug] report 1"); - data.Add("body", "Bug description"); + var data = new Dictionary + { + { "title", "[Bug] report 1" }, + { "body", "Bug description" } + }; var newIssue = await Request.PostAsync("/repos/" + USER + "/" + REPO + "/issues", new() { DataObject = data }); - Assert.True(newIssue.Ok); + await Expect(newIssue).ToBeOKAsync(); var issues = await Request.GetAsync("/repos/" + USER + "/" + REPO + "/issues"); - Assert.True(issues.Ok); + await Expect(newIssue).ToBeOKAsync(); var issuesJsonResponse = await issues.JsonAsync(); JsonElement? issue = null; foreach (JsonElement issueObj in issuesJsonResponse?.EnumerateArray()) @@ -254,23 +254,24 @@ public class TestGitHubAPI : PlaywrightTest } } } - Assert.NotNull(issue); + Assert.IsNotNull(issue); Assert.AreEqual("Bug description", issue?.GetProperty("body").GetString()); } - [Test] + [TestMethod] public async Task ShouldCreateFeatureRequests() { - var data = new Dictionary(); - data.Add("title", "[Feature] request 1"); - data.Add("body", "Feature description"); + var data = new Dictionary + { + { "title", "[Feature] request 1" }, + { "body", "Feature description" } + }; var newIssue = await Request.PostAsync("/repos/" + USER + "/" + REPO + "/issues", new() { DataObject = data }); - Assert.True(newIssue.Ok); + await Expect(newIssue).ToBeOKAsync(); var issues = await Request.GetAsync("/repos/" + USER + "/" + REPO + "/issues"); - Assert.True(issues.Ok); + await Expect(newIssue).ToBeOKAsync(); var issuesJsonResponse = await issues.JsonAsync(); - var issuesJson = (await issues.JsonAsync())?.EnumerateArray(); JsonElement? issue = null; foreach (JsonElement issueObj in issuesJsonResponse?.EnumerateArray()) @@ -283,11 +284,11 @@ public class TestGitHubAPI : PlaywrightTest } } } - Assert.NotNull(issue); + Assert.IsNotNull(issue); Assert.AreEqual("Feature description", issue?.GetProperty("body").GetString()); } - [SetUp] + [TestInitialize] public async Task SetUpAPITesting() { await CreateAPIRequestContext(); @@ -296,14 +297,16 @@ public class TestGitHubAPI : PlaywrightTest private async Task CreateAPIRequestContext() { - var headers = new Dictionary(); - // We set this header per GitHub guidelines. - headers.Add("Accept", "application/vnd.github.v3+json"); - // Add authorization token to all requests. - // Assuming personal access token available in the environment. - headers.Add("Authorization", "token " + API_TOKEN); - - Request = await this.Playwright.APIRequest.NewContextAsync(new() + var headers = new Dictionary + { + // We set this header per GitHub guidelines. + { "Accept", "application/vnd.github.v3+json" }, + // Add authorization token to all requests. + // Assuming personal access token available in the environment. + { "Authorization", "token " + API_TOKEN } + }; + + Request = await Playwright.APIRequest.NewContextAsync(new() { // All requests we send go to this API endpoint. BaseURL = "https://api.github.com", @@ -320,10 +323,10 @@ public class TestGitHubAPI : PlaywrightTest ["name"] = REPO, }, }); - Assert.True(resp.Ok); + await Expect(resp).ToBeOKAsync(); } - [TearDown] + [TestCleanup] public async Task TearDownAPITesting() { await DeleteTestRepository(); @@ -333,7 +336,7 @@ public class TestGitHubAPI : PlaywrightTest private async Task DeleteTestRepository() { var resp = await Request.DeleteAsync("/repos/" + USER + "/" + REPO); - Assert.True(resp.Ok); + await Expect(resp).ToBeOKAsync(); } } ``` @@ -345,21 +348,23 @@ The following test creates a new issue via API and then navigates to the list of ```csharp class TestGitHubAPI : PageTest { - [Test] - public async Task LastCreatedIssueShouldBeFirstInTheList() - { - var data = new Dictionary(); - data.Add("title", "[Feature] request 1"); - data.Add("body", "Feature description"); - var newIssue = await Request.PostAsync("/repos/" + USER + "/" + REPO + "/issues", new() { DataObject = data }); - Assert.True(newIssue.Ok); - - // When inheriting from 'PlaywrightTest' it only gives you a Playwright instance. To get a Page instance, either start - // a browser, context, and page manually or inherit from 'PageTest' which will launch it for you. - await Page.GotoAsync("https://github.com/" + USER + "/" + REPO + "/issues"); - var firstIssue = Page.Locator("a[data-hovercard-type='issue']").First; - await Expect(firstIssue).ToHaveTextAsync("[Feature] request 1"); - } + [TestMethod] + public async Task LastCreatedIssueShouldBeFirstInTheList() + { + var data = new Dictionary + { + { "title", "[Feature] request 1" }, + { "body", "Feature description" } + }; + var newIssue = await Request.PostAsync("/repos/" + USER + "/" + REPO + "/issues", new() { DataObject = data }); + await Expect(newIssue).ToBeOKAsync(); + + // When inheriting from 'PlaywrightTest' it only gives you a Playwright instance. To get a Page instance, either start + // a browser, context, and page manually or inherit from 'PageTest' which will launch it for you. + await Page.GotoAsync("https://github.com/" + USER + "/" + REPO + "/issues"); + var firstIssue = Page.Locator("a[data-hovercard-type='issue']").First; + await Expect(firstIssue).ToHaveTextAsync("[Feature] request 1"); + } } ``` @@ -368,22 +373,23 @@ class TestGitHubAPI : PageTest The following test creates a new issue via user interface in the browser and then checks via API if it was created: ```csharp +// Make sure to extend from PageTest if you want to use the Page class. class GitHubTests : PageTest { - [Test] - public async Task LastCreatedIssueShouldBeOnTheServer() - { - await Page.GotoAsync("https://github.com/" + USER + "/" + REPO + "/issues"); - await Page.Locator("text=New Issue").ClickAsync(); - await Page.Locator("[aria-label='Title']").FillAsync("Bug report 1"); - await Page.Locator("[aria-label='Comment body']").FillAsync("Bug description"); - await Page.Locator("text=Submit new issue").ClickAsync(); - String issueId = Page.Url.Substring(Page.Url.LastIndexOf('/')); - - var newIssue = await Request.GetAsync("https://github.com/" + USER + "/" + REPO + "/issues/" + issueId); - Assert.True(newIssue.Ok); - StringAssert.Contains(await newIssue.TextAsync(), "Bug report 1"); - } + [TestMethod] + public async Task LastCreatedIssueShouldBeOnTheServer() + { + await Page.GotoAsync("https://github.com/" + USER + "/" + REPO + "/issues"); + await Page.Locator("text=New Issue").ClickAsync(); + await Page.Locator("[aria-label='Title']").FillAsync("Bug report 1"); + await Page.Locator("[aria-label='Comment body']").FillAsync("Bug description"); + await Page.Locator("text=Submit new issue").ClickAsync(); + var issueId = Page.Url.Substring(Page.Url.LastIndexOf('/')); + + var newIssue = await Request.GetAsync("https://github.com/" + USER + "/" + REPO + "/issues/" + issueId); + await Expect(newIssue).ToBeOKAsync(); + StringAssert.Contains(await newIssue.TextAsync(), "Bug report 1"); + } } ``` @@ -421,6 +427,7 @@ var context = await Browser.NewContextAsync(new() { StorageState = state }); [BrowserType]: /api/class-browsertype.mdx "BrowserType" [CDPSession]: /api/class-cdpsession.mdx "CDPSession" [CDPSessionEvent]: /api/class-cdpsessionevent.mdx "CDPSessionEvent" +[Clock]: /api/class-clock.mdx "Clock" [ConsoleMessage]: /api/class-consolemessage.mdx "ConsoleMessage" [Dialog]: /api/class-dialog.mdx "Dialog" [Download]: /api/class-download.mdx "Download" @@ -462,9 +469,11 @@ var context = await Browser.NewContextAsync(new() { StorageState = state }); [xpath]: https://developer.mozilla.org/en-US/docs/Web/XPath "xpath" [bool]: https://docs.microsoft.com/en-us/dotnet/api/system.boolean "bool" +[Date]: https://learn.microsoft.com/en-us/dotnet/api/system.datetime "DateTime" [double]: https://docs.microsoft.com/en-us/dotnet/api/system.double "double" [byte]: https://docs.microsoft.com/en-us/dotnet/api/system.byte "byte" [int]: https://docs.microsoft.com/en-us/dotnet/api/system.int32 "int" +[long]: https://docs.microsoft.com/en-us/dotnet/api/system.int64 "long" [void]: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/void "void" [string]: https://docs.microsoft.com/en-us/dotnet/api/system.string "string" [URL]: https://nodejs.org/api/url.html "URL" diff --git a/dotnet/versioned_docs/version-stable/api/class-accessibility.mdx b/dotnet/versioned_docs/version-stable/api/class-accessibility.mdx index 587b59bef97..0e4050615b1 100644 --- a/dotnet/versioned_docs/version-stable/api/class-accessibility.mdx +++ b/dotnet/versioned_docs/version-stable/api/class-accessibility.mdx @@ -76,6 +76,7 @@ Console.WriteLine(System.Text.Json.JsonSerializer.Serialize(accessibilitySnapsho [BrowserType]: /api/class-browsertype.mdx "BrowserType" [CDPSession]: /api/class-cdpsession.mdx "CDPSession" [CDPSessionEvent]: /api/class-cdpsessionevent.mdx "CDPSessionEvent" +[Clock]: /api/class-clock.mdx "Clock" [ConsoleMessage]: /api/class-consolemessage.mdx "ConsoleMessage" [Dialog]: /api/class-dialog.mdx "Dialog" [Download]: /api/class-download.mdx "Download" @@ -117,9 +118,11 @@ Console.WriteLine(System.Text.Json.JsonSerializer.Serialize(accessibilitySnapsho [xpath]: https://developer.mozilla.org/en-US/docs/Web/XPath "xpath" [bool]: https://docs.microsoft.com/en-us/dotnet/api/system.boolean "bool" +[Date]: https://learn.microsoft.com/en-us/dotnet/api/system.datetime "DateTime" [double]: https://docs.microsoft.com/en-us/dotnet/api/system.double "double" [byte]: https://docs.microsoft.com/en-us/dotnet/api/system.byte "byte" [int]: https://docs.microsoft.com/en-us/dotnet/api/system.int32 "int" +[long]: https://docs.microsoft.com/en-us/dotnet/api/system.int64 "long" [void]: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/void "void" [string]: https://docs.microsoft.com/en-us/dotnet/api/system.string "string" [URL]: https://nodejs.org/api/url.html "URL" diff --git a/dotnet/versioned_docs/version-stable/api/class-apirequest.mdx b/dotnet/versioned_docs/version-stable/api/class-apirequest.mdx index 2600f422211..45cacf88bc0 100644 --- a/dotnet/versioned_docs/version-stable/api/class-apirequest.mdx +++ b/dotnet/versioned_docs/version-stable/api/class-apirequest.mdx @@ -47,6 +47,9 @@ await ApiRequest.NewContextAsync(options); - `Origin` [string]? *(optional)* Restrain sending http credentials on specific origin (scheme://host:port). + - `Send` `enum HttpCredentialsSend { Unauthorized, Always }?` *(optional)* + + This option only applies to the requests sent from corresponding [APIRequestContext] and does not affect requests sent from the browser. `'always'` - `Authorization` header with basic authentication credentials will be sent with the each API request. `'unauthorized` - the credentials are only sent when 401 (Unauthorized) response with `WWW-Authenticate` header is received. Defaults to `'unauthorized'`. Credentials for [HTTP authentication](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication). If no origin is specified, the username and password are sent to any servers upon unauthorized responses. - `IgnoreHTTPSErrors` [bool]? *(optional)*# @@ -94,6 +97,7 @@ await ApiRequest.NewContextAsync(options); [BrowserType]: /api/class-browsertype.mdx "BrowserType" [CDPSession]: /api/class-cdpsession.mdx "CDPSession" [CDPSessionEvent]: /api/class-cdpsessionevent.mdx "CDPSessionEvent" +[Clock]: /api/class-clock.mdx "Clock" [ConsoleMessage]: /api/class-consolemessage.mdx "ConsoleMessage" [Dialog]: /api/class-dialog.mdx "Dialog" [Download]: /api/class-download.mdx "Download" @@ -135,9 +139,11 @@ await ApiRequest.NewContextAsync(options); [xpath]: https://developer.mozilla.org/en-US/docs/Web/XPath "xpath" [bool]: https://docs.microsoft.com/en-us/dotnet/api/system.boolean "bool" +[Date]: https://learn.microsoft.com/en-us/dotnet/api/system.datetime "DateTime" [double]: https://docs.microsoft.com/en-us/dotnet/api/system.double "double" [byte]: https://docs.microsoft.com/en-us/dotnet/api/system.byte "byte" [int]: https://docs.microsoft.com/en-us/dotnet/api/system.int32 "int" +[long]: https://docs.microsoft.com/en-us/dotnet/api/system.int64 "long" [void]: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/void "void" [string]: https://docs.microsoft.com/en-us/dotnet/api/system.string "string" [URL]: https://nodejs.org/api/url.html "URL" diff --git a/dotnet/versioned_docs/version-stable/api/class-apirequestcontext.mdx b/dotnet/versioned_docs/version-stable/api/class-apirequestcontext.mdx index 24d67112af4..75acad5afdf 100644 --- a/dotnet/versioned_docs/version-stable/api/class-apirequestcontext.mdx +++ b/dotnet/versioned_docs/version-stable/api/class-apirequestcontext.mdx @@ -102,9 +102,15 @@ All responses returned by [ApiRequestContext.GetAsync()](/api/class-apirequestco **Usage** ```csharp -await ApiRequestContext.DisposeAsync(); +await ApiRequestContext.DisposeAsync(options); ``` +**Arguments** +- `options` `ApiRequestContextDisposeOptions?` *(optional)* + - `Reason` [string]? *(optional)* Added in: v1.45# + + The reason to be reported to the operations interrupted by the context disposal. + **Returns** - [void]# @@ -525,6 +531,7 @@ await ApiRequestContext.StorageStateAsync(options); [BrowserType]: /api/class-browsertype.mdx "BrowserType" [CDPSession]: /api/class-cdpsession.mdx "CDPSession" [CDPSessionEvent]: /api/class-cdpsessionevent.mdx "CDPSessionEvent" +[Clock]: /api/class-clock.mdx "Clock" [ConsoleMessage]: /api/class-consolemessage.mdx "ConsoleMessage" [Dialog]: /api/class-dialog.mdx "Dialog" [Download]: /api/class-download.mdx "Download" @@ -566,9 +573,11 @@ await ApiRequestContext.StorageStateAsync(options); [xpath]: https://developer.mozilla.org/en-US/docs/Web/XPath "xpath" [bool]: https://docs.microsoft.com/en-us/dotnet/api/system.boolean "bool" +[Date]: https://learn.microsoft.com/en-us/dotnet/api/system.datetime "DateTime" [double]: https://docs.microsoft.com/en-us/dotnet/api/system.double "double" [byte]: https://docs.microsoft.com/en-us/dotnet/api/system.byte "byte" [int]: https://docs.microsoft.com/en-us/dotnet/api/system.int32 "int" +[long]: https://docs.microsoft.com/en-us/dotnet/api/system.int64 "long" [void]: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/void "void" [string]: https://docs.microsoft.com/en-us/dotnet/api/system.string "string" [URL]: https://nodejs.org/api/url.html "URL" diff --git a/dotnet/versioned_docs/version-stable/api/class-apiresponse.mdx b/dotnet/versioned_docs/version-stable/api/class-apiresponse.mdx index 34acee96c0b..db43202b4bc 100644 --- a/dotnet/versioned_docs/version-stable/api/class-apiresponse.mdx +++ b/dotnet/versioned_docs/version-stable/api/class-apiresponse.mdx @@ -201,6 +201,7 @@ ApiResponse.Url [BrowserType]: /api/class-browsertype.mdx "BrowserType" [CDPSession]: /api/class-cdpsession.mdx "CDPSession" [CDPSessionEvent]: /api/class-cdpsessionevent.mdx "CDPSessionEvent" +[Clock]: /api/class-clock.mdx "Clock" [ConsoleMessage]: /api/class-consolemessage.mdx "ConsoleMessage" [Dialog]: /api/class-dialog.mdx "Dialog" [Download]: /api/class-download.mdx "Download" @@ -242,9 +243,11 @@ ApiResponse.Url [xpath]: https://developer.mozilla.org/en-US/docs/Web/XPath "xpath" [bool]: https://docs.microsoft.com/en-us/dotnet/api/system.boolean "bool" +[Date]: https://learn.microsoft.com/en-us/dotnet/api/system.datetime "DateTime" [double]: https://docs.microsoft.com/en-us/dotnet/api/system.double "double" [byte]: https://docs.microsoft.com/en-us/dotnet/api/system.byte "byte" [int]: https://docs.microsoft.com/en-us/dotnet/api/system.int32 "int" +[long]: https://docs.microsoft.com/en-us/dotnet/api/system.int64 "long" [void]: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/void "void" [string]: https://docs.microsoft.com/en-us/dotnet/api/system.string "string" [URL]: https://nodejs.org/api/url.html "URL" diff --git a/dotnet/versioned_docs/version-stable/api/class-apiresponseassertions.mdx b/dotnet/versioned_docs/version-stable/api/class-apiresponseassertions.mdx index 1430b6919c0..ce70f954c10 100644 --- a/dotnet/versioned_docs/version-stable/api/class-apiresponseassertions.mdx +++ b/dotnet/versioned_docs/version-stable/api/class-apiresponseassertions.mdx @@ -55,6 +55,7 @@ Expect(Response).Not [BrowserType]: /api/class-browsertype.mdx "BrowserType" [CDPSession]: /api/class-cdpsession.mdx "CDPSession" [CDPSessionEvent]: /api/class-cdpsessionevent.mdx "CDPSessionEvent" +[Clock]: /api/class-clock.mdx "Clock" [ConsoleMessage]: /api/class-consolemessage.mdx "ConsoleMessage" [Dialog]: /api/class-dialog.mdx "Dialog" [Download]: /api/class-download.mdx "Download" @@ -96,9 +97,11 @@ Expect(Response).Not [xpath]: https://developer.mozilla.org/en-US/docs/Web/XPath "xpath" [bool]: https://docs.microsoft.com/en-us/dotnet/api/system.boolean "bool" +[Date]: https://learn.microsoft.com/en-us/dotnet/api/system.datetime "DateTime" [double]: https://docs.microsoft.com/en-us/dotnet/api/system.double "double" [byte]: https://docs.microsoft.com/en-us/dotnet/api/system.byte "byte" [int]: https://docs.microsoft.com/en-us/dotnet/api/system.int32 "int" +[long]: https://docs.microsoft.com/en-us/dotnet/api/system.int64 "long" [void]: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/void "void" [string]: https://docs.microsoft.com/en-us/dotnet/api/system.string "string" [URL]: https://nodejs.org/api/url.html "URL" diff --git a/dotnet/versioned_docs/version-stable/api/class-browser.mdx b/dotnet/versioned_docs/version-stable/api/class-browser.mdx index 1bef2c4bedd..e0e40b77d2f 100644 --- a/dotnet/versioned_docs/version-stable/api/class-browser.mdx +++ b/dotnet/versioned_docs/version-stable/api/class-browser.mdx @@ -208,6 +208,9 @@ await browser.CloseAsync(); - `Origin` [string]? *(optional)* Restrain sending http credentials on specific origin (scheme://host:port). + - `Send` `enum HttpCredentialsSend { Unauthorized, Always }?` *(optional)* + + This option only applies to the requests sent from corresponding [APIRequestContext] and does not affect requests sent from the browser. `'always'` - `Authorization` header with basic authentication credentials will be sent with the each API request. `'unauthorized` - the credentials are only sent when 401 (Unauthorized) response with `WWW-Authenticate` header is received. Defaults to `'unauthorized'`. Credentials for [HTTP authentication](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication). If no origin is specified, the username and password are sent to any servers upon unauthorized responses. - `IgnoreHTTPSErrors` [bool]? *(optional)*# @@ -387,6 +390,9 @@ await Browser.NewPageAsync(options); - `Origin` [string]? *(optional)* Restrain sending http credentials on specific origin (scheme://host:port). + - `Send` `enum HttpCredentialsSend { Unauthorized, Always }?` *(optional)* + + This option only applies to the requests sent from corresponding [APIRequestContext] and does not affect requests sent from the browser. `'always'` - `Authorization` header with basic authentication credentials will be sent with the each API request. `'unauthorized` - the credentials are only sent when 401 (Unauthorized) response with `WWW-Authenticate` header is received. Defaults to `'unauthorized'`. Credentials for [HTTP authentication](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication). If no origin is specified, the username and password are sent to any servers upon unauthorized responses. - `IgnoreHTTPSErrors` [bool]? *(optional)*# @@ -550,6 +556,7 @@ Browser.Disconnected += async (_, browser) => {}; [BrowserType]: /api/class-browsertype.mdx "BrowserType" [CDPSession]: /api/class-cdpsession.mdx "CDPSession" [CDPSessionEvent]: /api/class-cdpsessionevent.mdx "CDPSessionEvent" +[Clock]: /api/class-clock.mdx "Clock" [ConsoleMessage]: /api/class-consolemessage.mdx "ConsoleMessage" [Dialog]: /api/class-dialog.mdx "Dialog" [Download]: /api/class-download.mdx "Download" @@ -591,9 +598,11 @@ Browser.Disconnected += async (_, browser) => {}; [xpath]: https://developer.mozilla.org/en-US/docs/Web/XPath "xpath" [bool]: https://docs.microsoft.com/en-us/dotnet/api/system.boolean "bool" +[Date]: https://learn.microsoft.com/en-us/dotnet/api/system.datetime "DateTime" [double]: https://docs.microsoft.com/en-us/dotnet/api/system.double "double" [byte]: https://docs.microsoft.com/en-us/dotnet/api/system.byte "byte" [int]: https://docs.microsoft.com/en-us/dotnet/api/system.int32 "int" +[long]: https://docs.microsoft.com/en-us/dotnet/api/system.int64 "long" [void]: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/void "void" [string]: https://docs.microsoft.com/en-us/dotnet/api/system.string "string" [URL]: https://nodejs.org/api/url.html "URL" diff --git a/dotnet/versioned_docs/version-stable/api/class-browsercontext.mdx b/dotnet/versioned_docs/version-stable/api/class-browsercontext.mdx index 882894d32c6..a32f62580f2 100644 --- a/dotnet/versioned_docs/version-stable/api/class-browsercontext.mdx +++ b/dotnet/versioned_docs/version-stable/api/class-browsercontext.mdx @@ -317,28 +317,6 @@ await page.SetContentAsync("\n" + - "
Click me
\n" + - "
Or click me
\n"); - -await page.ClickAsync("div"); -// Note: it makes sense to await the result here, because otherwise, the context -// gets closed and the binding function will throw an exception. -Assert.AreEqual("Click me", await result.Task); -``` - **Arguments** - `name` [string]# @@ -349,6 +327,11 @@ Assert.AreEqual("Click me", await result.Task); - `options` `BrowserContextExposeBindingOptions?` *(optional)* - `Handle` [bool]? *(optional)*# + :::warning[Deprecated] + This option will be removed in the future. + ::: + + Whether to pass the argument as a handle, instead of passing by value. When passing a handle, only one argument is supported. When passing by value, multiple arguments are supported. **Returns** @@ -434,21 +417,22 @@ await BrowserContext.GrantPermissionsAsync(permissions, options); - `permissions` [IEnumerable]<[string]># A permission or an array of permissions to grant. Permissions can be one of the following values: - * `'geolocation'` - * `'midi'` - * `'midi-sysex'` (system-exclusive midi) - * `'notifications'` - * `'camera'` - * `'microphone'` - * `'background-sync'` - * `'ambient-light-sensor'` * `'accelerometer'` - * `'gyroscope'` - * `'magnetometer'` * `'accessibility-events'` + * `'ambient-light-sensor'` + * `'background-sync'` + * `'camera'` * `'clipboard-read'` * `'clipboard-write'` + * `'geolocation'` + * `'gyroscope'` + * `'magnetometer'` + * `'microphone'` + * `'midi-sysex'` (system-exclusive midi) + * `'midi'` + * `'notifications'` * `'payment-handler'` + * `'storage-access'` - `options` `BrowserContextGrantPermissionsOptions?` *(optional)* - `Origin` [string]? *(optional)*# @@ -939,7 +923,7 @@ await BrowserContext.UnrouteAllAsync(options); - `options` `BrowserContextUnrouteAllOptions?` *(optional)* - `Behavior` `enum UnrouteBehavior { Wait, IgnoreErrors, Default }?` *(optional)*# - Specifies wether to wait for already running handlers and what to do if they throw errors: + Specifies whether to wait for already running handlers and what to do if they throw errors: * `'default'` - do not wait for current handler calls (if any) to finish, if unrouted handler throws, it may result in unhandled error * `'wait'` - wait for current handler calls (if any) to finish * `'ignoreErrors'` - do not wait for current handler calls (if any) to finish, all errors thrown by the handlers after unrouting are silently caught @@ -968,6 +952,23 @@ BrowserContext.APIRequest --- +### Clock {#browser-context-clock} + +Added in: v1.45browserContext.Clock + +Playwright has ability to mock clock and passage of time. + +**Usage** + +```csharp +BrowserContext.Clock +``` + +**Type** +- [Clock] + +--- + ### Tracing {#browser-context-tracing} Added in: v1.12browserContext.Tracing @@ -1214,6 +1215,7 @@ BrowserContext.WebError += async (_, webError) => {}; [BrowserType]: /api/class-browsertype.mdx "BrowserType" [CDPSession]: /api/class-cdpsession.mdx "CDPSession" [CDPSessionEvent]: /api/class-cdpsessionevent.mdx "CDPSessionEvent" +[Clock]: /api/class-clock.mdx "Clock" [ConsoleMessage]: /api/class-consolemessage.mdx "ConsoleMessage" [Dialog]: /api/class-dialog.mdx "Dialog" [Download]: /api/class-download.mdx "Download" @@ -1255,9 +1257,11 @@ BrowserContext.WebError += async (_, webError) => {}; [xpath]: https://developer.mozilla.org/en-US/docs/Web/XPath "xpath" [bool]: https://docs.microsoft.com/en-us/dotnet/api/system.boolean "bool" +[Date]: https://learn.microsoft.com/en-us/dotnet/api/system.datetime "DateTime" [double]: https://docs.microsoft.com/en-us/dotnet/api/system.double "double" [byte]: https://docs.microsoft.com/en-us/dotnet/api/system.byte "byte" [int]: https://docs.microsoft.com/en-us/dotnet/api/system.int32 "int" +[long]: https://docs.microsoft.com/en-us/dotnet/api/system.int64 "long" [void]: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/void "void" [string]: https://docs.microsoft.com/en-us/dotnet/api/system.string "string" [URL]: https://nodejs.org/api/url.html "URL" diff --git a/dotnet/versioned_docs/version-stable/api/class-browsertype.mdx b/dotnet/versioned_docs/version-stable/api/class-browsertype.mdx index 3f0ae0a0307..c96e9fa11a7 100644 --- a/dotnet/versioned_docs/version-stable/api/class-browsertype.mdx +++ b/dotnet/versioned_docs/version-stable/api/class-browsertype.mdx @@ -351,6 +351,9 @@ await BrowserType.LaunchPersistentContextAsync(userDataDir, options); - `Origin` [string]? *(optional)* Restrain sending http credentials on specific origin (scheme://host:port). + - `Send` `enum HttpCredentialsSend { Unauthorized, Always }?` *(optional)* + + This option only applies to the requests sent from corresponding [APIRequestContext] and does not affect requests sent from the browser. `'always'` - `Authorization` header with basic authentication credentials will be sent with the each API request. `'unauthorized` - the credentials are only sent when 401 (Unauthorized) response with `WWW-Authenticate` header is received. Defaults to `'unauthorized'`. Credentials for [HTTP authentication](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication). If no origin is specified, the username and password are sent to any servers upon unauthorized responses. - `IgnoreAllDefaultArgs` [bool]? *(optional)* Added in: v1.9# @@ -497,6 +500,7 @@ BrowserType.Name [BrowserType]: /api/class-browsertype.mdx "BrowserType" [CDPSession]: /api/class-cdpsession.mdx "CDPSession" [CDPSessionEvent]: /api/class-cdpsessionevent.mdx "CDPSessionEvent" +[Clock]: /api/class-clock.mdx "Clock" [ConsoleMessage]: /api/class-consolemessage.mdx "ConsoleMessage" [Dialog]: /api/class-dialog.mdx "Dialog" [Download]: /api/class-download.mdx "Download" @@ -538,9 +542,11 @@ BrowserType.Name [xpath]: https://developer.mozilla.org/en-US/docs/Web/XPath "xpath" [bool]: https://docs.microsoft.com/en-us/dotnet/api/system.boolean "bool" +[Date]: https://learn.microsoft.com/en-us/dotnet/api/system.datetime "DateTime" [double]: https://docs.microsoft.com/en-us/dotnet/api/system.double "double" [byte]: https://docs.microsoft.com/en-us/dotnet/api/system.byte "byte" [int]: https://docs.microsoft.com/en-us/dotnet/api/system.int32 "int" +[long]: https://docs.microsoft.com/en-us/dotnet/api/system.int64 "long" [void]: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/void "void" [string]: https://docs.microsoft.com/en-us/dotnet/api/system.string "string" [URL]: https://nodejs.org/api/url.html "URL" diff --git a/dotnet/versioned_docs/version-stable/api/class-cdpsession.mdx b/dotnet/versioned_docs/version-stable/api/class-cdpsession.mdx index 41e27068fd9..b2ef1df67bb 100644 --- a/dotnet/versioned_docs/version-stable/api/class-cdpsession.mdx +++ b/dotnet/versioned_docs/version-stable/api/class-cdpsession.mdx @@ -102,6 +102,7 @@ await CdpSession.SendAsync(method, params); [BrowserType]: /api/class-browsertype.mdx "BrowserType" [CDPSession]: /api/class-cdpsession.mdx "CDPSession" [CDPSessionEvent]: /api/class-cdpsessionevent.mdx "CDPSessionEvent" +[Clock]: /api/class-clock.mdx "Clock" [ConsoleMessage]: /api/class-consolemessage.mdx "ConsoleMessage" [Dialog]: /api/class-dialog.mdx "Dialog" [Download]: /api/class-download.mdx "Download" @@ -143,9 +144,11 @@ await CdpSession.SendAsync(method, params); [xpath]: https://developer.mozilla.org/en-US/docs/Web/XPath "xpath" [bool]: https://docs.microsoft.com/en-us/dotnet/api/system.boolean "bool" +[Date]: https://learn.microsoft.com/en-us/dotnet/api/system.datetime "DateTime" [double]: https://docs.microsoft.com/en-us/dotnet/api/system.double "double" [byte]: https://docs.microsoft.com/en-us/dotnet/api/system.byte "byte" [int]: https://docs.microsoft.com/en-us/dotnet/api/system.int32 "int" +[long]: https://docs.microsoft.com/en-us/dotnet/api/system.int64 "long" [void]: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/void "void" [string]: https://docs.microsoft.com/en-us/dotnet/api/system.string "string" [URL]: https://nodejs.org/api/url.html "URL" diff --git a/dotnet/versioned_docs/version-stable/api/class-cdpsessionevent.mdx b/dotnet/versioned_docs/version-stable/api/class-cdpsessionevent.mdx index 79c6b4c1886..6bc8d440a14 100644 --- a/dotnet/versioned_docs/version-stable/api/class-cdpsessionevent.mdx +++ b/dotnet/versioned_docs/version-stable/api/class-cdpsessionevent.mdx @@ -57,6 +57,7 @@ CdpSessionEvent.OnEvent += async (_, jsonElement) => {}; [BrowserType]: /api/class-browsertype.mdx "BrowserType" [CDPSession]: /api/class-cdpsession.mdx "CDPSession" [CDPSessionEvent]: /api/class-cdpsessionevent.mdx "CDPSessionEvent" +[Clock]: /api/class-clock.mdx "Clock" [ConsoleMessage]: /api/class-consolemessage.mdx "ConsoleMessage" [Dialog]: /api/class-dialog.mdx "Dialog" [Download]: /api/class-download.mdx "Download" @@ -98,9 +99,11 @@ CdpSessionEvent.OnEvent += async (_, jsonElement) => {}; [xpath]: https://developer.mozilla.org/en-US/docs/Web/XPath "xpath" [bool]: https://docs.microsoft.com/en-us/dotnet/api/system.boolean "bool" +[Date]: https://learn.microsoft.com/en-us/dotnet/api/system.datetime "DateTime" [double]: https://docs.microsoft.com/en-us/dotnet/api/system.double "double" [byte]: https://docs.microsoft.com/en-us/dotnet/api/system.byte "byte" [int]: https://docs.microsoft.com/en-us/dotnet/api/system.int32 "int" +[long]: https://docs.microsoft.com/en-us/dotnet/api/system.int64 "long" [void]: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/void "void" [string]: https://docs.microsoft.com/en-us/dotnet/api/system.string "string" [URL]: https://nodejs.org/api/url.html "URL" diff --git a/dotnet/versioned_docs/version-stable/api/class-clock.mdx b/dotnet/versioned_docs/version-stable/api/class-clock.mdx new file mode 100644 index 00000000000..42d4ebb6f9f --- /dev/null +++ b/dotnet/versioned_docs/version-stable/api/class-clock.mdx @@ -0,0 +1,257 @@ +--- +id: class-clock +title: "Clock" +--- +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; +import HTMLCard from '@site/src/components/HTMLCard'; + + +Accurately simulating time-dependent behavior is essential for verifying the correctness of applications. Learn more about [clock emulation](../clock.mdx). + +Note that clock is installed for the entire [BrowserContext], so the time in all the pages and iframes is controlled by the same clock. + + +--- + +## Methods + +### FastForwardAsync {#clock-fast-forward} + +Added in: v1.45clock.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** + +```csharp +await page.Clock.FastForwardAsync(1000); +await page.Clock.FastForwardAsync("30:00"); +``` + +**Arguments** +- `ticks` [long] | [string]# + + 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]# + +--- + +### InstallAsync {#clock-install} + +Added in: v1.45clock.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()](/api/class-clock.mdx#clock-run-for) and [Clock.FastForwardAsync()](/api/class-clock.mdx#clock-fast-forward) for more information. + +**Usage** + +```csharp +await Clock.InstallAsync(options); +``` + +**Arguments** +- `options` `ClockInstallOptions?` *(optional)* + - `TimeInt64|Time|TimeDate` [long]? | [string]? | [Date]? *(optional)*# + + Time to initialize with, current system time by default. + +**Returns** +- [void]# + +--- + +### PauseAtAsync {#clock-pause-at} + +Added in: v1.45clock.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()](/api/class-clock.mdx#clock-run-for), [Clock.FastForwardAsync()](/api/class-clock.mdx#clock-fast-forward), [Clock.PauseAtAsync()](/api/class-clock.mdx#clock-pause-at) or [Clock.ResumeAsync()](/api/class-clock.mdx#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** + +```csharp +await page.Clock.PauseAtAsync(DateTime.Parse("2020-02-02")); +await page.Clock.PauseAtAsync("2020-02-02"); +``` + +**Arguments** +- `time` [long] | [string] | [Date]# + +**Returns** +- [void]# + +--- + +### ResumeAsync {#clock-resume} + +Added in: v1.45clock.ResumeAsync + +Resumes timers. Once this method is called, time resumes flowing, timers are fired as usual. + +**Usage** + +```csharp +await Clock.ResumeAsync(); +``` + +**Returns** +- [void]# + +--- + +### RunForAsync {#clock-run-for} + +Added in: v1.45clock.RunForAsync + +Advance the clock, firing all the time-related callbacks. + +**Usage** + +```csharp +await page.Clock.RunForAsync(1000); +await page.Clock.RunForAsync("30:00"); +``` + +**Arguments** +- `ticks` [long] | [string]# + + 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]# + +--- + +### SetFixedTimeAsync {#clock-set-fixed-time} + +Added in: v1.45clock.SetFixedTimeAsync + +Makes `Date.now` and `new Date()` return fixed fake time at all times, keeps all the timers running. + +**Usage** + +```csharp +await page.Clock.SetFixedTimeAsync(DateTime.Now); +await page.Clock.SetFixedTimeAsync(new DateTime(2020, 2, 2)); +await page.Clock.SetFixedTimeAsync("2020-02-02"); +``` + +**Arguments** +- `time` [long] | [string] | [Date]# + + Time to be set. + +**Returns** +- [void]# + +--- + +### SetSystemTimeAsync {#clock-set-system-time} + +Added in: v1.45clock.SetSystemTimeAsync + +Sets current system time but does not trigger any timers. + +**Usage** + +```csharp +await page.Clock.SetSystemTimeAsync(DateTime.Now); +await page.Clock.SetSystemTimeAsync(new DateTime(2020, 2, 2)); +await page.Clock.SetSystemTimeAsync("2020-02-02"); +``` + +**Arguments** +- `time` [long] | [string] | [Date]# + +**Returns** +- [void]# + + +[Accessibility]: /api/class-accessibility.mdx "Accessibility" +[APIRequest]: /api/class-apirequest.mdx "APIRequest" +[APIRequestContext]: /api/class-apirequestcontext.mdx "APIRequestContext" +[APIResponse]: /api/class-apiresponse.mdx "APIResponse" +[APIResponseAssertions]: /api/class-apiresponseassertions.mdx "APIResponseAssertions" +[Browser]: /api/class-browser.mdx "Browser" +[BrowserContext]: /api/class-browsercontext.mdx "BrowserContext" +[BrowserType]: /api/class-browsertype.mdx "BrowserType" +[CDPSession]: /api/class-cdpsession.mdx "CDPSession" +[CDPSessionEvent]: /api/class-cdpsessionevent.mdx "CDPSessionEvent" +[Clock]: /api/class-clock.mdx "Clock" +[ConsoleMessage]: /api/class-consolemessage.mdx "ConsoleMessage" +[Dialog]: /api/class-dialog.mdx "Dialog" +[Download]: /api/class-download.mdx "Download" +[ElementHandle]: /api/class-elementhandle.mdx "ElementHandle" +[FileChooser]: /api/class-filechooser.mdx "FileChooser" +[FormData]: /api/class-formdata.mdx "FormData" +[Frame]: /api/class-frame.mdx "Frame" +[FrameLocator]: /api/class-framelocator.mdx "FrameLocator" +[JSHandle]: /api/class-jshandle.mdx "JSHandle" +[Keyboard]: /api/class-keyboard.mdx "Keyboard" +[Locator]: /api/class-locator.mdx "Locator" +[LocatorAssertions]: /api/class-locatorassertions.mdx "LocatorAssertions" +[Mouse]: /api/class-mouse.mdx "Mouse" +[Page]: /api/class-page.mdx "Page" +[PageAssertions]: /api/class-pageassertions.mdx "PageAssertions" +[Playwright]: /api/class-playwright.mdx "Playwright" +[PlaywrightAssertions]: /api/class-playwrightassertions.mdx "PlaywrightAssertions" +[Request]: /api/class-request.mdx "Request" +[Response]: /api/class-response.mdx "Response" +[Route]: /api/class-route.mdx "Route" +[Selectors]: /api/class-selectors.mdx "Selectors" +[TimeoutError]: /api/class-timeouterror.mdx "TimeoutError" +[Touchscreen]: /api/class-touchscreen.mdx "Touchscreen" +[Tracing]: /api/class-tracing.mdx "Tracing" +[Video]: /api/class-video.mdx "Video" +[WebError]: /api/class-weberror.mdx "WebError" +[WebSocket]: /api/class-websocket.mdx "WebSocket" +[WebSocketFrame]: /api/class-websocketframe.mdx "WebSocketFrame" +[Worker]: /api/class-worker.mdx "Worker" +[Element]: https://developer.mozilla.org/en-US/docs/Web/API/element "Element" +[EvaluationArgument]: /evaluating.mdx#evaluation-argument "EvaluationArgument" +[Promise]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise" +[iterator]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols "Iterator" +[origin]: https://developer.mozilla.org/en-US/docs/Glossary/Origin "Origin" +[selector]: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors "selector" +[Serializable]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable" +[UIEvent.detail]: https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/detail "UIEvent.detail" +[UnixTime]: https://en.wikipedia.org/wiki/Unix_time "Unix Time" +[xpath]: https://developer.mozilla.org/en-US/docs/Web/XPath "xpath" + +[bool]: https://docs.microsoft.com/en-us/dotnet/api/system.boolean "bool" +[Date]: https://learn.microsoft.com/en-us/dotnet/api/system.datetime "DateTime" +[double]: https://docs.microsoft.com/en-us/dotnet/api/system.double "double" +[byte]: https://docs.microsoft.com/en-us/dotnet/api/system.byte "byte" +[int]: https://docs.microsoft.com/en-us/dotnet/api/system.int32 "int" +[long]: https://docs.microsoft.com/en-us/dotnet/api/system.int64 "long" +[void]: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/void "void" +[string]: https://docs.microsoft.com/en-us/dotnet/api/system.string "string" +[URL]: https://nodejs.org/api/url.html "URL" +[Regex]: https://docs.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex "Regex" + +[Action]: https://docs.microsoft.com/en-us/dotnet/api/system.action-1 "Action" +[Func]: https://docs.microsoft.com/en-us/dotnet/api/system.func-2 "Func" +[IEnumerable]: https://docs.microsoft.com/en-us/dotnet/api/system.collections.ienumerable "IEnumerable" +[IDictionary]: https://docs.microsoft.com/en-us/dotnet/api/system.collections.idictionary "IDictionary" +[Task]: https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.task?view=net-5.0 "Task" +[IReadOnlyDictionary]: https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.ireadonlydictionary-2 "IReadOnlyDictionary" +[JsonElement]: https://docs.microsoft.com/en-us/dotnet/api/system.text.json.jsonelement "JsonElement" + +[all available image tags]: https://mcr.microsoft.com/en-us/product/playwright/dotnet/about "all available image tags" +[Microsoft Artifact Registry]: https://mcr.microsoft.com/en-us/product/playwright/dotnet/about "Microsoft Artifact Registry" +[Dockerfile.jammy]: https://github.com/microsoft/playwright-dotnet/blob/main/utils/docker/Dockerfile.jammy "Dockerfile.jammy" diff --git a/dotnet/versioned_docs/version-stable/api/class-consolemessage.mdx b/dotnet/versioned_docs/version-stable/api/class-consolemessage.mdx index df2e194f580..efd1a3c4597 100644 --- a/dotnet/versioned_docs/version-stable/api/class-consolemessage.mdx +++ b/dotnet/versioned_docs/version-stable/api/class-consolemessage.mdx @@ -7,7 +7,7 @@ import TabItem from '@theme/TabItem'; import HTMLCard from '@site/src/components/HTMLCard'; -[ConsoleMessage] objects are dispatched by page via the [Page.Console](/api/class-page.mdx#page-event-console) event. For each console messages logged in the page there will be corresponding event in the Playwright context. +[ConsoleMessage] objects are dispatched by page via the [Page.Console](/api/class-page.mdx#page-event-console) event. For each console message logged in the page there will be corresponding event in the Playwright context. ```csharp // Listen for all console messages and print them to the standard output. @@ -128,6 +128,7 @@ ConsoleMessage.Type [BrowserType]: /api/class-browsertype.mdx "BrowserType" [CDPSession]: /api/class-cdpsession.mdx "CDPSession" [CDPSessionEvent]: /api/class-cdpsessionevent.mdx "CDPSessionEvent" +[Clock]: /api/class-clock.mdx "Clock" [ConsoleMessage]: /api/class-consolemessage.mdx "ConsoleMessage" [Dialog]: /api/class-dialog.mdx "Dialog" [Download]: /api/class-download.mdx "Download" @@ -169,9 +170,11 @@ ConsoleMessage.Type [xpath]: https://developer.mozilla.org/en-US/docs/Web/XPath "xpath" [bool]: https://docs.microsoft.com/en-us/dotnet/api/system.boolean "bool" +[Date]: https://learn.microsoft.com/en-us/dotnet/api/system.datetime "DateTime" [double]: https://docs.microsoft.com/en-us/dotnet/api/system.double "double" [byte]: https://docs.microsoft.com/en-us/dotnet/api/system.byte "byte" [int]: https://docs.microsoft.com/en-us/dotnet/api/system.int32 "int" +[long]: https://docs.microsoft.com/en-us/dotnet/api/system.int64 "long" [void]: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/void "void" [string]: https://docs.microsoft.com/en-us/dotnet/api/system.string "string" [URL]: https://nodejs.org/api/url.html "URL" diff --git a/dotnet/versioned_docs/version-stable/api/class-dialog.mdx b/dotnet/versioned_docs/version-stable/api/class-dialog.mdx index 33afee08c1e..47bc80b63d1 100644 --- a/dotnet/versioned_docs/version-stable/api/class-dialog.mdx +++ b/dotnet/versioned_docs/version-stable/api/class-dialog.mdx @@ -159,6 +159,7 @@ Dialog.Type [BrowserType]: /api/class-browsertype.mdx "BrowserType" [CDPSession]: /api/class-cdpsession.mdx "CDPSession" [CDPSessionEvent]: /api/class-cdpsessionevent.mdx "CDPSessionEvent" +[Clock]: /api/class-clock.mdx "Clock" [ConsoleMessage]: /api/class-consolemessage.mdx "ConsoleMessage" [Dialog]: /api/class-dialog.mdx "Dialog" [Download]: /api/class-download.mdx "Download" @@ -200,9 +201,11 @@ Dialog.Type [xpath]: https://developer.mozilla.org/en-US/docs/Web/XPath "xpath" [bool]: https://docs.microsoft.com/en-us/dotnet/api/system.boolean "bool" +[Date]: https://learn.microsoft.com/en-us/dotnet/api/system.datetime "DateTime" [double]: https://docs.microsoft.com/en-us/dotnet/api/system.double "double" [byte]: https://docs.microsoft.com/en-us/dotnet/api/system.byte "byte" [int]: https://docs.microsoft.com/en-us/dotnet/api/system.int32 "int" +[long]: https://docs.microsoft.com/en-us/dotnet/api/system.int64 "long" [void]: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/void "void" [string]: https://docs.microsoft.com/en-us/dotnet/api/system.string "string" [URL]: https://nodejs.org/api/url.html "URL" diff --git a/dotnet/versioned_docs/version-stable/api/class-download.mdx b/dotnet/versioned_docs/version-stable/api/class-download.mdx index 8589ce12030..d2e12f2aeec 100644 --- a/dotnet/versioned_docs/version-stable/api/class-download.mdx +++ b/dotnet/versioned_docs/version-stable/api/class-download.mdx @@ -197,6 +197,7 @@ Download.Url [BrowserType]: /api/class-browsertype.mdx "BrowserType" [CDPSession]: /api/class-cdpsession.mdx "CDPSession" [CDPSessionEvent]: /api/class-cdpsessionevent.mdx "CDPSessionEvent" +[Clock]: /api/class-clock.mdx "Clock" [ConsoleMessage]: /api/class-consolemessage.mdx "ConsoleMessage" [Dialog]: /api/class-dialog.mdx "Dialog" [Download]: /api/class-download.mdx "Download" @@ -238,9 +239,11 @@ Download.Url [xpath]: https://developer.mozilla.org/en-US/docs/Web/XPath "xpath" [bool]: https://docs.microsoft.com/en-us/dotnet/api/system.boolean "bool" +[Date]: https://learn.microsoft.com/en-us/dotnet/api/system.datetime "DateTime" [double]: https://docs.microsoft.com/en-us/dotnet/api/system.double "double" [byte]: https://docs.microsoft.com/en-us/dotnet/api/system.byte "byte" [int]: https://docs.microsoft.com/en-us/dotnet/api/system.int32 "int" +[long]: https://docs.microsoft.com/en-us/dotnet/api/system.int64 "long" [void]: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/void "void" [string]: https://docs.microsoft.com/en-us/dotnet/api/system.string "string" [URL]: https://nodejs.org/api/url.html "URL" diff --git a/dotnet/versioned_docs/version-stable/api/class-elementhandle.mdx b/dotnet/versioned_docs/version-stable/api/class-elementhandle.mdx index 3dc4c3dc6a2..6e5b2d922ca 100644 --- a/dotnet/versioned_docs/version-stable/api/class-elementhandle.mdx +++ b/dotnet/versioned_docs/version-stable/api/class-elementhandle.mdx @@ -1062,6 +1062,8 @@ This method waits for [actionability](../actionability.mdx) checks, then tries t Throws when `elementHandle` does not point to an element [connected](https://developer.mozilla.org/en-US/docs/Web/API/Node/isConnected) to a Document or a ShadowRoot. +See [scrolling](../input.mdx#scrolling) for alternative ways to scroll. + **Usage** ```csharp @@ -1248,7 +1250,7 @@ Use locator-based [Locator.SetInputFilesAsync()](/api/class-locator.mdx#locator- ::: -Sets the value of the file input to these file paths or files. If some of the `filePaths` are relative paths, then they are resolved relative to the current working directory. For empty array, clears the selected files. +Sets the value of the file input to these file paths or files. If some of the `filePaths` are relative paths, then they are resolved relative to the current working directory. For empty array, clears the selected files. For inputs with a `[webkitdirectory]` attribute, only a single directory path is supported. This method expects [ElementHandle] to point to an [input element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input). However, if the element is inside the `