Skip to content

Commit 4b5ad33

Browse files
authored
doc: fix first .net script (#6922)
1 parent 82041b2 commit 4b5ad33

File tree

2 files changed

+33
-36
lines changed

2 files changed

+33
-36
lines changed

docs/src/intro-csharp.md

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -19,43 +19,34 @@ dotnet tool install --global Microsoft.Playwright.CLI
1919
Create a console project and add the Playwright dependency.
2020

2121
```bash
22+
# Create project
2223
dotnet new console -n pw_demo
2324
cd pw_demo
24-
dotnet add package Microsoft.Playwright --prerelease
25-
```
2625

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

29-
```bash
30-
playwright install
29+
# Install local Playwright tool and use it to install browsers.
30+
dotnet new tool-manifest
31+
dotnet tool install Microsoft.Playwright.CLI --version 1.0.0-alpha-1
32+
dotnet playwright install
3133
```
3234

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

3537
```csharp
36-
using System;
38+
using Microsoft.Playwright;
3739
using System.Threading.Tasks;
38-
using Microsoft.Playwright.NUnit;
39-
using NUnit.Framework;
4040

41-
namespace PlaywrightTests
41+
class Program
4242
{
43-
[Parallelizable(ParallelScope.Self)]
44-
public class MyTest : PageTest
43+
public static async Task Main()
4544
{
46-
[Test]
47-
public async Task ShouldAdd()
48-
{
49-
int result = await Page.EvaluateAsync<int>("() => 7 + 3");
50-
Assert.AreEqual(10, result);
51-
}
52-
53-
[Test]
54-
public async Task ShouldMultiply()
55-
{
56-
int result = await Page.EvaluateAsync<int>("() => 7 * 3");
57-
Assert.AreEqual(21, result);
58-
}
45+
using var playwright = await Playwright.CreateAsync();
46+
await using var browser = await playwright.Chromium.LaunchAsync();
47+
var page = await browser.NewPageAsync();
48+
await page.GotoAsync("https://playwright.dev/dotnet");
49+
await page.ScreenshotAsync(new PageScreenshotOptions { Path = "screenshot.png" });
5950
}
6051
}
6152
```
@@ -77,30 +68,38 @@ await playwright.Firefox.LaunchAsync(new BrowserTypeLaunchOptions { Headless = f
7768
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).
7869

7970
```bash
80-
dotnet new console -n pw_test
71+
# Create new project.
72+
dotnet new nunit -n PlaywrightTests
8173
cd pw_test
74+
75+
# Install dependencies
8276
dotnet add package Microsoft.Playwright --prerelease
8377
dotnet add package Microsoft.Playwright.NUnit --prerelease
84-
```
8578

86-
Ensure browsers necessary for testing are installed.
87-
88-
```bash
89-
playwright install
79+
# Install local Playwright tool and use it to install browsers.
80+
dotnet new tool-manifest
81+
dotnet tool install Microsoft.Playwright.CLI --version 1.0.0-alpha-1
82+
dotnet playwright install
9083
```
9184

92-
Create a PageTests.cs file.
85+
Edit UnitTest1.cs file.
9386
```csharp
94-
using System;
9587
using System.Threading.Tasks;
9688
using Microsoft.Playwright.NUnit;
9789
using NUnit.Framework;
9890

99-
namespace ExampleTest
91+
namespace PlaywrightTests
10092
{
10193
[Parallelizable(ParallelScope.Self)]
102-
public class PageTests : PageTest
94+
public class Tests : PageTest
10395
{
96+
[Test]
97+
public async Task ShouldAdd()
98+
{
99+
int result = await Page.EvaluateAsync<int>("() => 7 + 3");
100+
Assert.AreEqual(10, result);
101+
}
102+
104103
[Test]
105104
public async Task ShouldMultiply()
106105
{
@@ -112,7 +111,6 @@ namespace ExampleTest
112111
```
113112

114113
```bash
115-
dotnet build
116114
dotnet test -- NUnit.NumberOfTestWorkers=5
117115
```
118116

docs/src/test-runners-csharp.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ namespace PlaywrightTests
5959
Run your tests against Chromium
6060

6161
```bash
62-
dotnet build
6362
dotnet test
6463
```
6564

0 commit comments

Comments
 (0)