Skip to content

Commit

Permalink
doc: fix first .net script (#6922)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelfeldman authored Jun 5, 2021
1 parent 82041b2 commit 4b5ad33
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 36 deletions.
68 changes: 33 additions & 35 deletions docs/src/intro-csharp.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,43 +19,34 @@ dotnet tool install --global Microsoft.Playwright.CLI
Create a console project and add the Playwright dependency.

```bash
# Create project
dotnet new console -n pw_demo
cd pw_demo
dotnet add package Microsoft.Playwright --prerelease
```

Ensure browsers necessary for testing are installed.
# Install dependencies
dotnet add package Microsoft.Playwright --prerelease

```bash
playwright install
# Install local Playwright tool and use it to install browsers.
dotnet new tool-manifest
dotnet tool install Microsoft.Playwright.CLI --version 1.0.0-alpha-1
dotnet playwright install
```

Create a `Program.cs` that will navigate to `https://playwright.dev/dotnet` and take a screenshot in Chromium.

```csharp
using System;
using Microsoft.Playwright;
using System.Threading.Tasks;
using Microsoft.Playwright.NUnit;
using NUnit.Framework;

namespace PlaywrightTests
class Program
{
[Parallelizable(ParallelScope.Self)]
public class MyTest : PageTest
public static async Task Main()
{
[Test]
public async Task ShouldAdd()
{
int result = await Page.EvaluateAsync<int>("() => 7 + 3");
Assert.AreEqual(10, result);
}

[Test]
public async Task ShouldMultiply()
{
int result = await Page.EvaluateAsync<int>("() => 7 * 3");
Assert.AreEqual(21, result);
}
using var playwright = await Playwright.CreateAsync();
await using var browser = await playwright.Chromium.LaunchAsync();
var page = await browser.NewPageAsync();
await page.GotoAsync("https://playwright.dev/dotnet");
await page.ScreenshotAsync(new PageScreenshotOptions { Path = "screenshot.png" });
}
}
```
Expand All @@ -77,30 +68,38 @@ await playwright.Firefox.LaunchAsync(new BrowserTypeLaunchOptions { Headless = f
You can choose to use NUnit test fixtures that come bundled with Playwright. These fixtures support running tests on multiple browser engines in parallel, out of the box. Learn more about [Playwright with NUnit](./test-runners.md).

```bash
dotnet new console -n pw_test
# Create new project.
dotnet new nunit -n PlaywrightTests
cd pw_test

# Install dependencies
dotnet add package Microsoft.Playwright --prerelease
dotnet add package Microsoft.Playwright.NUnit --prerelease
```

Ensure browsers necessary for testing are installed.

```bash
playwright install
# Install local Playwright tool and use it to install browsers.
dotnet new tool-manifest
dotnet tool install Microsoft.Playwright.CLI --version 1.0.0-alpha-1
dotnet playwright install
```

Create a PageTests.cs file.
Edit UnitTest1.cs file.
```csharp
using System;
using System.Threading.Tasks;
using Microsoft.Playwright.NUnit;
using NUnit.Framework;

namespace ExampleTest
namespace PlaywrightTests
{
[Parallelizable(ParallelScope.Self)]
public class PageTests : PageTest
public class Tests : PageTest
{
[Test]
public async Task ShouldAdd()
{
int result = await Page.EvaluateAsync<int>("() => 7 + 3");
Assert.AreEqual(10, result);
}

[Test]
public async Task ShouldMultiply()
{
Expand All @@ -112,7 +111,6 @@ namespace ExampleTest
```

```bash
dotnet build
dotnet test -- NUnit.NumberOfTestWorkers=5
```

Expand Down
1 change: 0 additions & 1 deletion docs/src/test-runners-csharp.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ namespace PlaywrightTests
Run your tests against Chromium

```bash
dotnet build
dotnet test
```

Expand Down

0 comments on commit 4b5ad33

Please sign in to comment.