From 2efa96a882fa2c1fcd2c1eb6199ba079ca4d6a41 Mon Sep 17 00:00:00 2001 From: Debbie O'Brien Date: Fri, 14 Oct 2022 16:55:52 +0200 Subject: [PATCH] docs: update docs to show role selectors (#18063) --- docs/src/writing-tests-csharp.md | 8 ++++---- docs/src/writing-tests-js.md | 8 ++++---- docs/src/writing-tests-python.md | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/docs/src/writing-tests-csharp.md b/docs/src/writing-tests-csharp.md index f5fb453b20..6a0511e548 100644 --- a/docs/src/writing-tests-csharp.md +++ b/docs/src/writing-tests-csharp.md @@ -36,7 +36,7 @@ public class Tests : PageTest await Expect(Page).ToHaveTitleAsync(new Regex("Playwright")); // create a locator - var getStarted = Page.Locator("text=Get Started"); + var getStarted = Page.GetByRole(AriaRole.Link, new() { NameString = "Get started" }); // Expect an attribute "to be strictly equal" to the value. await Expect(getStarted).ToHaveAttributeAsync("href", "/docs/intro"); @@ -71,7 +71,7 @@ public class UnitTest1 : PageTest await Expect(Page).ToHaveTitleAsync(new Regex("Playwright")); // create a locator - var getStarted = Page.Locator("text=Get Started"); + var getStarted = Page.GetByRole(AriaRole.Link, new() { NameString = "Get started" }); // Expect an attribute "to be strictly equal" to the value. await Expect(getStarted).ToHaveAttributeAsync("href", "/docs/intro"); @@ -102,7 +102,7 @@ await Expect(Page).ToHaveTitleAsync(new Regex("Playwright")); [Locators](./locators.md) are the central piece of Playwright's auto-waiting and retry-ability. Locators represent a way to find element(s) on the page at any moment and are used to perform actions on elements such as `.ClickAsync` `.FillAsync` etc. Custom locators can be created with the [`method: Page.locator`] method. ```csharp -var getStarted = Page.Locator("text=Get Started"); +var getStarted = Page.GetByRole(AriaRole.Link, new() { NameString = "Get started" }); await Expect(getStarted).ToHaveAttributeAsync("href", "/docs/installation"); await getStarted.ClickAsync(); @@ -111,7 +111,7 @@ await getStarted.ClickAsync(); [Selectors](./selectors.md) are strings that are used to create Locators. Playwright supports many different selectors like [Text](./selectors.md#text-selector), [CSS](./selectors.md#css-selector), [XPath](./selectors.md#xpath-selectors) and many more. Learn more about available selectors and how to pick one in this [in-depth guide](./selectors.md). ```csharp -await Expect(Page.Locator("text=Installation")).ToBeVisibleAsync(); +await Expect(Page.GetByRole(AriaRole.Heading, new() { NameString = "Installation" })).ToBeVisibleAsync(); ``` diff --git a/docs/src/writing-tests-js.md b/docs/src/writing-tests-js.md index b8d36a1c16..5416ce6b1a 100644 --- a/docs/src/writing-tests-js.md +++ b/docs/src/writing-tests-js.md @@ -28,7 +28,7 @@ test('homepage has Playwright in title and get started link linking to the intro await expect(page).toHaveTitle(/Playwright/); // create a locator - const getStarted = page.getByText('Get Started'); + const getStarted = page.getByRole('link', { name: 'Get started' }); // Expect an attribute "to be strictly equal" to the value. await expect(getStarted).toHaveAttribute('href', '/docs/intro'); @@ -51,7 +51,7 @@ test('homepage has Playwright in title and get started link linking to the intro await expect(page).toHaveTitle(/Playwright/); // create a locator - const getStarted = page.getByText('Get Started'); + const getStarted = page.getByRole('link', { name: 'Get started' }); // Expect an attribute "to be strictly equal" to the value. await expect(getStarted).toHaveAttribute('href', '/docs/intro'); @@ -82,7 +82,7 @@ await expect(page).toHaveTitle(/Playwright/); [Locators](./locators.md) are the central piece of Playwright's auto-waiting and retry-ability. Locators represent a way to find element(s) on the page at any moment and are used to perform actions on elements such as `.click` `.fill` etc. Custom locators can be created with the [`method: Page.locator`] method. ```js -const getStarted = page.getByText('Get Started'); +const getStarted = page.getByRole('link', { name: 'Get started' }); await expect(getStarted).toHaveAttribute('href', '/docs/installation'); await getStarted.click(); @@ -92,7 +92,7 @@ await getStarted.click(); ```js -await expect(page.getByText('Installation')).toBeVisible(); +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 1fc0deb137..097ecdaa08 100644 --- a/docs/src/writing-tests-python.md +++ b/docs/src/writing-tests-python.md @@ -19,7 +19,7 @@ def test_homepage_has_Playwright_in_title_and_get_started_link_linking_to_the_in expect(page).to_have_title(re.compile("Playwright")) # create a locator - get_started = page.locator("text=Get Started") + get_started = page.get_by_role("link", name="Get started"); # Expect an attribute "to be strictly equal" to the value. expect(get_started).to_have_attribute("href", "/docs/intro") @@ -51,7 +51,7 @@ expect(page).to_have_title(re.compile("Playwright")) ```python from playwright.sync_api import expect -get_started = page.locator("text=Get Started") +get_started = page.get_by_role("link", name="Get started"); expect(get_started).to_have_attribute("href", "/docs/installation") get_started.click() @@ -63,7 +63,7 @@ get_started.click() ```python from playwright.sync_api import expect -expect(page.locator("text=Installation")).to_be_visible() +expect(page.get_by_role("heading", name="Installation")).to_be_visible() ```