Skip to content

Commit 6ab2419

Browse files
kblokactions-user
andauthored
Migrate tests to Nunit (#2276)
* Remove xunit collection * Docs changes * New nunit flow * Remove xunit imports * Replace Playwright.Xunit with Playwright.Nunit * Docs changes * Refactor skip browser * Missing import fixes * PuppeteerFact to PuppeteerTimeout * Use ignore attribute * Replace skip non windows * Remove PuppeteerLoaderCollection * Rename PuppeteerSharp.Xunit project to Nunit * Replace packages * Remove xunit constructor * Replace Fact with test * Replace InlineData with TestCase * Remove theory attribute * Use more PuppeteerTimeout * Add some usings * Assert.Equal to Assert.AreEqual * Empty to IsEmpty * Docs changes * Same to AreSame * Assert.Contains to StringAssert.Contains * ThrowsAnyAsync to ThrowAsync * Migrate .Single * Remove async from Assert.ThrowsAsync * sync test * Migrate DoesNotContain * NotEmpty to IsNotEmpty * more usings * cookies fix * more usings * async to sync * Contains fixes * sync * more usings * More of the same * sync * Improve task queue tests * Fix TaskHelperTests * Fix FrameManagementTests * More simple things * CloseTests fixes * TargetTests fixes * Small things * Green build * CodeFactor * Fix QueryOneTests * Fix WaitForSelectorAriaTests * Fix CDPSession tests * Fix some tests * Fix mouse test * Remove extra browser creation * Fix tests with custom setups * fix goto tests * More fixes * Codefactor * Fix a wait task test --------- Co-authored-by: GitHub Action <[email protected]>
1 parent 7275e9a commit 6ab2419

File tree

198 files changed

+2813
-3165
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

198 files changed

+2813
-3165
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ await using var page = await browser.NewPageAsync();
5757
await page.GoToAsync("http://www.google.com");
5858
await page.ScreenshotAsync(outputFile);
5959
```
60-
<sup><a href='/lib/PuppeteerSharp.Tests/ScreenshotTests/PageScreenshotTests.cs#L63-L71' title='Snippet source file'>snippet source</a> | <a href='#snippet-screenshotasync' title='Start of snippet'>anchor</a></sup>
60+
<sup><a href='/lib/PuppeteerSharp.Tests/ScreenshotTests/PageScreenshotTests.cs#L61-L69' title='Snippet source file'>snippet source</a> | <a href='#snippet-screenshotasync' title='Start of snippet'>anchor</a></sup>
6161
<!-- endSnippet -->
6262

6363
You can also change the view port before generating the screenshot
@@ -71,7 +71,7 @@ await Page.SetViewportAsync(new ViewPortOptions
7171
Height = 500
7272
});
7373
```
74-
<sup><a href='/lib/PuppeteerSharp.Tests/ScreenshotTests/ElementHandleScreenshotTests.cs#L21-L27' title='Snippet source file'>snippet source</a> | <a href='#snippet-setviewportasync' title='Start of snippet'>anchor</a></sup>
74+
<sup><a href='/lib/PuppeteerSharp.Tests/ScreenshotTests/ElementHandleScreenshotTests.cs#L19-L25' title='Snippet source file'>snippet source</a> | <a href='#snippet-setviewportasync' title='Start of snippet'>anchor</a></sup>
7575
<!-- endSnippet -->
7676

7777
### Generate PDF files
@@ -87,7 +87,7 @@ await page.GoToAsync("http://www.google.com"); // In case of fonts being loaded
8787
await page.EvaluateExpressionHandleAsync("document.fonts.ready"); // Wait for fonts to be loaded. Omitting this might result in no text rendered in pdf.
8888
await page.PdfAsync(outputFile);
8989
```
90-
<sup><a href='/lib/PuppeteerSharp.Tests/PageTests/PdfTests.cs#L30-L40' title='Snippet source file'>snippet source</a> | <a href='#snippet-pdfasync' title='Start of snippet'>anchor</a></sup>
90+
<sup><a href='/lib/PuppeteerSharp.Tests/PageTests/PdfTests.cs#L28-L38' title='Snippet source file'>snippet source</a> | <a href='#snippet-pdfasync' title='Start of snippet'>anchor</a></sup>
9191
<!-- endSnippet -->
9292

9393
### Inject HTML
@@ -99,7 +99,7 @@ await using var page = await browser.NewPageAsync();
9999
await page.SetContentAsync("<div>My Receipt</div>");
100100
var result = await page.GetContentAsync();
101101
```
102-
<sup><a href='/lib/PuppeteerSharp.Tests/PageTests/SetContentTests.cs#L21-L27' title='Snippet source file'>snippet source</a> | <a href='#snippet-setcontentasync' title='Start of snippet'>anchor</a></sup>
102+
<sup><a href='/lib/PuppeteerSharp.Tests/PageTests/SetContentTests.cs#L19-L25' title='Snippet source file'>snippet source</a> | <a href='#snippet-setcontentasync' title='Start of snippet'>anchor</a></sup>
103103
<!-- endSnippet -->
104104

105105
### Evaluate Javascript
@@ -112,7 +112,7 @@ var seven = await page.EvaluateExpressionAsync<int>("4 + 3");
112112
var someObject = await page.EvaluateFunctionAsync<dynamic>("(value) => ({a: value})", 5);
113113
Console.WriteLine(someObject.a);
114114
```
115-
<sup><a href='/lib/PuppeteerSharp.Tests/QuerySelectorTests/ElementHandleQuerySelectorEvalTests.cs#L19-L24' title='Snippet source file'>snippet source</a> | <a href='#snippet-evaluate' title='Start of snippet'>anchor</a></sup>
115+
<sup><a href='/lib/PuppeteerSharp.Tests/QuerySelectorTests/ElementHandleQuerySelectorEvalTests.cs#L17-L22' title='Snippet source file'>snippet source</a> | <a href='#snippet-evaluate' title='Start of snippet'>anchor</a></sup>
116116
<!-- endSnippet -->
117117

118118
### Wait For Selector

lib/PuppeteerSharp.Xunit/PuppeteerSharp.Xunit.csproj renamed to lib/PuppeteerSharp.Nunit/PuppeteerSharp.Nunit.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,8 @@
44
<TargetFrameworks Condition="'$(OS)' == 'Windows_NT' ">net48;net6.0</TargetFrameworks>
55
<TargetFrameworks Condition="'$(OS)' != 'Windows_NT' ">net6.0</TargetFrameworks>
66
</PropertyGroup>
7+
<ItemGroup>
8+
<PackageReference Include="NUnit" Version="3.13.3" />
9+
</ItemGroup>
710
<Import Project="../Common/SignAssembly.props" />
811
</Project>

lib/PuppeteerSharp.Xunit/PuppeteerTestAttribute.cs renamed to lib/PuppeteerSharp.Nunit/PuppeteerTestAttribute.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
using System;
2+
using NUnit.Framework;
23

3-
namespace PuppeteerSharp.Xunit
4+
namespace PuppeteerSharp.Nunit
45
{
56
/// <summary>
67
/// Enables decorating test facts with information about the corresponding test in the upstream repository.
78
/// </summary>
89
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
9-
public class PuppeteerTestAttribute : Attribute
10+
public class PuppeteerTestAttribute : TestAttribute
1011
{
1112
/// <summary>
1213
/// Creates a new instance of the attribute.

lib/PuppeteerSharp.Tests/AccessibilityTests/AccessibilityTests.cs

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
using System.Threading.Tasks;
22
using PuppeteerSharp.PageAccessibility;
33
using PuppeteerSharp.Tests.Attributes;
4-
using PuppeteerSharp.Xunit;
5-
using Xunit;
6-
using Xunit.Abstractions;
4+
using PuppeteerSharp.Nunit;
5+
using NUnit.Framework;
76

87
namespace PuppeteerSharp.Tests.AccesibilityTests
98
{
10-
[Collection(TestConstants.TestFixtureCollectionName)]
119
public class AccesibilityTests : PuppeteerPageBaseTest
1210
{
13-
public AccesibilityTests(ITestOutputHelper output) : base(output)
11+
public AccesibilityTests(): base()
1412
{
1513
}
1614

1715
[PuppeteerTest("accessibility.spec.ts", "Accessibility", "should work")]
18-
[SkipBrowserFact(skipFirefox: true)]
16+
[Skip(SkipAttribute.Targets.Firefox)]
1917
public async Task ShouldWork()
2018
{
2119
await Page.SetContentAsync(@"
@@ -114,17 +112,17 @@ await Page.SetContentAsync(@"
114112
};
115113
await Page.FocusAsync("[placeholder='Empty input']");
116114
var snapshot = await Page.Accessibility.SnapshotAsync();
117-
Assert.Equal(nodeToCheck, snapshot);
115+
Assert.AreEqual(nodeToCheck, snapshot);
118116
}
119117

120118
[PuppeteerTest("accessibility.spec.ts", "Accessibility", "should report uninteresting nodes")]
121-
[SkipBrowserFact(skipFirefox: true)]
119+
[Skip(SkipAttribute.Targets.Firefox)]
122120
public async Task ShouldReportUninterestingNodes()
123121
{
124122
await Page.SetContentAsync("<textarea autofocus>hi</textarea>");
125123
await Page.FocusAsync("textarea");
126124

127-
Assert.Equal(
125+
Assert.AreEqual(
128126
new SerializedAXNode
129127
{
130128
Role = "textbox",
@@ -156,7 +154,7 @@ public async Task ShouldReportUninterestingNodes()
156154
}
157155

158156
[PuppeteerTest("accessibility.spec.ts", "Accessibility", "roledescription")]
159-
[SkipBrowserFact(skipFirefox: true)]
157+
[Skip(SkipAttribute.Targets.Firefox)]
160158
public async Task RoleDescription()
161159
{
162160
await Page.SetContentAsync("<div tabIndex=-1 aria-roledescription='foo'>Hi</div>");
@@ -166,25 +164,25 @@ public async Task RoleDescription()
166164
}
167165

168166
[PuppeteerTest("accessibility.spec.ts", "Accessibility", "orientation")]
169-
[SkipBrowserFact(skipFirefox: true)]
167+
[Skip(SkipAttribute.Targets.Firefox)]
170168
public async Task Orientation()
171169
{
172170
await Page.SetContentAsync("<a href='' role='slider' aria-orientation='vertical'>11</a>");
173171
var snapshot = await Page.Accessibility.SnapshotAsync();
174-
Assert.Equal("vertical", snapshot.Children[0].Orientation);
172+
Assert.AreEqual("vertical", snapshot.Children[0].Orientation);
175173
}
176174

177175
[PuppeteerTest("accessibility.spec.ts", "Accessibility", "autocomplete")]
178-
[SkipBrowserFact(skipFirefox: true)]
176+
[Skip(SkipAttribute.Targets.Firefox)]
179177
public async Task AutoComplete()
180178
{
181179
await Page.SetContentAsync("<input type='number' aria-autocomplete='list' />");
182180
var snapshot = await Page.Accessibility.SnapshotAsync();
183-
Assert.Equal("list", snapshot.Children[0].AutoComplete);
181+
Assert.AreEqual("list", snapshot.Children[0].AutoComplete);
184182
}
185183

186184
[PuppeteerTest("accessibility.spec.ts", "Accessibility", "multiselectable")]
187-
[SkipBrowserFact(skipFirefox: true)]
185+
[Skip(SkipAttribute.Targets.Firefox)]
188186
public async Task MultiSelectable()
189187
{
190188
await Page.SetContentAsync("<div role='grid' tabIndex=-1 aria-multiselectable=true>hey</div>");
@@ -193,24 +191,24 @@ public async Task MultiSelectable()
193191
}
194192

195193
[PuppeteerTest("accessibility.spec.ts", "Accessibility", "keyshortcuts")]
196-
[SkipBrowserFact(skipFirefox: true)]
194+
[Skip(SkipAttribute.Targets.Firefox)]
197195
public async Task KeyShortcuts()
198196
{
199197
await Page.SetContentAsync("<div role='grid' tabIndex=-1 aria-keyshortcuts='foo'>hey</div>");
200198
var snapshot = await Page.Accessibility.SnapshotAsync();
201-
Assert.Equal("foo", snapshot.Children[0].KeyShortcuts);
199+
Assert.AreEqual("foo", snapshot.Children[0].KeyShortcuts);
202200
}
203201

204202
[PuppeteerTest("accessibility.spec.ts", "filtering children of leaf nodes", "should not report text nodes inside controls")]
205-
[SkipBrowserFact(skipFirefox: true)]
203+
[Skip(SkipAttribute.Targets.Firefox)]
206204
public async Task ShouldNotReportTextNodesInsideControls()
207205
{
208206
await Page.SetContentAsync(@"
209207
<div role='tablist'>
210208
<div role='tab' aria-selected='true'><b>Tab1</b></div>
211209
<div role='tab'>Tab2</div>
212210
</div>");
213-
Assert.Equal(
211+
Assert.AreEqual(
214212
new SerializedAXNode
215213
{
216214
Role = "RootWebArea",
@@ -234,14 +232,14 @@ await Page.SetContentAsync(@"
234232
}
235233

236234
[PuppeteerTest("accessibility.spec.ts", "filtering children of leaf nodes", "rich text editable fields should have children")]
237-
[SkipBrowserFact(skipFirefox: true)]
235+
[Skip(SkipAttribute.Targets.Firefox)]
238236
public async Task RichTextEditableFieldsShouldHaveChildren()
239237
{
240238
await Page.SetContentAsync(@"
241239
<div contenteditable='true'>
242240
Edit this image: <img src='fakeimage.png' alt='my fake image'>
243241
</div>");
244-
Assert.Equal(
242+
Assert.AreEqual(
245243
new SerializedAXNode
246244
{
247245
Role = "generic",
@@ -265,14 +263,14 @@ await Page.SetContentAsync(@"
265263
}
266264

267265
[PuppeteerTest("accessibility.spec.ts", "filtering children of leaf nodes", "rich text editable fields with role should have children")]
268-
[SkipBrowserFact(skipFirefox: true)]
266+
[Skip(SkipAttribute.Targets.Firefox)]
269267
public async Task RichTextEditableFieldsWithRoleShouldHaveChildren()
270268
{
271269
await Page.SetContentAsync(@"
272270
<div contenteditable='true' role='textbox'>
273271
Edit this image: <img src='fakeimage.png' alt='my fake image'>
274272
</div>");
275-
Assert.Equal(
273+
Assert.AreEqual(
276274
new SerializedAXNode
277275
{
278276
Role = "textbox",
@@ -292,11 +290,11 @@ await Page.SetContentAsync(@"
292290
}
293291

294292
[PuppeteerTest("accessibility.spec.ts", "plaintext contenteditable", "plain text field with role should not have children")]
295-
[SkipBrowserFact(skipFirefox: true)]
293+
[Skip(SkipAttribute.Targets.Firefox)]
296294
public async Task PlainTextFieldWithRoleShouldNotHaveChildren()
297295
{
298296
await Page.SetContentAsync("<div contenteditable='plaintext-only' role='textbox'>Edit this image:<img src='fakeimage.png' alt='my fake image'></div>");
299-
Assert.Equal(
297+
Assert.AreEqual(
300298
new SerializedAXNode
301299
{
302300
Role = "textbox",
@@ -308,26 +306,26 @@ public async Task PlainTextFieldWithRoleShouldNotHaveChildren()
308306
}
309307

310308
[PuppeteerTest("accessibility.spec.ts", "plaintext contenteditable", "plain text field with tabindex and without role should not have content")]
311-
[SkipBrowserFact(skipFirefox: true)]
309+
[Skip(SkipAttribute.Targets.Firefox)]
312310
public async Task PlainTextFieldWithoutRoleShouldNotHaveContent()
313311
{
314312
await Page.SetContentAsync(
315313
"<div contenteditable='plaintext-only'>Edit this image:<img src='fakeimage.png' alt='my fake image'></div>");
316314
var snapshot = await Page.Accessibility.SnapshotAsync();
317-
Assert.Equal("generic", snapshot.Children[0].Role);
318-
Assert.Equal(string.Empty, snapshot.Children[0].Name);
315+
Assert.AreEqual("generic", snapshot.Children[0].Role);
316+
Assert.AreEqual(string.Empty, snapshot.Children[0].Name);
319317
}
320318

321319
[PuppeteerTest("accessibility.spec.ts", "filtering children of leaf nodes", "non editable textbox with role and tabIndex and label should not have children")]
322-
[SkipBrowserFact(skipFirefox: true)]
320+
[Skip(SkipAttribute.Targets.Firefox)]
323321
public async Task NonEditableTextboxWithRoleAndTabIndexAndLabelShouldNotHaveChildren()
324322
{
325323
await Page.SetContentAsync(@"
326324
<div role='textbox' tabIndex=0 aria-checked='true' aria-label='my favorite textbox'>
327325
this is the inner content
328326
<img alt='yo' src='fakeimg.png'>
329327
</div>");
330-
Assert.Equal(
328+
Assert.AreEqual(
331329
new SerializedAXNode
332330
{
333331
Role = "textbox",
@@ -338,15 +336,15 @@ this is the inner content
338336
}
339337

340338
[PuppeteerTest("accessibility.spec.ts", "filtering children of leaf nodes", "checkbox with and tabIndex and label should not have children")]
341-
[SkipBrowserFact(skipFirefox: true)]
339+
[Skip(SkipAttribute.Targets.Firefox)]
342340
public async Task CheckboxWithAndTabIndexAndLabelShouldNotHaveChildren()
343341
{
344342
await Page.SetContentAsync(@"
345343
<div role='checkbox' tabIndex=0 aria-checked='true' aria-label='my favorite checkbox'>
346344
this is the inner content
347345
<img alt='yo' src='fakeimg.png'>
348346
</div>");
349-
Assert.Equal(
347+
Assert.AreEqual(
350348
new SerializedAXNode
351349
{
352350
Role = "checkbox",
@@ -357,15 +355,15 @@ this is the inner content
357355
}
358356

359357
[PuppeteerTest("accessibility.spec.ts", "filtering children of leaf nodes", "checkbox without label should not have children")]
360-
[SkipBrowserFact(skipFirefox: true)]
358+
[Skip(SkipAttribute.Targets.Firefox)]
361359
public async Task CheckboxWithoutLabelShouldNotHaveChildren()
362360
{
363361
await Page.SetContentAsync(@"
364362
<div role='checkbox' aria-checked='true'>
365363
this is the inner content
366364
<img alt='yo' src='fakeimg.png'>
367365
</div>");
368-
Assert.Equal(
366+
Assert.AreEqual(
369367
new SerializedAXNode
370368
{
371369
Role = "checkbox",

lib/PuppeteerSharp.Tests/AccessibilityTests/RootOptionTests.cs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
11
using System.Threading.Tasks;
22
using PuppeteerSharp.PageAccessibility;
33
using PuppeteerSharp.Tests.Attributes;
4-
using PuppeteerSharp.Xunit;
5-
using Xunit;
6-
using Xunit.Abstractions;
4+
using PuppeteerSharp.Nunit;
5+
using NUnit.Framework;
76

87
namespace PuppeteerSharp.Tests.AccesibilityTests
98
{
10-
[Collection(TestConstants.TestFixtureCollectionName)]
119
public class RootOptionTests : PuppeteerPageBaseTest
1210
{
13-
public RootOptionTests(ITestOutputHelper output) : base(output)
11+
public RootOptionTests(): base()
1412
{
1513
}
1614

1715
[PuppeteerTest("accessibility.spec.ts", "root option", "should work a button")]
18-
[SkipBrowserFact(skipFirefox: true)]
16+
[Skip(SkipAttribute.Targets.Firefox)]
1917
public async Task ShouldWorkAButton()
2018
{
2119
await Page.SetContentAsync("<button>My Button</button>");
2220

2321
var button = await Page.QuerySelectorAsync("button");
24-
Assert.Equal(
22+
Assert.AreEqual(
2523
new SerializedAXNode
2624
{
2725
Role = "button",
@@ -31,13 +29,13 @@ public async Task ShouldWorkAButton()
3129
}
3230

3331
[PuppeteerTest("accessibility.spec.ts", "root option", "should work an input")]
34-
[SkipBrowserFact(skipFirefox: true)]
32+
[Skip(SkipAttribute.Targets.Firefox)]
3533
public async Task ShouldWorkAnInput()
3634
{
3735
await Page.SetContentAsync("<input title='My Input' value='My Value'>");
3836

3937
var input = await Page.QuerySelectorAsync("input");
40-
Assert.Equal(
38+
Assert.AreEqual(
4139
new SerializedAXNode
4240
{
4341
Role = "textbox",
@@ -48,7 +46,7 @@ public async Task ShouldWorkAnInput()
4846
}
4947

5048
[PuppeteerTest("accessibility.spec.ts", "root option", "should work a menu")]
51-
[SkipBrowserFact(skipFirefox: true)]
49+
[Skip(SkipAttribute.Targets.Firefox)]
5250
public async Task ShouldWorkAMenu()
5351
{
5452
await Page.SetContentAsync(@"
@@ -86,11 +84,11 @@ await Page.SetContentAsync(@"
8684
}
8785
};
8886

89-
Assert.Equal(nodeToCheck, snapshot);
87+
Assert.AreEqual(nodeToCheck, snapshot);
9088
}
9189

9290
[PuppeteerTest("accessibility.spec.ts", "root option", "should return null when the element is no longer in DOM")]
93-
[SkipBrowserFact(skipFirefox: true)]
91+
[Skip(SkipAttribute.Targets.Firefox)]
9492
public async Task ShouldReturnNullWhenTheElementIsNoLongerInDOM()
9593
{
9694
await Page.SetContentAsync("<button>My Button</button>");
@@ -100,7 +98,7 @@ public async Task ShouldReturnNullWhenTheElementIsNoLongerInDOM()
10098
}
10199

102100
[PuppeteerTest("accessibility.spec.ts", "root option", "should support the interestingOnly option")]
103-
[SkipBrowserFact(skipFirefox: true)]
101+
[Skip(SkipAttribute.Targets.Firefox)]
104102
public async Task ShouldSupportTheInterestingOnlyOption()
105103
{
106104
await Page.SetContentAsync("<div><button>My Button</button></div>");
@@ -109,7 +107,7 @@ public async Task ShouldSupportTheInterestingOnlyOption()
109107
{
110108
Root = div
111109
}));
112-
Assert.Equal(
110+
Assert.AreEqual(
113111
new SerializedAXNode
114112
{
115113
Role = "generic",

0 commit comments

Comments
 (0)