From a8ee6d0017c51bc6c97f6c500573929fd0bcff19 Mon Sep 17 00:00:00 2001 From: amaechi hope Date: Wed, 30 Oct 2024 16:25:59 +0100 Subject: [PATCH] docs(dotnet): fix code snippets for GetByText --- 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-locator.md | 2 +- docs/src/api/class-page.md | 18 +++++++++--------- docs/src/api/class-tracing.md | 2 +- docs/src/api/params.md | 10 +++++----- docs/src/downloads.md | 2 +- docs/src/events.md | 2 +- docs/src/handles.md | 2 +- docs/src/input.md | 16 ++++++++-------- docs/src/locators.md | 6 +++--- docs/src/mock.md | 6 +++--- docs/src/navigations.md | 4 ++-- docs/src/network.md | 6 +++--- docs/src/other-locators.md | 6 +++--- docs/src/pages.md | 4 ++-- tests/library/inspector/cli-codegen-1.spec.ts | 4 ++-- 19 files changed, 49 insertions(+), 49 deletions(-) diff --git a/docs/src/api/class-browsercontext.md b/docs/src/api/class-browsercontext.md index 8d6c57a3e3..a87c49235e 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 3333d36996..868259cb47 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 c8f54c7380..3fdd658c17 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 82502c8d5e..4a9079cb03 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-locator.md b/docs/src/api/class-locator.md index ba6dc91353..9a776e7465 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-page.md b/docs/src/api/class-page.md index 373649154d..2254221505 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,7 +3186,7 @@ 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(); }); @@ -3243,7 +3243,7 @@ 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(); }); @@ -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-tracing.md b/docs/src/api/class-tracing.md index 065896925f..78a95fa0d2 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 9b8d3de31b..0f8b0be963 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/downloads.md b/docs/src/downloads.md index 824b714d11..5b18e4e95d 100644 --- a/docs/src/downloads.md +++ b/docs/src/downloads.md @@ -61,7 +61,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/events.md b/docs/src/events.md index 23d3c90c3e..060a855638 100644 --- a/docs/src/events.md +++ b/docs/src/events.md @@ -85,7 +85,7 @@ popup.value.goto("https://wikipedia.org") ```csharp var popup = await page.RunAndWaitForPopupAsync(async => { - await page.GetByText("open the popup").ClickAsync(); + await Page.GetByText("open the popup").ClickAsync(); }); await popup.GotoAsync("https://wikipedia.org"); ``` diff --git a/docs/src/handles.md b/docs/src/handles.md index 1a1f368267..b0638fe11a 100644 --- a/docs/src/handles.md +++ b/docs/src/handles.md @@ -327,7 +327,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/input.md b/docs/src/input.md index b6fab7d005..3ec5749891 100644 --- a/docs/src/input.md +++ b/docs/src/input.md @@ -301,23 +301,23 @@ page.get_by_text("Item").click(position={ "x": 0, "y": 0}) await page.GetByRole(AriaRole.Button).ClickAsync(); // Double click -await page.GetByText("Item").DblClickAsync(); +await Page.GetByText("Item").DblClickAsync(); // Right click -await page.GetByText("Item").ClickAsync(new() { Button = MouseButton.Right }); +await Page.GetByText("Item").ClickAsync(new() { Button = MouseButton.Right }); // Shift + click -await page.GetByText("Item").ClickAsync(new() { Modifiers = new[] { KeyboardModifier.Shift } }); +await Page.GetByText("Item").ClickAsync(new() { Modifiers = new[] { KeyboardModifier.Shift } }); // Ctrl + click or Windows and Linux // Meta + click on macOS -await page.GetByText("Item").ClickAsync(new() { Modifiers = new[] { KeyboardModifier.ControlOrMeta } }); +await Page.GetByText("Item").ClickAsync(new() { Modifiers = new[] { KeyboardModifier.ControlOrMeta } }); // Hover over element -await page.GetByText("Item").HoverAsync(); +await Page.GetByText("Item").HoverAsync(); // Click the top left corner -await page.GetByText("Item").ClickAsync(new() { position = new Position { X = 0, Y = 0 } }); +await Page.GetByText("Item").ClickAsync(new() { position = new Position { X = 0, Y = 0 } }); ``` Under the hood, this and other pointer-related methods: @@ -460,7 +460,7 @@ page.get_by_role("textbox").press("$") ```csharp // Hit Enter -await page.GetByText("Submit").PressAsync("Enter"); +await Page.GetByText("Submit").PressAsync("Enter"); // Dispatch Control+Right await page.GetByRole(AriaRole.Textbox).PressAsync("Control+ArrowRight"); @@ -826,7 +826,7 @@ page.get_by_text("Footer text").scroll_into_view_if_needed() ```csharp // Scroll the footer into view, forcing an "infinite list" to load more content -await page.GetByText("Footer text").ScrollIntoViewIfNeededAsync(); +await Page.GetByText("Footer text").ScrollIntoViewIfNeededAsync(); ``` If you would like to control the scrolling more precisely, use [`method: Mouse.wheel`] or [`method: Locator.evaluate`]: diff --git a/docs/src/locators.md b/docs/src/locators.md index 648a654177..446d89645e 100644 --- a/docs/src/locators.md +++ b/docs/src/locators.md @@ -730,7 +730,7 @@ await page.get_by_text("Details").click() page.get_by_text("Details").click() ``` ```csharp -await page.GetByText("Details").ClickAsync(); +await Page.GetByText("Details").ClickAsync(); ``` ```html @@ -1265,7 +1265,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).First).ToBeVisibleAsync(); if (await dialog.IsVisibleAsync()) await page.GetByRole(AriaRole.Button, new() { Name = "Dismiss" }).ClickAsync(); @@ -1441,7 +1441,7 @@ page.getByText("orange").click(); ``` ```csharp -await page.GetByText("orange").ClickAsync(); +await Page.GetByText("orange").ClickAsync(); ``` #### Filter by text diff --git a/docs/src/mock.md b/docs/src/mock.md index 468690904a..cc84887397 100644 --- a/docs/src/mock.md +++ b/docs/src/mock.md @@ -76,7 +76,7 @@ await page.RouteAsync("*/**/api/v1/fruits", async route => { await page.GotoAsync("https://demo.playwright.dev/api-mocking"); // Assert that the Strawberry fruit is visible -await Expect(page.GetByTextAsync("Strawberry")).ToBeVisibleAsync(); +await Expect(Page.GetByTextAsync("Strawberry")).ToBeVisibleAsync(); ``` ```java @@ -188,7 +188,7 @@ await page.RouteAsync("*/**/api/v1/fruits", async (route) => { await page.GotoAsync("https://demo.playwright.dev/api-mocking"); // Assert that the Loquat fruit is visible -await Expect(page.GetByTextAsync("Loquat", new () { Exact = true })).ToBeVisibleAsync(); +await Expect(Page.GetByTextAsync("Loquat", new () { Exact = true })).ToBeVisibleAsync(); ``` ```java @@ -283,7 +283,7 @@ await page.RouteFromHARAsync("./hars/fruit.har", new () { await page.GotoAsync("https://demo.playwright.dev/api-mocking"); // Assert that the fruit is visible -await Expect(page.GetByText("Strawberry")).ToBeVisibleAsync(); +await Expect(Page.GetByText("Strawberry")).ToBeVisibleAsync(); ``` ```java diff --git a/docs/src/navigations.md b/docs/src/navigations.md index 44bab9187a..9e307e43c3 100644 --- a/docs/src/navigations.md +++ b/docs/src/navigations.md @@ -89,7 +89,7 @@ page.get_by_text("example domain").click() // Navigate and click element // Click will auto-wait for the element await page.GotoAsync("https://example.com"); -await page.GetByText("Example Domain").ClickAsync(); +await Page.GetByText("Example Domain").ClickAsync(); ``` For the scenario above, Playwright will wait for the text to become visible, @@ -146,7 +146,7 @@ page.wait_for_url("**/login") ``` ```csharp -await page.GetByText("Click me").ClickAsync(); +await Page.GetByText("Click me").ClickAsync(); await page.WaitForURL("**/login"); ``` diff --git a/docs/src/network.md b/docs/src/network.md index 97c637a806..e1cd4ed656 100644 --- a/docs/src/network.md +++ b/docs/src/network.md @@ -338,7 +338,7 @@ response = response_info.value ```csharp // Use a glob URL pattern var waitForResponseTask = page.WaitForResponseAsync("**/api/fetch_data"); -await page.GetByText("Update").ClickAsync(); +await Page.GetByText("Update").ClickAsync(); var response = await waitForResponseTask; ``` @@ -397,12 +397,12 @@ response = response_info.value ```csharp // Use a regular expression var waitForResponseTask = page.WaitForResponseAsync(new Regex("\\.jpeg$")); -await page.GetByText("Update").ClickAsync(); +await Page.GetByText("Update").ClickAsync(); var response = await waitForResponseTask; // Use a predicate taking a Response object var waitForResponseTask = page.WaitForResponseAsync(r => r.Url.Contains(token)); -await page.GetByText("Update").ClickAsync(); +await Page.GetByText("Update").ClickAsync(); var response = await waitForResponseTask; ``` diff --git a/docs/src/other-locators.md b/docs/src/other-locators.md index c7f6e234d1..e4d612367a 100644 --- a/docs/src/other-locators.md +++ b/docs/src/other-locators.md @@ -464,7 +464,7 @@ parent = page.get_by_role("listitem").filter(has=child) ``` ```csharp -var child = page.GetByText("Hello"); +var child = Page.GetByText("Hello"); var parent = page.GetByRole(AriaRole.Listitem).Filter(new () { Has = child }); ``` @@ -487,7 +487,7 @@ parent = page.get_by_text("Hello").locator('xpath=..') ``` ```csharp -var parent = page.GetByText("Hello").Locator("xpath=.."); +var parent = Page.GetByText("Hello").Locator("xpath=.."); ``` ## React locator @@ -698,7 +698,7 @@ page.get_by_text("Password").fill("secret") ```csharp // Fill the input by targeting the label. -await page.GetByText("Password").FillAsync("secret"); +await Page.GetByText("Password").FillAsync("secret"); ``` However, other methods will target the label itself, for example [`method: LocatorAssertions.toHaveText`] will assert the text content of the label, not the input field. diff --git a/docs/src/pages.md b/docs/src/pages.md index 07e7b59daa..446d5cfbd1 100644 --- a/docs/src/pages.md +++ b/docs/src/pages.md @@ -184,7 +184,7 @@ print(new_page.title()) // Get page after a specific action (e.g. clicking a link) var newPage = await context.RunAndWaitForPageAsync(async () => { - await page.GetByText("open new tab").ClickAsync(); + await Page.GetByText("open new tab").ClickAsync(); }); // Interact with the new page normally await newPage.GetByRole(AriaRole.Button).ClickAsync(); @@ -288,7 +288,7 @@ print(popup.title()) // Get popup after a specific action (e.g., click) var popup = await page.RunAndWaitForPopupAsync(async () => { - await page.GetByText("open the popup").ClickAsync(); + await Page.GetByText("open the popup").ClickAsync(); }); // Interact with the popup normally await popup.GetByRole(AriaRole.Button).ClickAsync(); diff --git a/tests/library/inspector/cli-codegen-1.spec.ts b/tests/library/inspector/cli-codegen-1.spec.ts index a876a25e47..d55b33e12f 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, });`);