Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

docs(dotnet): examples for dialog, download and filechooser (#6526)

Anže Vodovnikd6b98effc324
diff --git a/docs/src/api/class-dialog.md b/docs/src/api/class-dialog.md
index 5224c46818..2915851d15 100644
--- a/docs/src/api/class-dialog.md
+++ b/docs/src/api/class-dialog.md
@@ -80,6 +80,29 @@ with sync_playwright() as playwright:
run(playwright)
```
+```csharp
+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 [`event: Page.dialog`] listener.
When listener is present, it **must** either [`method: Dialog.accept`] or [`method: 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.
diff --git a/docs/src/api/class-download.md b/docs/src/api/class-download.md
index e5de7a7313..dea3857f5e 100644
--- a/docs/src/api/class-download.md
+++ b/docs/src/api/class-download.md
@@ -48,6 +48,12 @@ download = download_info.value
path = download.path()
```
+```csharp
+var downloadTask = page.WaitForDownloadAsync();
+await Task.WhenAll(downloadTask, page.ClickAsync("#downloadButton"));
+Console.WriteLine(await downloadTask.Result.PathAsync());
+```
+
:::note
Browser context **must** be created with the [`option: acceptDownloads`] set to `true` when user needs access to the
downloaded content. If [`option: acceptDownloads`] is not set, download events are emitted, but the actual download is
@@ -96,4 +102,4 @@ browsers can use different logic for computing it.
## method: Download.url
- returns: <[string]>
-Returns downloaded url.
\ No newline at end of file
+Returns downloaded url.
diff --git a/docs/src/api/class-filechooser.md b/docs/src/api/class-filechooser.md
index 2389db652f..c571c856c0 100644
--- a/docs/src/api/class-filechooser.md
+++ b/docs/src/api/class-filechooser.md
@@ -29,6 +29,12 @@ file_chooser = fc_info.value
file_chooser.set_files("myfile.pdf")
```
+```csharp
+var fileChooserTask = page.WaitForFileChooserAsync();
+await Task.WhenAll(fileChooserTask, page.ClickAsync("upload"));
+await fileChooserTask.Result.SetFilesAsync("temp.txt");
+```
+
## method: FileChooser.element
- returns: <[ElementHandle]>