Skip to content

Commit

Permalink
feat(roll): roll to ToT Playwright (26-10-22) (microsoft#817)
Browse files Browse the repository at this point in the history
  • Loading branch information
playwrightmachine authored Oct 26, 2022
1 parent 4af769d commit 59548d2
Show file tree
Hide file tree
Showing 25 changed files with 533 additions and 89 deletions.
15 changes: 15 additions & 0 deletions dotnet/docs/api/class-elementhandle.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ await locator.ClickAsync();

- [ElementHandle.BoundingBoxAsync()](/api/class-elementhandle.mdx#element-handle-bounding-box)
- [ElementHandle.CheckAsync(options)](/api/class-elementhandle.mdx#element-handle-check)
- [ElementHandle.ClearAsync(options)](/api/class-elementhandle.mdx#element-handle-clear)
- [ElementHandle.ClickAsync(options)](/api/class-elementhandle.mdx#element-handle-click)
- [ElementHandle.ContentFrameAsync()](/api/class-elementhandle.mdx#element-handle-content-frame)
- [ElementHandle.DblClickAsync(options)](/api/class-elementhandle.mdx#element-handle-dblclick)
Expand Down Expand Up @@ -135,6 +136,20 @@ If the element is detached from the DOM at any moment during the action, this me

When all steps combined have not finished during the specified `timeout`, this method throws a [TimeoutError]. Passing zero timeout disables this.

## ElementHandle.ClearAsync(options) {#element-handle-clear}

<font size="2" style={{position: "relative", top: "-20px"}}>Added in: v1.28</font>

- `options` &#60;`ElementHandleClearOptions?`&#62;
- `Force`<a aria-hidden="true" tabindex="-1" class="list-anchor-link" id="element-handle-clear-option-force"/> &#60;[bool]?&#62; Whether to bypass the [actionability](../actionability.mdx) checks. Defaults to `false`.<a href="#element-handle-clear-option-force" class="list-anchor">#</a>
- `NoWaitAfter`<a aria-hidden="true" tabindex="-1" class="list-anchor-link" id="element-handle-clear-option-no-wait-after"/> &#60;[bool]?&#62; Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to inaccessible pages. Defaults to `false`.<a href="#element-handle-clear-option-no-wait-after" class="list-anchor">#</a>
- `Timeout`<a aria-hidden="true" tabindex="-1" class="list-anchor-link" id="element-handle-clear-option-timeout"/> &#60;[double]?&#62; Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [BrowserContext.SetDefaultTimeout(timeout)](/api/class-browsercontext.mdx#browser-context-set-default-timeout) or [Page.SetDefaultTimeout(timeout)](/api/class-page.mdx#page-set-default-timeout) methods.<a href="#element-handle-clear-option-timeout" class="list-anchor">#</a>
- returns:<a aria-hidden="true" tabindex="-1" class="list-anchor-link" id="element-handle-clear-return"/> &#60;[void]&#62;<a href="#element-handle-clear-return" class="list-anchor">#</a>

This method waits for [actionability](../actionability.mdx) checks, focuses the element, clears it and triggers an `input` event after clearing.

If the target element is not an `<input>`, `<textarea>` or `[contenteditable]` element, this method throws an error. However, if the element is inside the `<label>` element that has an associated [control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), the control will be cleared instead.

## ElementHandle.ClickAsync(options) {#element-handle-click}

<font size="2" style={{position: "relative", top: "-20px"}}>Added in: v1.8</font>
Expand Down
17 changes: 17 additions & 0 deletions dotnet/docs/api/class-frame.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class FrameExamples
- [Frame.AddStyleTagAsync(options)](/api/class-frame.mdx#frame-add-style-tag)
- [Frame.CheckAsync(selector, options)](/api/class-frame.mdx#frame-check)
- [Frame.ChildFrames](/api/class-frame.mdx#frame-child-frames)
- [Frame.ClearAsync(selector, options)](/api/class-frame.mdx#frame-clear)
- [Frame.ClickAsync(selector, options)](/api/class-frame.mdx#frame-click)
- [Frame.ContentAsync()](/api/class-frame.mdx#frame-content)
- [Frame.DblClickAsync(selector, options)](/api/class-frame.mdx#frame-dblclick)
Expand Down Expand Up @@ -165,6 +166,22 @@ When all steps combined have not finished during the specified `timeout`, this m

- returns:<a aria-hidden="true" tabindex="-1" class="list-anchor-link" id="frame-child-frames-return"/> &#60;[IEnumerable]<[Frame]>&#62;<a href="#frame-child-frames-return" class="list-anchor">#</a>

## Frame.ClearAsync(selector, options) {#frame-clear}

<font size="2" style={{position: "relative", top: "-20px"}}>Added in: v1.28</font>

- `selector`<a aria-hidden="true" tabindex="-1" class="list-anchor-link" id="frame-clear-option-selector"/> &#60;[string]&#62; A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](../selectors.mdx) for more details.<a href="#frame-clear-option-selector" class="list-anchor">#</a>
- `options` &#60;`FrameClearOptions?`&#62;
- `Force`<a aria-hidden="true" tabindex="-1" class="list-anchor-link" id="frame-clear-option-force"/> &#60;[bool]?&#62; Whether to bypass the [actionability](../actionability.mdx) checks. Defaults to `false`.<a href="#frame-clear-option-force" class="list-anchor">#</a>
- `NoWaitAfter`<a aria-hidden="true" tabindex="-1" class="list-anchor-link" id="frame-clear-option-no-wait-after"/> &#60;[bool]?&#62; Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to inaccessible pages. Defaults to `false`.<a href="#frame-clear-option-no-wait-after" class="list-anchor">#</a>
- `Strict`<a aria-hidden="true" tabindex="-1" class="list-anchor-link" id="frame-clear-option-strict"/> &#60;[bool]?&#62; When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call throws an exception.<a href="#frame-clear-option-strict" class="list-anchor">#</a>
- `Timeout`<a aria-hidden="true" tabindex="-1" class="list-anchor-link" id="frame-clear-option-timeout"/> &#60;[double]?&#62; Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [BrowserContext.SetDefaultTimeout(timeout)](/api/class-browsercontext.mdx#browser-context-set-default-timeout) or [Page.SetDefaultTimeout(timeout)](/api/class-page.mdx#page-set-default-timeout) methods.<a href="#frame-clear-option-timeout" class="list-anchor">#</a>
- returns:<a aria-hidden="true" tabindex="-1" class="list-anchor-link" id="frame-clear-return"/> &#60;[void]&#62;<a href="#frame-clear-return" class="list-anchor">#</a>

This method waits for an element matching `selector`, waits for [actionability](../actionability.mdx) checks, focuses the element, clears it and triggers an `input` event after clearing.

If the target element is not an `<input>`, `<textarea>` or `[contenteditable]` element, this method throws an error. However, if the element is inside the `<label>` element that has an associated [control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), the control will be cleared instead.

## Frame.ClickAsync(selector, options) {#frame-click}

<font size="2" style={{position: "relative", top: "-20px"}}>Added in: v1.8</font>
Expand Down
26 changes: 26 additions & 0 deletions dotnet/docs/api/class-locator.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ Locators are the central piece of Playwright's auto-waiting and retry-ability. I

- [Locator.AllInnerTextsAsync()](/api/class-locator.mdx#locator-all-inner-texts)
- [Locator.AllTextContentsAsync()](/api/class-locator.mdx#locator-all-text-contents)
- [Locator.BlurAsync(options)](/api/class-locator.mdx#locator-blur)
- [Locator.BoundingBoxAsync(options)](/api/class-locator.mdx#locator-bounding-box)
- [Locator.CheckAsync(options)](/api/class-locator.mdx#locator-check)
- [Locator.ClearAsync(options)](/api/class-locator.mdx#locator-clear)
- [Locator.ClickAsync(options)](/api/class-locator.mdx#locator-click)
- [Locator.CountAsync()](/api/class-locator.mdx#locator-count)
- [Locator.DblClickAsync(options)](/api/class-locator.mdx#locator-dblclick)
Expand Down Expand Up @@ -81,6 +83,16 @@ Returns an array of `node.innerText` values for all matching nodes.

Returns an array of `node.textContent` values for all matching nodes.

## Locator.BlurAsync(options) {#locator-blur}

<font size="2" style={{position: "relative", top: "-20px"}}>Added in: v1.28</font>

- `options` &#60;`LocatorBlurOptions?`&#62;
- `Timeout`<a aria-hidden="true" tabindex="-1" class="list-anchor-link" id="locator-blur-option-timeout"/> &#60;[double]?&#62; Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [BrowserContext.SetDefaultTimeout(timeout)](/api/class-browsercontext.mdx#browser-context-set-default-timeout) or [Page.SetDefaultTimeout(timeout)](/api/class-page.mdx#page-set-default-timeout) methods.<a href="#locator-blur-option-timeout" class="list-anchor">#</a>
- returns:<a aria-hidden="true" tabindex="-1" class="list-anchor-link" id="locator-blur-return"/> &#60;[void]&#62;<a href="#locator-blur-return" class="list-anchor">#</a>

Calls [blur](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/blur) on the element.

## Locator.BoundingBoxAsync(options) {#locator-bounding-box}

<font size="2" style={{position: "relative", top: "-20px"}}>Added in: v1.14</font>
Expand Down Expand Up @@ -132,6 +144,20 @@ If the element is detached from the DOM at any moment during the action, this me

When all steps combined have not finished during the specified `timeout`, this method throws a [TimeoutError]. Passing zero timeout disables this.

## Locator.ClearAsync(options) {#locator-clear}

<font size="2" style={{position: "relative", top: "-20px"}}>Added in: v1.28</font>

- `options` &#60;`LocatorClearOptions?`&#62;
- `Force`<a aria-hidden="true" tabindex="-1" class="list-anchor-link" id="locator-clear-option-force"/> &#60;[bool]?&#62; Whether to bypass the [actionability](../actionability.mdx) checks. Defaults to `false`.<a href="#locator-clear-option-force" class="list-anchor">#</a>
- `NoWaitAfter`<a aria-hidden="true" tabindex="-1" class="list-anchor-link" id="locator-clear-option-no-wait-after"/> &#60;[bool]?&#62; Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to inaccessible pages. Defaults to `false`.<a href="#locator-clear-option-no-wait-after" class="list-anchor">#</a>
- `Timeout`<a aria-hidden="true" tabindex="-1" class="list-anchor-link" id="locator-clear-option-timeout"/> &#60;[double]?&#62; Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [BrowserContext.SetDefaultTimeout(timeout)](/api/class-browsercontext.mdx#browser-context-set-default-timeout) or [Page.SetDefaultTimeout(timeout)](/api/class-page.mdx#page-set-default-timeout) methods.<a href="#locator-clear-option-timeout" class="list-anchor">#</a>
- returns:<a aria-hidden="true" tabindex="-1" class="list-anchor-link" id="locator-clear-return"/> &#60;[void]&#62;<a href="#locator-clear-return" class="list-anchor">#</a>

This method waits for [actionability](../actionability.mdx) checks, focuses the element, clears it and triggers an `input` event after clearing.

If the target element is not an `<input>`, `<textarea>` or `[contenteditable]` element, this method throws an error. However, if the element is inside the `<label>` element that has an associated [control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), the control will be cleared instead.

## Locator.ClickAsync(options) {#locator-click}

<font size="2" style={{position: "relative", top: "-20px"}}>Added in: v1.14</font>
Expand Down
17 changes: 17 additions & 0 deletions dotnet/docs/api/class-page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ page.Load -= PageLoadHandler;
- [Page.APIRequest](/api/class-page.mdx#page-request)
- [Page.BringToFrontAsync()](/api/class-page.mdx#page-bring-to-front)
- [Page.CheckAsync(selector, options)](/api/class-page.mdx#page-check)
- [Page.ClearAsync(selector, options)](/api/class-page.mdx#page-clear)
- [Page.ClickAsync(selector, options)](/api/class-page.mdx#page-click)
- [Page.CloseAsync(options)](/api/class-page.mdx#page-close)
- [Page.ContentAsync()](/api/class-page.mdx#page-content)
Expand Down Expand Up @@ -493,6 +494,22 @@ When all steps combined have not finished during the specified `timeout`, this m

Shortcut for main frame's [Frame.CheckAsync(selector, options)](/api/class-frame.mdx#frame-check).

## Page.ClearAsync(selector, options) {#page-clear}

<font size="2" style={{position: "relative", top: "-20px"}}>Added in: v1.28</font>

- `selector`<a aria-hidden="true" tabindex="-1" class="list-anchor-link" id="page-clear-option-selector"/> &#60;[string]&#62; A selector to search for an element. If there are multiple elements satisfying the selector, the first will be used. See [working with selectors](../selectors.mdx) for more details.<a href="#page-clear-option-selector" class="list-anchor">#</a>
- `options` &#60;`PageClearOptions?`&#62;
- `Force`<a aria-hidden="true" tabindex="-1" class="list-anchor-link" id="page-clear-option-force"/> &#60;[bool]?&#62; Whether to bypass the [actionability](../actionability.mdx) checks. Defaults to `false`.<a href="#page-clear-option-force" class="list-anchor">#</a>
- `NoWaitAfter`<a aria-hidden="true" tabindex="-1" class="list-anchor-link" id="page-clear-option-no-wait-after"/> &#60;[bool]?&#62; Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to inaccessible pages. Defaults to `false`.<a href="#page-clear-option-no-wait-after" class="list-anchor">#</a>
- `Strict`<a aria-hidden="true" tabindex="-1" class="list-anchor-link" id="page-clear-option-strict"/> &#60;[bool]?&#62; When true, the call requires selector to resolve to a single element. If given selector resolves to more than one element, the call throws an exception.<a href="#page-clear-option-strict" class="list-anchor">#</a>
- `Timeout`<a aria-hidden="true" tabindex="-1" class="list-anchor-link" id="page-clear-option-timeout"/> &#60;[double]?&#62; Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [BrowserContext.SetDefaultTimeout(timeout)](/api/class-browsercontext.mdx#browser-context-set-default-timeout) or [Page.SetDefaultTimeout(timeout)](/api/class-page.mdx#page-set-default-timeout) methods.<a href="#page-clear-option-timeout" class="list-anchor">#</a>
- returns:<a aria-hidden="true" tabindex="-1" class="list-anchor-link" id="page-clear-return"/> &#60;[void]&#62;<a href="#page-clear-return" class="list-anchor">#</a>

This method waits for an element matching `selector`, waits for [actionability](../actionability.mdx) checks, focuses the element, clears it and triggers an `input` event after clearing. Note that you can pass an empty string to clear the input field.

If the target element is not an `<input>`, `<textarea>` or `[contenteditable]` element, this method throws an error. However, if the element is inside the `<label>` element that has an associated [control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), the control will be cleared instead.

## Page.ClickAsync(selector, options) {#page-click}

<font size="2" style={{position: "relative", top: "-20px"}}>Added in: v1.8</font>
Expand Down
19 changes: 16 additions & 3 deletions dotnet/docs/browser-contexts.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,22 @@ import TabItem from '@theme/TabItem';

Tests written with Playwright execute in isolated clean-slate environments called browser contexts. This isolation model improves reproducibility and prevents cascading test failures.

[BrowserContext]s are equivalent to incognito-like profiles, they are fast and cheap to create and completely isolated, even when running in a single browser. Playwright creates a context for each test, and provides a default [Page] in that context.
## What is Test Isolation?

When using Playwright as a Test Runner, this happens out of the box for each test. Otherwise, you can create browser contexts manually.
Test Isolation is when each test is completely isolated from another test. Every test runs independently from any other test. This means that each test has it's own local storage, session storage, cookies etc. Playwright achieves this using [BrowserContext]s which are equivalent to incognito-like profiles. They are fast and cheap to create and are completely isolated, even when running in a single browser. Playwright creates a context for each test, and provides a default [Page] in that context.

## Why is Test Isolation Important?
- No failure carry-over. If one test fails it doesn't affect the other test.
- Easy to debug errors or flakiness, because you can run just a single test as many times as you'd like.
- Don't have to think about the order when running in parallel, sharding, etc.

## Two Ways of Test Isolation

There are two different strategies when it comes to Test Isolation: start from scratch or cleanup in between. The problem with cleaning up in between tests is that it can be easy to forget to clean up and some things are impossible to clean up such as "visited links". State from one test can leak into the next test which could cause your test to fail and make debugging harder as the problem comes from another test. Starting from scratch means everything is new, so if the test fails you only have to look within that test to debug.

## How Playwright Achieves Test Isolation

Playwright uses browser contexts to achieve Test Isolation. Each test has it's own Browser Context. Running the test creates a new browser context each time. When using Playwright as a Test Runner, browser contexts are created by default. Otherwise, you can create browser contexts manually.

```csharp
await using var browser = playwright.Chromium.LaunchAsync();
Expand All @@ -19,7 +32,7 @@ var page = await context.NewPageAsync();

Browser contexts can also be used to emulate multi-page scenarios involving mobile devices, permissions, locale and color scheme. Check out our [Emulation](./emulation.mdx) guide for more details.

## Multiple contexts in a single test
## Multiple Contexts in a Single Test

Playwright can create multiple browser contexts within a single scenario. This is useful when you want to test for multi-user functionality, like a chat.

Expand Down
Loading

0 comments on commit 59548d2

Please sign in to comment.