Skip to content

Commit 9fff3c0

Browse files
jnyrupkblok
andauthored
Migrate to Nunit4 (#2705)
* Migrate to NUnit4 * Microsoft.NET.Test.Sdk 17.0.0 -> 17.10.0 * Move ToJToken to own file * Mark tests methods with [Test] * Ignore tests marked with [Test] * Align per-test and per-class disposal * Update what tests to ignore * undo markdown changes --------- Co-authored-by: Darío Kondratiuk <[email protected]>
1 parent a314025 commit 9fff3c0

File tree

191 files changed

+2119
-2115
lines changed

Some content is hidden

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

191 files changed

+2119
-2115
lines changed

lib/PuppeteerSharp.Nunit/PuppeteerSharp.Nunit.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</PropertyGroup>
77
<ItemGroup>
88
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
9-
<PackageReference Include="NUnit" Version="3.13.3" />
9+
<PackageReference Include="NUnit" Version="4.1.0" />
1010
</ItemGroup>
1111
<ItemGroup>
1212
<EmbeddedResource Include="TestExpectations\TestExpectations.local.json" />

lib/PuppeteerSharp.Tests/AccessibilityTests/AccessibilityTests.cs

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ await Page.SetContentAsync(@"
104104
};
105105
await Page.FocusAsync("[placeholder='Empty input']");
106106
var snapshot = await Page.Accessibility.SnapshotAsync();
107-
Assert.AreEqual(nodeToCheck, snapshot);
107+
Assert.That(snapshot, Is.EqualTo(nodeToCheck));
108108
}
109109

110110
[Test, Retry(2), PuppeteerTest("accessibility.spec", "Accessibility", "should report uninteresting nodes")]
@@ -115,8 +115,12 @@ public async Task ShouldReportUninterestingNodes()
115115

116116
// This object has more children than in upstream.
117117
// Because upstream uses `toMatchObject` which stops going deeper if the element has not Children.
118-
Assert.AreEqual(
119-
new SerializedAXNode
118+
Assert.That(
119+
FindFocusedNode(await Page.Accessibility.SnapshotAsync(new AccessibilitySnapshotOptions
120+
{
121+
InterestingOnly = false
122+
})),
123+
Is.EqualTo(new SerializedAXNode
120124
{
121125
Role = "textbox",
122126
Name = "",
@@ -144,11 +148,7 @@ public async Task ShouldReportUninterestingNodes()
144148
}
145149
}
146150
}
147-
},
148-
FindFocusedNode(await Page.Accessibility.SnapshotAsync(new AccessibilitySnapshotOptions
149-
{
150-
InterestingOnly = false
151-
})));
151+
}));
152152
}
153153

154154
[Test, Retry(2), PuppeteerTest("accessibility.spec", "Accessibility", "get snapshots while the tree is re-calculated")]
@@ -188,7 +188,7 @@ await Page.SetContentAsync(@"
188188
</html>");
189189

190190
var button = await Page.QuerySelectorAsync("button");
191-
Assert.AreEqual("Show", await GetAccessibleNameAsync(Page, button));
191+
Assert.That(await GetAccessibleNameAsync(Page, button), Is.EqualTo("Show"));
192192
await button!.ClickAsync();
193193
await Page.WaitForSelectorAsync("aria/Hide");
194194
}
@@ -207,39 +207,39 @@ public async Task RoleDescription()
207207
await Page.SetContentAsync("<div tabIndex=-1 aria-roledescription='foo'>Hi</div>");
208208
var snapshot = await Page.Accessibility.SnapshotAsync();
209209
// See https://chromium-review.googlesource.com/c/chromium/src/+/3088862
210-
Assert.Null(snapshot.Children[0].RoleDescription);
210+
Assert.That(snapshot.Children[0].RoleDescription, Is.Null);
211211
}
212212

213213
[Test, Retry(2), PuppeteerTest("accessibility.spec", "Accessibility", "orientation")]
214214
public async Task Orientation()
215215
{
216216
await Page.SetContentAsync("<a href='' role='slider' aria-orientation='vertical'>11</a>");
217217
var snapshot = await Page.Accessibility.SnapshotAsync();
218-
Assert.AreEqual("vertical", snapshot.Children[0].Orientation);
218+
Assert.That(snapshot.Children[0].Orientation, Is.EqualTo("vertical"));
219219
}
220220

221221
[Test, Retry(2), PuppeteerTest("accessibility.spec", "Accessibility", "autocomplete")]
222222
public async Task AutoComplete()
223223
{
224224
await Page.SetContentAsync("<input type='number' aria-autocomplete='list' />");
225225
var snapshot = await Page.Accessibility.SnapshotAsync();
226-
Assert.AreEqual("list", snapshot.Children[0].AutoComplete);
226+
Assert.That(snapshot.Children[0].AutoComplete, Is.EqualTo("list"));
227227
}
228228

229229
[Test, Retry(2), PuppeteerTest("accessibility.spec", "Accessibility", "multiselectable")]
230230
public async Task MultiSelectable()
231231
{
232232
await Page.SetContentAsync("<div role='grid' tabIndex=-1 aria-multiselectable=true>hey</div>");
233233
var snapshot = await Page.Accessibility.SnapshotAsync();
234-
Assert.True(snapshot.Children[0].Multiselectable);
234+
Assert.That(snapshot.Children[0].Multiselectable, Is.True);
235235
}
236236

237237
[Test, Retry(2), PuppeteerTest("accessibility.spec", "Accessibility", "keyshortcuts")]
238238
public async Task KeyShortcuts()
239239
{
240240
await Page.SetContentAsync("<div role='grid' tabIndex=-1 aria-keyshortcuts='foo'>hey</div>");
241241
var snapshot = await Page.Accessibility.SnapshotAsync();
242-
Assert.AreEqual("foo", snapshot.Children[0].KeyShortcuts);
242+
Assert.That(snapshot.Children[0].KeyShortcuts, Is.EqualTo("foo"));
243243
}
244244

245245
[Test, Retry(2), PuppeteerTest("accessibility.spec", "filtering children of leaf nodes", "should not report text nodes inside controls")]
@@ -250,8 +250,9 @@ await Page.SetContentAsync(@"
250250
<div role='tab' aria-selected='true'><b>Tab1</b></div>
251251
<div role='tab'>Tab2</div>
252252
</div>");
253-
Assert.AreEqual(
254-
new SerializedAXNode
253+
Assert.That(
254+
await Page.Accessibility.SnapshotAsync(),
255+
Is.EqualTo(new SerializedAXNode
255256
{
256257
Role = "RootWebArea",
257258
Name = "",
@@ -267,8 +268,7 @@ await Page.SetContentAsync(@"
267268
Name = "Tab2"
268269
}
269270
}
270-
},
271-
await Page.Accessibility.SnapshotAsync());
271+
}));
272272
}
273273

274274
[Test, Retry(2), PuppeteerTest("accessibility.spec", "filtering children of leaf nodes", "rich text editable fields should have children")]
@@ -278,8 +278,9 @@ await Page.SetContentAsync(@"
278278
<div contenteditable='true'>
279279
Edit this image: <img src='fakeimage.png' alt='my fake image'>
280280
</div>");
281-
Assert.AreEqual(
282-
new SerializedAXNode
281+
Assert.That(
282+
(await Page.Accessibility.SnapshotAsync()).Children[0],
283+
Is.EqualTo(new SerializedAXNode
283284
{
284285
Role = "generic",
285286
Name = "",
@@ -295,8 +296,7 @@ await Page.SetContentAsync(@"
295296
Name = "my fake image"
296297
}
297298
}
298-
},
299-
(await Page.Accessibility.SnapshotAsync()).Children[0]);
299+
}));
300300
}
301301

302302
[Test, Retry(2), PuppeteerTest("accessibility.spec", "filtering children of leaf nodes", "rich text editable fields with role should have children")]
@@ -306,8 +306,9 @@ await Page.SetContentAsync(@"
306306
<div contenteditable='true' role='textbox'>
307307
Edit this image: <img src='fakeimage.png' alt='my fake image'>
308308
</div>");
309-
Assert.AreEqual(
310-
new SerializedAXNode
309+
Assert.That(
310+
(await Page.Accessibility.SnapshotAsync()).Children[0],
311+
Is.EqualTo(new SerializedAXNode
311312
{
312313
Role = "textbox",
313314
Name = "",
@@ -320,23 +321,22 @@ await Page.SetContentAsync(@"
320321
Name = "Edit this image: "
321322
},
322323
}
323-
},
324-
(await Page.Accessibility.SnapshotAsync()).Children[0]);
324+
}));
325325
}
326326

327327
[Test, Retry(2), PuppeteerTest("accessibility.spec", "plaintext contenteditable", "plain text field with role should not have children")]
328328
public async Task PlainTextFieldWithRoleShouldNotHaveChildren()
329329
{
330330
await Page.SetContentAsync("<div contenteditable='plaintext-only' role='textbox'>Edit this image:<img src='fakeimage.png' alt='my fake image'></div>");
331-
Assert.AreEqual(
332-
new SerializedAXNode
331+
Assert.That(
332+
(await Page.Accessibility.SnapshotAsync()).Children[0],
333+
Is.EqualTo(new SerializedAXNode
333334
{
334335
Role = "textbox",
335336
Name = "",
336337
Value = "Edit this image:",
337338
Multiline = true,
338-
},
339-
(await Page.Accessibility.SnapshotAsync()).Children[0]);
339+
}));
340340
}
341341

342342
[Test, Retry(2), PuppeteerTest("accessibility.spec", "plaintext contenteditable", "plain text field with tabindex and without role should not have content")]
@@ -345,8 +345,8 @@ public async Task PlainTextFieldWithoutRoleShouldNotHaveContent()
345345
await Page.SetContentAsync(
346346
"<div contenteditable='plaintext-only'>Edit this image:<img src='fakeimage.png' alt='my fake image'></div>");
347347
var snapshot = await Page.Accessibility.SnapshotAsync();
348-
Assert.AreEqual("generic", snapshot.Children[0].Role);
349-
Assert.AreEqual(string.Empty, snapshot.Children[0].Name);
348+
Assert.That(snapshot.Children[0].Role, Is.EqualTo("generic"));
349+
Assert.That(snapshot.Children[0].Name, Is.EqualTo(string.Empty));
350350
}
351351

352352
[Test, Retry(2), PuppeteerTest("accessibility.spec", "filtering children of leaf nodes", "non editable textbox with role and tabIndex and label should not have children")]
@@ -357,14 +357,14 @@ await Page.SetContentAsync(@"
357357
this is the inner content
358358
<img alt='yo' src='fakeimg.png'>
359359
</div>");
360-
Assert.AreEqual(
361-
new SerializedAXNode
360+
Assert.That(
361+
(await Page.Accessibility.SnapshotAsync()).Children[0],
362+
Is.EqualTo(new SerializedAXNode
362363
{
363364
Role = "textbox",
364365
Name = "my favorite textbox",
365366
Value = "this is the inner content "
366-
},
367-
(await Page.Accessibility.SnapshotAsync()).Children[0]);
367+
}));
368368
}
369369

370370
[Test, Retry(2), PuppeteerTest("accessibility.spec", "filtering children of leaf nodes", "checkbox with and tabIndex and label should not have children")]
@@ -375,14 +375,14 @@ await Page.SetContentAsync(@"
375375
this is the inner content
376376
<img alt='yo' src='fakeimg.png'>
377377
</div>");
378-
Assert.AreEqual(
379-
new SerializedAXNode
378+
Assert.That(
379+
(await Page.Accessibility.SnapshotAsync()).Children[0],
380+
Is.EqualTo(new SerializedAXNode
380381
{
381382
Role = "checkbox",
382383
Name = "my favorite checkbox",
383384
Checked = CheckedState.True
384-
},
385-
(await Page.Accessibility.SnapshotAsync()).Children[0]);
385+
}));
386386
}
387387

388388
[Test, Retry(2), PuppeteerTest("accessibility.spec", "filtering children of leaf nodes", "checkbox without label should not have children")]
@@ -393,14 +393,14 @@ await Page.SetContentAsync(@"
393393
this is the inner content
394394
<img alt='yo' src='fakeimg.png'>
395395
</div>");
396-
Assert.AreEqual(
397-
new SerializedAXNode
396+
Assert.That(
397+
(await Page.Accessibility.SnapshotAsync()).Children[0],
398+
Is.EqualTo(new SerializedAXNode
398399
{
399400
Role = "checkbox",
400401
Name = "this is the inner content yo",
401402
Checked = CheckedState.True
402-
},
403-
(await Page.Accessibility.SnapshotAsync()).Children[0]);
403+
}));
404404
}
405405

406406
private SerializedAXNode FindFocusedNode(SerializedAXNode serializedAXNode)

lib/PuppeteerSharp.Tests/AccessibilityTests/RootOptionTests.cs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ public async Task ShouldWorkAButton()
1313
await Page.SetContentAsync("<button>My Button</button>");
1414

1515
var button = await Page.QuerySelectorAsync("button");
16-
Assert.AreEqual(
17-
new SerializedAXNode
16+
Assert.That(
17+
await Page.Accessibility.SnapshotAsync(new AccessibilitySnapshotOptions { Root = button }),
18+
Is.EqualTo(new SerializedAXNode
1819
{
1920
Role = "button",
2021
Name = "My Button"
21-
},
22-
await Page.Accessibility.SnapshotAsync(new AccessibilitySnapshotOptions { Root = button }));
22+
}));
2323
}
2424

2525
[Test, Retry(2), PuppeteerTest("accessibility.spec", "root option", "should work an input")]
@@ -28,14 +28,14 @@ public async Task ShouldWorkAnInput()
2828
await Page.SetContentAsync("<input title='My Input' value='My Value'>");
2929

3030
var input = await Page.QuerySelectorAsync("input");
31-
Assert.AreEqual(
32-
new SerializedAXNode
31+
Assert.That(
32+
await Page.Accessibility.SnapshotAsync(new AccessibilitySnapshotOptions { Root = input }),
33+
Is.EqualTo(new SerializedAXNode
3334
{
3435
Role = "textbox",
3536
Name = "My Input",
3637
Value = "My Value"
37-
},
38-
await Page.Accessibility.SnapshotAsync(new AccessibilitySnapshotOptions { Root = input }));
38+
}));
3939
}
4040

4141
[Test, Retry(2), PuppeteerTest("accessibility.spec", "root option", "should work a menu")]
@@ -76,7 +76,7 @@ await Page.SetContentAsync(@"
7676
}
7777
};
7878

79-
Assert.AreEqual(nodeToCheck, snapshot);
79+
Assert.That(snapshot, Is.EqualTo(nodeToCheck));
8080
}
8181

8282
[Test, Retry(2), PuppeteerTest("accessibility.spec", "root option", "should return null when the element is no longer in DOM")]
@@ -85,20 +85,25 @@ public async Task ShouldReturnNullWhenTheElementIsNoLongerInDOM()
8585
await Page.SetContentAsync("<button>My Button</button>");
8686
var button = await Page.QuerySelectorAsync("button");
8787
await Page.EvaluateFunctionAsync("button => button.remove()", button);
88-
Assert.Null(await Page.Accessibility.SnapshotAsync(new AccessibilitySnapshotOptions { Root = button }));
88+
Assert.That(await Page.Accessibility.SnapshotAsync(new AccessibilitySnapshotOptions { Root = button }), Is.Null);
8989
}
9090

9191
[Test, Retry(2), PuppeteerTest("accessibility.spec", "root option", "should support the interestingOnly option")]
9292
public async Task ShouldSupportTheInterestingOnlyOption()
9393
{
9494
await Page.SetContentAsync("<div><button>My Button</button></div>");
9595
var div = await Page.QuerySelectorAsync("div");
96-
Assert.Null(await Page.Accessibility.SnapshotAsync(new AccessibilitySnapshotOptions
96+
Assert.That(await Page.Accessibility.SnapshotAsync(new AccessibilitySnapshotOptions
9797
{
9898
Root = div
99-
}));
100-
Assert.AreEqual(
101-
new SerializedAXNode
99+
}), Is.Null);
100+
Assert.That(
101+
await Page.Accessibility.SnapshotAsync(new AccessibilitySnapshotOptions
102+
{
103+
Root = div,
104+
InterestingOnly = false
105+
}),
106+
Is.EqualTo(new SerializedAXNode
102107
{
103108
Role = "generic",
104109
Name = "",
@@ -125,11 +130,6 @@ public async Task ShouldSupportTheInterestingOnlyOption()
125130
}
126131
}
127132
}
128-
},
129-
await Page.Accessibility.SnapshotAsync(new AccessibilitySnapshotOptions
130-
{
131-
Root = div,
132-
InterestingOnly = false
133133
}));
134134
}
135135
}

lib/PuppeteerSharp.Tests/AriaQueryHandlerTests/ParseAriaSelectorTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ public async Task ShouldFindButton()
2727
{
2828
async Task ExpectFound(IElementHandle button)
2929
{
30-
Assert.NotNull(button);
30+
Assert.That(button, Is.Not.Null);
3131
var id = await button.EvaluateFunctionAsync<string>(@"(button) => {
3232
return button.id;
3333
}");
34-
Assert.AreEqual("btn", id);
34+
Assert.That(id, Is.EqualTo("btn"));
3535
}
3636

3737
var button = await Page.QuerySelectorAsync("aria/Submit button and some spaces[role=\"button\"]");
@@ -55,7 +55,7 @@ async Task ExpectFound(IElementHandle button)
5555
button = await Page.QuerySelectorAsync("aria/ignored[name=\"Submit button and some spaces\"][role=\"button\"]");
5656
await ExpectFound(button);
5757
var ex = Assert.ThrowsAsync<PuppeteerException>(() => Page.QuerySelectorAsync("aria/smth[smth=\"true\"]"));
58-
Assert.AreEqual("Unknown aria attribute \"smth\" in selector", ex.Message);
58+
Assert.That(ex.Message, Is.EqualTo("Unknown aria attribute \"smth\" in selector"));
5959
}
6060
}
6161
}

lib/PuppeteerSharp.Tests/AriaQueryHandlerTests/QueryAllArrayTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ await Page.EvaluateExpressionAsync(@"
3030
.QuerySelectorAllHandleAsync("aria/[role=\"button\"]")
3131
.EvaluateFunctionAsync<int>(@"buttons => buttons.reduce((acc, button) => acc + Number(button.textContent), 0)");
3232

33-
Assert.AreEqual(50005000, sum);
33+
Assert.That(sum, Is.EqualTo(50005000));
3434
}
3535
}
3636
}

lib/PuppeteerSharp.Tests/AriaQueryHandlerTests/QueryAllTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ await Page.SetContentAsync(@"
2121
var divs = await Page.QuerySelectorAllAsync("aria/menu div");
2222
var ids = await Task.WhenAll(divs.Select(div => div.EvaluateFunctionAsync<string>("div => div.id")));
2323

24-
Assert.AreEqual("mnu1, mnu2", String.Join(", ", ids));
24+
Assert.That(String.Join(", ", ids), Is.EqualTo("mnu1, mnu2"));
2525
}
2626
}
2727
}

0 commit comments

Comments
 (0)