From f6d63f7c99ceb4c8302a080a482345651b4bd221 Mon Sep 17 00:00:00 2001 From: Debbie O'Brien Date: Tue, 1 Aug 2023 22:04:04 +0200 Subject: [PATCH] docs: update example test assertion (#24554) uses different assertion to make test visually better when using trace viewer etc and is more realistic example --- docs/src/writing-tests-csharp.md | 6 ++++-- docs/src/writing-tests-java.md | 5 +++-- docs/src/writing-tests-js.md | 4 ++-- docs/src/writing-tests-python.md | 4 ++-- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/docs/src/writing-tests-csharp.md b/docs/src/writing-tests-csharp.md index 6542ae5c78..3818b9f039 100644 --- a/docs/src/writing-tests-csharp.md +++ b/docs/src/writing-tests-csharp.md @@ -47,8 +47,10 @@ public class Tests : PageTest // Click the get started link. await getStarted.ClickAsync(); - // Expects the URL to contain intro. - await Expect(Page).ToHaveURLAsync(new Regex(".*intro")); + // Expects page to have a heading with the name of Installation. + await Expect(page + .GetByRole(AriaRole.Heading, new() { Name = "Installation" })) + .ToBeVisibleAsync(); } } ``` diff --git a/docs/src/writing-tests-java.md b/docs/src/writing-tests-java.md index ababca5a06..c6e10731fa 100644 --- a/docs/src/writing-tests-java.md +++ b/docs/src/writing-tests-java.md @@ -35,8 +35,9 @@ public class App { // Click the get started link. getStarted.click(); - // Expects the URL to contain intro. - assertThat(page).hasURL(Pattern.compile(".*intro")); + // Expects page to have a heading with the name of Installation. + assertThat(page.getByRole(AriaRole.HEADING, + new Page.GetByRoleOptions().setName("Installation"))).isVisible(); } } } diff --git a/docs/src/writing-tests-js.md b/docs/src/writing-tests-js.md index cad8e0861a..bebfa460e9 100644 --- a/docs/src/writing-tests-js.md +++ b/docs/src/writing-tests-js.md @@ -47,8 +47,8 @@ test('get started link', async ({ page }) => { // Click the get started link. await page.getByRole('link', { name: 'Get started' }).click(); - // Expects the URL to contain intro. - await expect(page).toHaveURL(/.*intro/); + // Expects page to have a heading with the name of Installation. + await expect(page.getByRole('heading', { name: 'Installation' })).toBeVisible(); }); ``` diff --git a/docs/src/writing-tests-python.md b/docs/src/writing-tests-python.md index 1ec2a6d876..45efdb2223 100644 --- a/docs/src/writing-tests-python.md +++ b/docs/src/writing-tests-python.md @@ -27,8 +27,8 @@ def test_homepage_has_Playwright_in_title_and_get_started_link_linking_to_the_in # Click the get started link. get_started.click() - # Expects the URL to contain intro. - expect(page).to_have_url(re.compile(".*intro")) + # Expects page to have a heading with the name of Installation. + expect(page.get_by_role("heading", name="Installation")).to_be_visible() ```