Skip to content

Commit

Permalink
feat(roll): roll to ToT Playwright (08-08-22) (microsoft#716)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
playwrightmachine and github-actions[bot] authored Aug 8, 2022
1 parent 67e7ea4 commit 5ad83c8
Show file tree
Hide file tree
Showing 17 changed files with 334 additions and 141 deletions.
13 changes: 12 additions & 1 deletion dotnet/docs/codegen.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,22 @@ import TabItem from '@theme/TabItem';

Playwright comes with the ability to generate tests out of the box and is a great way to quickly get started with testing. It will open two windows, a browser window where you interact with the website you wish to test and the Playwright Inspector window where you can record your tests, copy the tests, clear your tests as well as change the language of your tests.

**You will learn**
- [How to generate tests with Codegen](/codegen.mdx#running-codegen)
- [How to emulate viewport size](/codegen.mdx#emulate-viewport-size)
- [How to emulate devices](/codegen.mdx#emulate-devices)
- [How to emulate color scheme](/codegen.mdx#emulate-color-scheme)
- [How to emulate geolocation, language and timezone](/codegen.mdx#emulate-geolocation-language-and-timezone)
- [How to preserve authenticated state](/codegen.mdx#preserve-authenticated-state)
- [How to record using a custom setup](/codegen.mdx#record-using-custom-setup)

## Running Codegen

```bash
pwsh bin\Debug\netX\playwright.ps1 codegen playwright.dev
```

Run `codegen` and perform actions in the browser. Playwright will generate the code for the user interactions. `codegen` will attempt to generate resilient text-based selectors.
Run `codegen` and perform actions in the browser. Playwright will generate the code for the user interactions. `Codegen` will attempt to generate resilient text-based selectors.

<img width="1183" alt="Codegen generating code for tests for playwright.dev website" src="https://user-images.githubusercontent.com/13063165/181852815-971c10da-0b55-4e54-8a73-77e1e825193c.png" />

Expand Down
4 changes: 2 additions & 2 deletions dotnet/docs/intro.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ namespace PlaywrightTests;
public class Tests : PageTest
{
[Test]
async public Task HomepageHasPlaywrightInTitleAndGetStartedLinkLinkingtoTheIntroPage()
public async Task HomepageHasPlaywrightInTitleAndGetStartedLinkLinkingtoTheIntroPage()
{
await Page.GotoAsync("https://playwright.dev");

Expand Down Expand Up @@ -121,7 +121,7 @@ namespace PlaywrightTests;
public class UnitTest1 : PageTest
{
[TestMethod]
async public Task HomepageHasPlaywrightInTitleAndGetStartedLinkLinkingtoTheIntroPage()
public async Task HomepageHasPlaywrightInTitleAndGetStartedLinkLinkingtoTheIntroPage()
{
await Page.GotoAsync("https://playwright.dev");

Expand Down
61 changes: 55 additions & 6 deletions dotnet/docs/test-assertions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,36 @@ await Expect(locator).ToContainTextAsync("substring");
await Expect(locator).ToContainTextAsync(new Regex("\\d messages"));
```

Note that if array is passed as an expected value, entire lists of elements can be asserted:
If you pass an array as an expected value, the expectations are:
1. Locator resolves to a list of elements.
1. Elements from a **subset** of this list contain text from the expected array, respectively.
1. The matching subset of elements has the same order as the expected array.
1. Each text value from the expected array is matched by some element from the list.

For example, consider the following list:

```html
<ul>
<li>Item Text 1</li>
<li>Item Text 2</li>
<li>Item Text 3</li>
</ul>
```

Let's see how we can use the assertion:

```csharp
var locator = Page.Locator("list > .list-item");
await Expect(locator).ToContainTextAsync(new string[] { "Text 1", "Text 4", "Text 5" });
// ✓ Contains the right items in the right order
await Expect(Page.Locator("ul > li")).ToContainTextAsync(new string[] {"Text 1", "Text 3", "Text 4"});

// ✖ Wrong order
await Expect(Page.Locator("ul > li")).ToContainTextAsync(new string[] {"Text 3", "Text 2"});

// ✖ No item contains this text
await Expect(Page.Locator("ul > li")).ToContainTextAsync(new string[] {"Some 33"});

// ✖ Locator points to the outer list element, not to the list items
await Expect(Page.Locator("ul")).ToContainTextAsync(new string[] {"Text 3"});
```

## Expect(Locator).ToHaveAttributeAsync(name, value, options) {#locator-assertions-to-have-attribute}
Expand Down Expand Up @@ -345,11 +370,35 @@ await Expect(locator).ToHaveTextAsync(new Regex("Welcome, Test User"));
await Expect(locator).ToHaveTextAsync(new Regex("Welcome, .*"));
```

Note that if array is passed as an expected value, entire lists of elements can be asserted:
If you pass an array as an expected value, the expectations are:
1. Locator resolves to a list of elements.
1. The number of elements equals the number of expected values in the array.
1. Elements from the list have text matching expected array values, one by one, in order.

For example, consider the following list:

```html
<ul>
<li>Text 1</li>
<li>Text 2</li>
<li>Text 3</li>
</ul>
```

Let's see how we can use the assertion:

```csharp
var locator = Page.Locator("list > .component");
await Expect(locator).toHaveTextAsync(new string[]{ "Text 1", "Text 2", "Text 3" });
// ✓ Has the right items in the right order
await Expect(Page.Locator("ul > li")).ToHaveTextAsync(new string[] {"Text 1", "Text 2", "Text 3"});

// ✖ Wrong order
await Expect(Page.Locator("ul > li")).ToHaveTextAsync(new string[] {"Text 3", "Text 2", "Text 1"});

// ✖ Last item does not match
await Expect(Page.Locator("ul > li")).ToHaveTextAsync(new string[] {"Text 1", "Text 2", "Text"});

// ✖ Locator points to the outer list element, not to the list items
await Expect(Page.Locator("ul")).ToHaveTextAsync(new string[] {"Text 1", "Text 2", "Text 3"});
```

## Expect(Locator).ToHaveValueAsync(value, options) {#locator-assertions-to-have-value}
Expand Down
18 changes: 9 additions & 9 deletions dotnet/docs/test-runners.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace PlaywrightTests;
public class MyTest : PageTest
{
[Test]
async public Task ShouldHaveTheCorrectSlogan()
public async Task ShouldHaveTheCorrectSlogan()
{
await Page.GotoAsync("https://playwright.dev");
await Expect(Page.Locator("text=enables reliable end-to-end testing for modern web apps")).ToBeVisibleAsync();
Expand Down Expand Up @@ -138,7 +138,7 @@ dotnet test
You can also choose specifically which tests to run, using the [filtering capabilities](https://docs.microsoft.com/en-us/dotnet/core/testing/selective-unit-tests?pivots=nunit):

```bash
dotnet test --filter "Name~ShouldAdd"
dotnet test --filter "Name~Slogan"
```

### Running NUnit tests in Parallel
Expand Down Expand Up @@ -184,7 +184,7 @@ public class MyTest : PageTest

### Customizing [Browser]/launch options

[Browser]/launch options can be override either using a run settings file or by setting the run settings options directly via the CLI. See the following example:
[Browser]/launch options can be overridden either using a run settings file or by setting the run settings options directly via the CLI. See the following example:

```xml
<?xml version="1.0" encoding="utf-8"?>
Expand Down Expand Up @@ -263,7 +263,7 @@ If you want to enable debugging, you can set the `DEBUG` variable to `pw:api` as

### Base NUnit classes for Playwright

There are few base classes available to you in `Microsoft.Playwright.NUnit` namespace:
There are a few base classes available to you in `Microsoft.Playwright.NUnit` namespace:

|Test |Description|
|--------------|-----------|
Expand Down Expand Up @@ -300,14 +300,14 @@ namespace PlaywrightTests;
public class UnitTest1: PageTest
{
[TestMethod]
async public Task ShouldHaveTheCorrectSlogan()
public async Task ShouldHaveTheCorrectSlogan()
{
await Page.GotoAsync("https://playwright.dev");
await Expect(Page.Locator("text=enables reliable end-to-end testing for modern web apps")).ToBeVisibleAsync();
}

[TestMethod]
async public Task ShouldHaveTheCorrectTitle()
public async Task ShouldHaveTheCorrectTitle()
{
await Page.GotoAsync("https://playwright.dev");
var title = Page.Locator(".navbar__inner .navbar__title");
Expand Down Expand Up @@ -397,7 +397,7 @@ dotnet test
You can also choose specifically which tests to run, using the [filtering capabilities](https://docs.microsoft.com/en-us/dotnet/core/testing/selective-unit-tests?pivots=mstest):

```bash
dotnet test --filter "Name~ShouldAdd"
dotnet test --filter "Name~Slogan"
```

### Running MSTest tests in Parallel
Expand Down Expand Up @@ -449,7 +449,7 @@ public class UnitTest1 : PageTest

### Customizing [Browser]/launch options

[Browser]/launch options can be override either using a run settings file or by setting the run settings options directly via the CLI. See the following example:
[Browser]/launch options can be overridden either using a run settings file or by setting the run settings options directly via the CLI. See the following example:

```xml
<?xml version="1.0" encoding="utf-8"?>
Expand Down Expand Up @@ -531,7 +531,7 @@ If you want to enable debugging, you can set the `DEBUG` variable to `pw:api` as

### Base MSTest classes for Playwright

There are few base classes available to you in `Microsoft.Playwright.MSTest` namespace:
There are a few base classes available to you in `Microsoft.Playwright.MSTest` namespace:

|Test |Description|
|--------------|-----------|
Expand Down
4 changes: 2 additions & 2 deletions dotnet/docs/writing-tests.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace PlaywrightTests;
public class Tests : PageTest
{
[Test]
async public Task HomepageHasPlaywrightInTitleAndGetStartedLinkLinkingtoTheIntroPage()
public async Task HomepageHasPlaywrightInTitleAndGetStartedLinkLinkingtoTheIntroPage()
{
await Page.GotoAsync("https://playwright.dev");

Expand Down Expand Up @@ -58,7 +58,7 @@ namespace PlaywrightTests;
public class UnitTest1 : PageTest
{
[TestMethod]
async public Task HomepageHasPlaywrightInTitleAndGetStartedLinkLinkingtoTheIntroPage()
public async Task HomepageHasPlaywrightInTitleAndGetStartedLinkLinkingtoTheIntroPage()
{
await Page.GotoAsync("https://playwright.dev");

Expand Down
13 changes: 12 additions & 1 deletion java/docs/codegen.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,22 @@ import TabItem from '@theme/TabItem';

Playwright comes with the ability to generate tests out of the box and is a great way to quickly get started with testing. It will open two windows, a browser window where you interact with the website you wish to test and the Playwright Inspector window where you can record your tests, copy the tests, clear your tests as well as change the language of your tests.

**You will learn**
- [How to generate tests with Codegen](/codegen.mdx#running-codegen)
- [How to emulate viewport size](/codegen.mdx#emulate-viewport-size)
- [How to emulate devices](/codegen.mdx#emulate-devices)
- [How to emulate color scheme](/codegen.mdx#emulate-color-scheme)
- [How to emulate geolocation, language and timezone](/codegen.mdx#emulate-geolocation-language-and-timezone)
- [How to preserve authenticated state](/codegen.mdx#preserve-authenticated-state)
- [How to record using a custom setup](/codegen.mdx#record-using-custom-setup)

## Running Codegen

```bash
mvn exec:java -e -Dexec.mainClass=com.microsoft.playwright.CLI -Dexec.args="codegen playwright.dev"
```

Run `codegen` and perform actions in the browser. Playwright will generate the code for the user interactions. `codegen` will attempt to generate resilient text-based selectors.
Run `codegen` and perform actions in the browser. Playwright will generate the code for the user interactions. `Codegen` will attempt to generate resilient text-based selectors.

<img width="1183" alt="Codegen generating code for tests for playwright.dev website" src="https://user-images.githubusercontent.com/13063165/181852815-971c10da-0b55-4e54-8a73-77e1e825193c.png" />

Expand Down
59 changes: 55 additions & 4 deletions java/docs/test-assertions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,36 @@ Ensures the [Locator] points to an element that contains the given text. You can
assertThat(page.locator(".title")).containsText("substring");
```

Note that if array is passed as an expected value, entire lists of elements can be asserted:
If you pass an array as an expected value, the expectations are:
1. Locator resolves to a list of elements.
1. Elements from a **subset** of this list contain text from the expected array, respectively.
1. The matching subset of elements has the same order as the expected array.
1. Each text value from the expected array is matched by some element from the list.

For example, consider the following list:

```html
<ul>
<li>Item Text 1</li>
<li>Item Text 2</li>
<li>Item Text 3</li>
</ul>
```

Let's see how we can use the assertion:

```java
assertThat(page.locator("list > .list-item")).containsText(new String[] {"Text 1", "Text 4", "Text 5"});
// ✓ Contains the right items in the right order
assertThat(page.locator("ul > li")).containsText(new String[] {"Text 1", "Text 3", "Text 4"});

// ✖ Wrong order
assertThat(page.locator("ul > li")).containsText(new String[] {"Text 3", "Text 2"});

// ✖ No item contains this text
assertThat(page.locator("ul > li")).containsText(new String[] {"Some 33"});

// ✖ Locator points to the outer list element, not to the list items
assertThat(page.locator("ul")).containsText(new String[] {"Text 3"});
```

## assertThat(locator).hasAttribute(name, value[, options]) {#locator-assertions-to-have-attribute}
Expand Down Expand Up @@ -322,10 +348,35 @@ assertThat(page.locator(".title")).hasText("Welcome, Test User");
assertThat(page.locator(".title")).hasText(Pattern.compile("Welcome, .*"));
```

Note that if array is passed as an expected value, entire lists of elements can be asserted:
If you pass an array as an expected value, the expectations are:
1. Locator resolves to a list of elements.
1. The number of elements equals the number of expected values in the array.
1. Elements from the list have text matching expected array values, one by one, in order.

For example, consider the following list:

```html
<ul>
<li>Text 1</li>
<li>Text 2</li>
<li>Text 3</li>
</ul>
```

Let's see how we can use the assertion:

```java
assertThat(page.locator("list > .component")).hasText(new String[] {"Text 1", "Text 2", "Text 3"});
// ✓ Has the right items in the right order
assertThat(page.locator("ul > li")).hasText(new String[] {"Text 1", "Text 2", "Text 3"});

// ✖ Wrong order
assertThat(page.locator("ul > li")).hasText(new String[] {"Text 3", "Text 2", "Text 1"});

// ✖ Last item does not match
assertThat(page.locator("ul > li")).hasText(new String[] {"Text 1", "Text 2", "Text"});

// ✖ Locator points to the outer list element, not to the list items
assertThat(page.locator("ul")).hasText(new String[] {"Text 1", "Text 2", "Text 3"});
```

## assertThat(locator).hasValue(value[, options]) {#locator-assertions-to-have-value}
Expand Down
9 changes: 0 additions & 9 deletions nodejs/docs/api/class-reporter.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ Additionally, [reporter.onStdOut(chunk, test, result)](/api/class-reporter.mdx#r
- [reporter.onBegin(config, suite)](/api/class-reporter.mdx#reporter-on-begin)
- [reporter.onEnd(result)](/api/class-reporter.mdx#reporter-on-end)
- [reporter.onError(error)](/api/class-reporter.mdx#reporter-on-error)
- [reporter.onExit()](/api/class-reporter.mdx#reporter-on-exit)
- [reporter.onStdErr(chunk, test, result)](/api/class-reporter.mdx#reporter-on-std-err)
- [reporter.onStdOut(chunk, test, result)](/api/class-reporter.mdx#reporter-on-std-out)
- [reporter.onStepBegin(test, result, step)](/api/class-reporter.mdx#reporter-on-step-begin)
Expand Down Expand Up @@ -172,14 +171,6 @@ Called after all tests has been run, or testing has been interrupted. Note that

Called on some global error, for example unhandled exception in the worker process.

## reporter.onExit() {#reporter-on-exit}

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

- returns:<a aria-hidden="true" tabindex="-1" class="list-anchor-link" id="reporter-on-exit-return"/> &#60;[Promise]<[void]>&#62;<a href="#reporter-on-exit-return" class="list-anchor">#</a>

Called before the test runner will terminate. Useful to perform work after all reporters have finished, for example open some UI. Fore regular reporting, you should use [reporter.onEnd(result)](/api/class-reporter.mdx#reporter-on-end) instead.

## reporter.onStdErr(chunk, test, result) {#reporter-on-std-err}

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

0 comments on commit 5ad83c8

Please sign in to comment.