@@ -19,43 +19,34 @@ dotnet tool install --global Microsoft.Playwright.CLI
19
19
Create a console project and add the Playwright dependency.
20
20
21
21
``` bash
22
+ # Create project
22
23
dotnet new console -n pw_demo
23
24
cd pw_demo
24
- dotnet add package Microsoft.Playwright --prerelease
25
- ```
26
25
27
- Ensure browsers necessary for testing are installed.
26
+ # Install dependencies
27
+ dotnet add package Microsoft.Playwright --prerelease
28
28
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
31
33
```
32
34
33
35
Create a ` Program.cs ` that will navigate to ` https://playwright.dev/dotnet ` and take a screenshot in Chromium.
34
36
35
37
``` csharp
36
- using System ;
38
+ using Microsoft . Playwright ;
37
39
using System .Threading .Tasks ;
38
- using Microsoft .Playwright .NUnit ;
39
- using NUnit .Framework ;
40
40
41
- namespace PlaywrightTests
41
+ class Program
42
42
{
43
- [Parallelizable (ParallelScope .Self )]
44
- public class MyTest : PageTest
43
+ public static async Task Main ()
45
44
{
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" });
59
50
}
60
51
}
61
52
```
@@ -77,30 +68,38 @@ await playwright.Firefox.LaunchAsync(new BrowserTypeLaunchOptions { Headless = f
77
68
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 ) .
78
69
79
70
``` bash
80
- dotnet new console -n pw_test
71
+ # Create new project.
72
+ dotnet new nunit -n PlaywrightTests
81
73
cd pw_test
74
+
75
+ # Install dependencies
82
76
dotnet add package Microsoft.Playwright --prerelease
83
77
dotnet add package Microsoft.Playwright.NUnit --prerelease
84
- ```
85
78
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
90
83
```
91
84
92
- Create a PageTests .cs file.
85
+ Edit UnitTest1 .cs file.
93
86
``` csharp
94
- using System ;
95
87
using System .Threading .Tasks ;
96
88
using Microsoft .Playwright .NUnit ;
97
89
using NUnit .Framework ;
98
90
99
- namespace ExampleTest
91
+ namespace PlaywrightTests
100
92
{
101
93
[Parallelizable (ParallelScope .Self )]
102
- public class PageTests : PageTest
94
+ public class Tests : PageTest
103
95
{
96
+ [Test ]
97
+ public async Task ShouldAdd ()
98
+ {
99
+ int result = await Page .EvaluateAsync <int >(" () => 7 + 3" );
100
+ Assert .AreEqual (10 , result );
101
+ }
102
+
104
103
[Test ]
105
104
public async Task ShouldMultiply ()
106
105
{
@@ -112,7 +111,6 @@ namespace ExampleTest
112
111
```
113
112
114
113
``` bash
115
- dotnet build
116
114
dotnet test -- NUnit.NumberOfTestWorkers=5
117
115
```
118
116
0 commit comments