From e5833c2622b1daf5497d9ed2a002cff319e69920 Mon Sep 17 00:00:00 2001 From: amaechi hope Date: Fri, 8 Nov 2024 17:35:36 +0100 Subject: [PATCH] docs(dotnet): fix code snippets --- docs/src/api/class-browsercontext.md | 2 +- docs/src/api/class-download.md | 2 +- docs/src/api/class-elementhandle.md | 2 +- docs/src/api/class-filechooser.md | 2 +- docs/src/api/class-keyboard.md | 2 +- docs/src/api/class-locator.md | 2 +- docs/src/api/class-locatorassertions.md | 2 +- docs/src/api/class-page.md | 24 +++++++++---------- docs/src/api/class-request.md | 6 ++--- docs/src/api/class-tracing.md | 2 +- docs/src/api/params.md | 10 ++++---- docs/src/events.md | 4 ++-- docs/src/network.md | 2 +- tests/library/inspector/cli-codegen-1.spec.ts | 4 ++-- 14 files changed, 33 insertions(+), 33 deletions(-) diff --git a/docs/src/api/class-browsercontext.md b/docs/src/api/class-browsercontext.md index a87c49235e..8d6c57a3e3 100644 --- a/docs/src/api/class-browsercontext.md +++ b/docs/src/api/class-browsercontext.md @@ -256,7 +256,7 @@ print(page.evaluate("location.href")) ```csharp var popup = await context.RunAndWaitForPageAsync(async => { - await Page.GetByText("open new page").ClickAsync(); + await page.GetByText("open new page").ClickAsync(); }); Console.WriteLine(await popup.EvaluateAsync("location.href")); ``` diff --git a/docs/src/api/class-download.md b/docs/src/api/class-download.md index 868259cb47..3333d36996 100644 --- a/docs/src/api/class-download.md +++ b/docs/src/api/class-download.md @@ -54,7 +54,7 @@ download.save_as("/path/to/save/at/" + download.suggested_filename) ```csharp // Start the task of waiting for the download before clicking var waitForDownloadTask = page.WaitForDownloadAsync(); -await Page.GetByText("Download file").ClickAsync(); +await page.GetByText("Download file").ClickAsync(); var download = await waitForDownloadTask; // Wait for the download process to complete and save the downloaded file somewhere diff --git a/docs/src/api/class-elementhandle.md b/docs/src/api/class-elementhandle.md index 3fdd658c17..c8f54c7380 100644 --- a/docs/src/api/class-elementhandle.md +++ b/docs/src/api/class-elementhandle.md @@ -101,7 +101,7 @@ locator.click() ``` ```csharp -var locator = Page.GetByText("Submit"); +var locator = page.GetByText("Submit"); await locator.HoverAsync(); await locator.ClickAsync(); ``` diff --git a/docs/src/api/class-filechooser.md b/docs/src/api/class-filechooser.md index 4a9079cb03..82502c8d5e 100644 --- a/docs/src/api/class-filechooser.md +++ b/docs/src/api/class-filechooser.md @@ -33,7 +33,7 @@ file_chooser.set_files("myfile.pdf") ```csharp var fileChooser = await page.RunAndWaitForFileChooserAsync(async () => { - await Page.GetByText("Upload file").ClickAsync(); + await page.GetByText("Upload file").ClickAsync(); }); await fileChooser.SetFilesAsync("temp.txt"); ``` diff --git a/docs/src/api/class-keyboard.md b/docs/src/api/class-keyboard.md index dfd4f25d43..f86c4ad11f 100644 --- a/docs/src/api/class-keyboard.md +++ b/docs/src/api/class-keyboard.md @@ -290,7 +290,7 @@ browser.close() ``` ```csharp -await Page.GotoAsync("https://keycode.info"); +await page.GotoAsync("https://keycode.info"); await page.Keyboard.PressAsync("A"); await page.ScreenshotAsync(new() { Path = "A.png" }); await page.Keyboard.PressAsync("ArrowLeft"); diff --git a/docs/src/api/class-locator.md b/docs/src/api/class-locator.md index 9a776e7465..ba6dc91353 100644 --- a/docs/src/api/class-locator.md +++ b/docs/src/api/class-locator.md @@ -1757,7 +1757,7 @@ new_email.click() ```csharp var newEmail = page.GetByRole(AriaRole.Button, new() { Name = "New" }); -var dialog = Page.GetByText("Confirm security settings"); +var dialog = page.GetByText("Confirm security settings"); await Expect(newEmail.Or(dialog)).ToBeVisibleAsync(); if (await dialog.IsVisibleAsync()) await page.GetByRole(AriaRole.Button, new() { Name = "Dismiss" }).ClickAsync(); diff --git a/docs/src/api/class-locatorassertions.md b/docs/src/api/class-locatorassertions.md index ae613ea0e9..b48b3fce7e 100644 --- a/docs/src/api/class-locatorassertions.md +++ b/docs/src/api/class-locatorassertions.md @@ -2138,7 +2138,7 @@ expect(page.locator('body')).to_match_aria_snapshot(''' ``` ```csharp -await Page.GotoAsync("https://demo.playwright.dev/todomvc/"); +await page.GotoAsync("https://demo.playwright.dev/todomvc/"); await Expect(page.Locator("body")).ToMatchAriaSnapshotAsync(@" - heading ""todos"" - textbox ""What needs to be done?"" diff --git a/docs/src/api/class-page.md b/docs/src/api/class-page.md index b993d8384d..373649154d 100644 --- a/docs/src/api/class-page.md +++ b/docs/src/api/class-page.md @@ -485,7 +485,7 @@ print(popup.evaluate("location.href")) ```csharp var popup = await page.RunAndWaitForPopupAsync(async () => { - await Page.GetByText("open the popup").ClickAsync(); + await page.GetByText("open the popup").ClickAsync(); }); Console.WriteLine(await popup.EvaluateAsync("location.href")); ``` @@ -3186,12 +3186,12 @@ await page.get_by_role("button", name="Start here").click() ```csharp // Setup the handler. -await page.AddLocatorHandlerAsync(Page.GetByText("Sign up to the newsletter"), async () => { +await page.AddLocatorHandlerAsync(page.GetByText("Sign up to the newsletter"), async () => { await page.GetByRole(AriaRole.Button, new() { Name = "No thanks" }).ClickAsync(); }); // Write the test as usual. -await Page.GotoAsync("https://example.com"); +await page.GotoAsync("https://example.com"); await page.GetByRole("button", new() { Name = "Start here" }).ClickAsync(); ``` @@ -3243,12 +3243,12 @@ await page.get_by_role("button", name="Start here").click() ```csharp // Setup the handler. -await page.AddLocatorHandlerAsync(Page.GetByText("Confirm your security details"), async () => { +await page.AddLocatorHandlerAsync(page.GetByText("Confirm your security details"), async () => { await page.GetByRole(AriaRole.Button, new() { Name = "Remind me later" }).ClickAsync(); }); // Write the test as usual. -await Page.GotoAsync("https://example.com"); +await page.GotoAsync("https://example.com"); await page.GetByRole("button", new() { Name = "Start here" }).ClickAsync(); ``` @@ -3305,7 +3305,7 @@ await page.AddLocatorHandlerAsync(page.Locator("body"), async () => { }, new() { NoWaitAfter = true }); // Write the test as usual. -await Page.GotoAsync("https://example.com"); +await page.GotoAsync("https://example.com"); await page.GetByRole("button", new() { Name = "Start here" }).ClickAsync(); ``` @@ -3336,7 +3336,7 @@ await page.add_locator_handler(page.get_by_label("Close"), handler, times=1) ``` ```csharp -await page.AddLocatorHandlerAsync(Page.GetByText("Sign up to the newsletter"), async locator => { +await page.AddLocatorHandlerAsync(page.GetByText("Sign up to the newsletter"), async locator => { await locator.ClickAsync(); }, new() { Times = 1 }); ``` @@ -4734,7 +4734,7 @@ with page.expect_navigation(): await page.RunAndWaitForNavigationAsync(async () => { // This action triggers the navigation after a timeout. - await Page.GetByText("Navigate after timeout").ClickAsync(); + await page.GetByText("Navigate after timeout").ClickAsync(); }); // The method continues after navigation has finished @@ -4865,13 +4865,13 @@ second_request = second.value // Waits for the next request with the specified url. await page.RunAndWaitForRequestAsync(async () => { - await Page.GetByText("trigger request").ClickAsync(); + await page.GetByText("trigger request").ClickAsync(); }, "http://example.com/resource"); // Alternative way with a predicate. await page.RunAndWaitForRequestAsync(async () => { - await Page.GetByText("trigger request").ClickAsync(); + await page.GetByText("trigger request").ClickAsync(); }, request => request.Url == "https://example.com" && request.Method == "GET"); ``` @@ -5009,13 +5009,13 @@ return response.ok // Waits for the next response with the specified url. await page.RunAndWaitForResponseAsync(async () => { - await Page.GetByText("trigger response").ClickAsync(); + await page.GetByText("trigger response").ClickAsync(); }, "http://example.com/resource"); // Alternative way with a predicate. await page.RunAndWaitForResponseAsync(async () => { - await Page.GetByText("trigger response").ClickAsync(); + await page.GetByText("trigger response").ClickAsync(); }, response => response.Url == "https://example.com" && response.Status == 200 && response.Request.Method == "GET"); ``` diff --git a/docs/src/api/class-request.md b/docs/src/api/class-request.md index e7ab7dcbfa..e13d9de69f 100644 --- a/docs/src/api/class-request.md +++ b/docs/src/api/class-request.md @@ -214,7 +214,7 @@ print(response.request.redirected_from.url) # "http://example.com" ``` ```csharp -var response = await Page.GotoAsync("http://www.microsoft.com"); +var response = await page.GotoAsync("http://www.microsoft.com"); Console.WriteLine(response.Request.RedirectedFrom?.Url); // http://www.microsoft.com ``` @@ -241,7 +241,7 @@ print(response.request.redirected_from) # None ``` ```csharp -var response = await Page.GotoAsync("https://www.google.com"); +var response = await page.GotoAsync("https://www.google.com"); Console.WriteLine(response.Request.RedirectedFrom?.Url); // null ``` @@ -368,7 +368,7 @@ print(request.timing) ```csharp var request = await page.RunAndWaitForRequestFinishedAsync(async () => { - await Page.GotoAsync("https://www.microsoft.com"); + await page.GotoAsync("https://www.microsoft.com"); }); Console.WriteLine(request.Timing.ResponseEnd); ``` diff --git a/docs/src/api/class-tracing.md b/docs/src/api/class-tracing.md index 78a95fa0d2..065896925f 100644 --- a/docs/src/api/class-tracing.md +++ b/docs/src/api/class-tracing.md @@ -250,7 +250,7 @@ var page = await context.NewPageAsync(); await page.GotoAsync("https://playwright.dev"); await context.Tracing.StartChunkAsync(); -await Page.GetByText("Get Started").ClickAsync(); +await page.GetByText("Get Started").ClickAsync(); // Everything between StartChunkAsync and StopChunkAsync will be recorded in the trace. await context.Tracing.StopChunkAsync(new() { diff --git a/docs/src/api/params.md b/docs/src/api/params.md index 0f8b0be963..9b8d3de31b 100644 --- a/docs/src/api/params.md +++ b/docs/src/api/params.md @@ -1505,19 +1505,19 @@ page.getByText(Pattern.compile("^hello$", Pattern.CASE_INSENSITIVE)); ```csharp // Matches -Page.GetByText("world"); +page.GetByText("world"); // Matches first
-Page.GetByText("Hello world"); +page.GetByText("Hello world"); // Matches second
-Page.GetByText("Hello", new() { Exact = true }); +page.GetByText("Hello", new() { Exact = true }); // Matches both
s -Page.GetByText(new Regex("Hello")); +page.GetByText(new Regex("Hello")); // Matches second
-Page.GetByText(new Regex("^hello$", RegexOptions.IgnoreCase)); +page.GetByText(new Regex("^hello$", RegexOptions.IgnoreCase)); ``` **Details** diff --git a/docs/src/events.md b/docs/src/events.md index 983bd66719..5bf13597ee 100644 --- a/docs/src/events.md +++ b/docs/src/events.md @@ -152,11 +152,11 @@ void listener(object sender, IRequest request) Console.WriteLine("Request finished: " + request.Url); }; page.RequestFinished += listener; -await Page.GotoAsync("https://wikipedia.org"); +await page.GotoAsync("https://wikipedia.org"); // Remove previously added listener. page.RequestFinished -= listener; -await Page.GotoAsync("https://www.openstreetmap.org/"); +await page.GotoAsync("https://www.openstreetmap.org/"); ``` ## Adding one-off listeners diff --git a/docs/src/network.md b/docs/src/network.md index 3fdd8d24ce..e1cd4ed656 100644 --- a/docs/src/network.md +++ b/docs/src/network.md @@ -476,7 +476,7 @@ page.goto("https://example.com") await page.RouteAsync("**/api/fetch_data", async route => { await route.FulfillAsync(new() { Status = 200, Body = testData }); }); -await Page.GotoAsync("https://example.com"); +await page.GotoAsync("https://example.com"); ``` ## Modify requests diff --git a/tests/library/inspector/cli-codegen-1.spec.ts b/tests/library/inspector/cli-codegen-1.spec.ts index d55b33e12f..a876a25e47 100644 --- a/tests/library/inspector/cli-codegen-1.spec.ts +++ b/tests/library/inspector/cli-codegen-1.spec.ts @@ -774,7 +774,7 @@ var page1 = await page.RunAndWaitForPopupAsync(async () => expect.soft(sources.get('C#')!.text).toContain(` await page.GotoAsync("about:blank"); -await Page.GetByText("link").ClickAsync();`); +await page.GetByText("link").ClickAsync();`); expect(page.url()).toContain('about:blank#foo'); }); @@ -819,7 +819,7 @@ await Page.GetByText("link").ClickAsync();`); .setButton(MouseButton.MIDDLE));`); expect(sources.get('C#')!.text).toContain(` -await Page.GetByText("Click me").ClickAsync(new LocatorClickOptions +await page.GetByText("Click me").ClickAsync(new LocatorClickOptions { Button = MouseButton.Middle, });`);