Skip to content

Commit

Permalink
feat(roll): roll to ToT Playwright (17-10-24) (#1565)
Browse files Browse the repository at this point in the history
  • Loading branch information
playwrightmachine authored Oct 17, 2024
1 parent c31dbcf commit 74ee03e
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 19 deletions.
38 changes: 19 additions & 19 deletions dotnet/docs/locators.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ These are the recommended built-in locators.
- [Page.GetByTestId()](#locate-by-test-id) to locate an element based on its `data-testid` attribute (other attributes can be configured).

```csharp
await page.GetByLabel("User Name").FillAsync("John");
await Page.GetByLabel("User Name").FillAsync("John");

await page.GetByLabel("Password").FillAsync("secret-password");
await Page.GetByLabel("Password").FillAsync("secret-password");

await page.GetByRole(AriaRole.Button, new() { Name = "Sign in" }).ClickAsync();
await Page.GetByRole(AriaRole.Button, new() { Name = "Sign in" }).ClickAsync();

await Expect(Page.GetByText("Welcome, John!")).ToBeVisibleAsync();
```
Expand All @@ -50,7 +50,7 @@ For example, consider the following DOM structure.
Locate the element by its role of `button` with name "Sign in".

```csharp
await page.GetByRole(AriaRole.Button, new() { Name = "Sign in" }).ClickAsync();
await Page.GetByRole(AriaRole.Button, new() { Name = "Sign in" }).ClickAsync();
```

:::note
Expand All @@ -60,7 +60,7 @@ Use the [code generator](./codegen.mdx) to generate a locator, and then edit it
Every time a locator is used for an action, an up-to-date DOM element is located in the page. In the snippet below, the underlying DOM element will be located twice, once prior to every action. This means that if the DOM changes in between the calls due to re-render, the new element corresponding to the locator will be used.

```csharp
var locator = page.GetByRole(AriaRole.Button, new() { Name = "Sign in" });
var locator = Page.GetByRole(AriaRole.Button, new() { Name = "Sign in" });

await locator.HoverAsync();
await locator.ClickAsync();
Expand All @@ -69,7 +69,7 @@ await locator.ClickAsync();
Note that all methods that create a locator, such as [Page.GetByLabel()](/api/class-page.mdx#page-get-by-label), are also available on the [Locator] and [FrameLocator] classes, so you can chain them and iteratively narrow down your locator.

```csharp
var locator = page
var locator = Page
.FrameLocator("#my-frame")
.GetByRole(AriaRole.Button, new() { Name = "Sign in" });

Expand Down Expand Up @@ -109,11 +109,11 @@ await Expect(Page
.GetByRole(AriaRole.Heading, new() { Name = "Sign up" }))
.ToBeVisibleAsync();

await page
await Page
.GetByRole(AriaRole.Checkbox, new() { Name = "Subscribe" })
.CheckAsync();

await page
await Page
.GetByRole(AriaRole.Button, new() {
NameRegex = new Regex("submit", RegexOptions.IgnoreCase)
})
Expand Down Expand Up @@ -150,7 +150,7 @@ For example, consider the following DOM structure.
You can fill the input after locating it by the label text:

```csharp
await page.GetByLabel("Password").FillAsync("secret");
await Page.GetByLabel("Password").FillAsync("secret");
```

:::note[When to use label locators]
Expand All @@ -176,7 +176,7 @@ For example, consider the following DOM structure.
You can fill the input after locating it by the placeholder text:

```csharp
await page
await Page
.GetByPlaceholder("[email protected]")
.FillAsync("[email protected]");
```
Expand Down Expand Up @@ -252,7 +252,7 @@ For example, consider the following DOM structure.
You can click on the image after locating it by the text alternative:

```csharp
await page.GetByAltText("playwright logo").ClickAsync();
await Page.GetByAltText("playwright logo").ClickAsync();
```

:::note[When to use alt locators]
Expand Down Expand Up @@ -304,7 +304,7 @@ For example, consider the following DOM structure.
You can locate the element by its test id:

```csharp
await page.GetByTestId("directions").ClickAsync();
await Page.GetByTestId("directions").ClickAsync();
```

:::note[When to use testid locators]
Expand Down Expand Up @@ -336,27 +336,27 @@ In your html you can now use `data-pw` as your test id instead of the default `d
And then locate the element as you would normally do:

```csharp
await page.GetByTestId("directions").ClickAsync();
await Page.GetByTestId("directions").ClickAsync();
```

### Locate by CSS or XPath

If you absolutely must use CSS or XPath locators, you can use [Page.Locator()](/api/class-page.mdx#page-locator) to create a locator that takes a selector describing how to find an element in the page. Playwright supports CSS and XPath selectors, and auto-detects them if you omit `css=` or `xpath=` prefix.

```csharp
await page.Locator("css=button").ClickAsync();
await page.Locator("xpath=//button").ClickAsync();
await Page.Locator("css=button").ClickAsync();
await Page.Locator("xpath=//button").ClickAsync();

await page.Locator("button").ClickAsync();
await page.Locator("//button").ClickAsync();
await Page.Locator("button").ClickAsync();
await Page.Locator("//button").ClickAsync();
```

XPath and CSS selectors can be tied to the DOM structure or implementation. These selectors can break when the DOM structure changes. Long CSS or XPath chains below are an example of a **bad practice** that leads to unstable tests:

```csharp
await page.Locator("#tsf > div:nth-child(2) > div.A8SBwf > div.RNNXgb > div > div.a4bIc > input").ClickAsync();
await Page.Locator("#tsf > div:nth-child(2) > div.A8SBwf > div.RNNXgb > div > div.a4bIc > input").ClickAsync();

await page.Locator("//*[@id='tsf']/div[2]/div[1]/div[1]/div/div[2]/input").ClickAsync();
await Page.Locator("//*[@id='tsf']/div[2]/div[1]/div[1]/div/div[2]/input").ClickAsync();
```

:::note[When to use this]
Expand Down
48 changes: 48 additions & 0 deletions nodejs/docs/api/class-test.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,54 @@ test('less readable', async ({ page }) => {

---

### test.fail.only {#test-fail-only}

<font size="2" style={{position: "relative", top: "-20px"}}>Added in: v1.49</font><x-search>test.test.fail.only</x-search>

You can use `test.fail.only` to focus on a specific test that is expected to fail. This is particularly useful when debugging a failing test or working on a specific issue.

To declare a focused "failing" test:
* `test.fail.only(title, body)`
* `test.fail.only(title, details, body)`

**Usage**

You can declare a focused failing test, so that Playwright runs only this test and ensures it actually fails.

```js
import { test, expect } from '@playwright/test';
test.fail.only('focused failing test', async ({ page }) => {
// This test is expected to fail
});
test('not in the focused group', async ({ page }) => {
// This test will not run
});
```

**Arguments**
- `title` [string] *(optional)*<a aria-hidden="true" tabIndex="-1" class="list-anchor-link" id="test-fail-only-option-title"/><a href="#test-fail-only-option-title" class="list-anchor">#</a>

Test title.
- `details` [Object] *(optional)*<a aria-hidden="true" tabIndex="-1" class="list-anchor-link" id="test-fail-only-option-details"/><a href="#test-fail-only-option-details" class="list-anchor">#</a>
- `tag` [string] | [Array]&lt;[string]&gt; *(optional)*


- `annotation` [Object] | [Array]&lt;[Object]&gt; *(optional)*
- `type` [string]


- `description` [string] *(optional)*



See [test.describe()](/api/class-test.mdx#test-describe) for test details description.
- `body` [function]\([Fixtures], [TestInfo]\) *(optional)*<a aria-hidden="true" tabIndex="-1" class="list-anchor-link" id="test-fail-only-option-body"/><a href="#test-fail-only-option-body" class="list-anchor">#</a>

Test body that takes one or two arguments: an object with fixtures and optional [TestInfo].

---

### test.fixme {#test-fixme}

<font size="2" style={{position: "relative", top: "-20px"}}>Added in: v1.10</font><x-search>test.test.fixme</x-search>
Expand Down
2 changes: 2 additions & 0 deletions nodejs/docs/release-notes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import LiteYouTube from '@site/src/components/LiteYouTube';

## Version 1.48

<LiteYouTube id="VGlkSBkMVCQ" title="Playwright 1.48" />

### WebSocket routing

New methods [page.routeWebSocket()](/api/class-page.mdx#page-route-web-socket) and [browserContext.routeWebSocket()](/api/class-browsercontext.mdx#browser-context-route-web-socket) allow to intercept, modify and mock WebSocket connections initiated in the page. Below is a simple example that mocks WebSocket communication by responding to a `"request"` with a `"response"`.
Expand Down

0 comments on commit 74ee03e

Please sign in to comment.