docs: fix inconsistent .NET snippets (#29831)

This commit is contained in:
Max Schmitt 2024-03-06 17:51:44 +01:00 committed by GitHub
parent 425f737eb6
commit d125ff4d39
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 16 additions and 10 deletions

View File

@ -186,7 +186,10 @@ context.on("dialog", lambda dialog: dialog.accept())
```
```csharp
context.Dialog += (_, dialog) => dialog.AcceptAsync();
Context.Dialog += async (_, dialog) =>
{
await dialog.AcceptAsync();
};
```
:::note
@ -390,7 +393,7 @@ browser_context.add_init_script(path="preload.js")
```
```csharp
await context.AddInitScriptAsync(scriptPath: "preload.js");
await Context.AddInitScriptAsync(scriptPath: "preload.js");
```
:::note
@ -1180,7 +1183,7 @@ context.route("/api/**", handle_route)
await page.RouteAsync("/api/**", async r =>
{
if (r.Request.PostData.Contains("my-string"))
await r.FulfillAsync(body: "mocked-data");
await r.FulfillAsync(new() { Body = "mocked-data" });
else
await r.ContinueAsync();
});

View File

@ -608,7 +608,7 @@ page.add_init_script(path="./preload.js")
```
```csharp
await page.AddInitScriptAsync(scriptPath: "./preload.js");
await Page.AddInitScriptAsync(scriptPath: "./preload.js");
```
:::note

View File

@ -32,8 +32,11 @@ page.get_by_role("button").click()
```
```csharp
page.Dialog += (_, dialog) => dialog.AcceptAsync();
await page.GetByRole(AriaRole.Button).ClickAsync();
Page.Dialog += async (_, dialog) =>
{
await dialog.AcceptAsync();
};
await Page.GetByRole(AriaRole.Button).ClickAsync();
```
:::note
@ -116,10 +119,10 @@ page.close(run_before_unload=True)
```
```csharp
page.Dialog += (_, dialog) =>
Page.Dialog += async (_, dialog) =>
{
Assert.AreEqual("beforeunload", dialog.Type);
dialog.DismissAsync();
await dialog.DismissAsync();
};
await page.CloseAsync(runBeforeUnload: true);
await Page.CloseAsync(new() { RunBeforeUnload = true });
```

View File

@ -550,7 +550,7 @@ await page.RouteAsync("**/*", async route => {
});
// Continue requests as POST.
await page.RouteAsync("**/*", async route => await route.ContinueAsync(method: "POST"));
await Page.RouteAsync("**/*", async route => await route.ContinueAsync(new() { Method = "POST" }));
```
You can continue requests with modifications. Example above removes an HTTP header from the outgoing requests.