docs: update docs to show role selectors (#18063)

This commit is contained in:
Debbie O'Brien 2022-10-14 16:55:52 +02:00 committed by GitHub
parent ef8268fb89
commit 2efa96a882
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 11 deletions

View file

@ -36,7 +36,7 @@ public class Tests : PageTest
await Expect(Page).ToHaveTitleAsync(new Regex("Playwright")); await Expect(Page).ToHaveTitleAsync(new Regex("Playwright"));
// create a locator // 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. // Expect an attribute "to be strictly equal" to the value.
await Expect(getStarted).ToHaveAttributeAsync("href", "/docs/intro"); await Expect(getStarted).ToHaveAttributeAsync("href", "/docs/intro");
@ -71,7 +71,7 @@ public class UnitTest1 : PageTest
await Expect(Page).ToHaveTitleAsync(new Regex("Playwright")); await Expect(Page).ToHaveTitleAsync(new Regex("Playwright"));
// create a locator // 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. // Expect an attribute "to be strictly equal" to the value.
await Expect(getStarted).ToHaveAttributeAsync("href", "/docs/intro"); 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. [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 ```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 Expect(getStarted).ToHaveAttributeAsync("href", "/docs/installation");
await getStarted.ClickAsync(); 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). [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 ```csharp
await Expect(Page.Locator("text=Installation")).ToBeVisibleAsync(); await Expect(Page.GetByRole(AriaRole.Heading, new() { NameString = "Installation" })).ToBeVisibleAsync();
``` ```

View file

@ -28,7 +28,7 @@ test('homepage has Playwright in title and get started link linking to the intro
await expect(page).toHaveTitle(/Playwright/); await expect(page).toHaveTitle(/Playwright/);
// create a locator // 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. // Expect an attribute "to be strictly equal" to the value.
await expect(getStarted).toHaveAttribute('href', '/docs/intro'); 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/); await expect(page).toHaveTitle(/Playwright/);
// create a locator // 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. // Expect an attribute "to be strictly equal" to the value.
await expect(getStarted).toHaveAttribute('href', '/docs/intro'); 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. [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 ```js
const getStarted = page.getByText('Get Started'); const getStarted = page.getByRole('link', { name: 'Get started' });
await expect(getStarted).toHaveAttribute('href', '/docs/installation'); await expect(getStarted).toHaveAttribute('href', '/docs/installation');
await getStarted.click(); await getStarted.click();
@ -92,7 +92,7 @@ await getStarted.click();
```js ```js
await expect(page.getByText('Installation')).toBeVisible(); await expect(page.getByRole('heading', { name: 'Installation' })).toBeVisible();
``` ```

View file

@ -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")) expect(page).to_have_title(re.compile("Playwright"))
# create a locator # 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 an attribute "to be strictly equal" to the value.
expect(get_started).to_have_attribute("href", "/docs/intro") expect(get_started).to_have_attribute("href", "/docs/intro")
@ -51,7 +51,7 @@ expect(page).to_have_title(re.compile("Playwright"))
```python ```python
from playwright.sync_api import expect 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") expect(get_started).to_have_attribute("href", "/docs/installation")
get_started.click() get_started.click()
@ -63,7 +63,7 @@ get_started.click()
```python ```python
from playwright.sync_api import expect 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()
``` ```