Skip to content

Commit fffdcaf

Browse files
authored
Add PuppeteerTests attributes - Part 4 (#1699)
* Add PuppeteerTests attributes - Part 4 * ops
1 parent ecaf43b commit fffdcaf

File tree

13 files changed

+301
-252
lines changed

13 files changed

+301
-252
lines changed

lib/PuppeteerSharp.Tests/InputTests/ClickTests.cs renamed to lib/PuppeteerSharp.Tests/ClickTests/PageClickTests.cs

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,20 @@
33
using System.Threading.Tasks;
44
using PuppeteerSharp.Input;
55
using PuppeteerSharp.Tests.Attributes;
6+
using PuppeteerSharp.Xunit;
67
using Xunit;
78
using Xunit.Abstractions;
89

9-
namespace PuppeteerSharp.Tests.InputTests
10+
namespace PuppeteerSharp.Tests.ClickTests
1011
{
1112
[Collection(TestConstants.TestFixtureCollectionName)]
12-
public class ClickTests : PuppeteerPageBaseTest
13+
public class PageClickTests : PuppeteerPageBaseTest
1314
{
14-
public ClickTests(ITestOutputHelper output) : base(output)
15+
public PageClickTests(ITestOutputHelper output) : base(output)
1516
{
1617
}
1718

19+
[PuppeteerTest("click.spec.ts", "Page.click", "should click the button")]
1820
[Fact(Timeout = TestConstants.DefaultTestTimeout)]
1921
public async Task ShouldClickTheButton()
2022
{
@@ -23,6 +25,7 @@ public async Task ShouldClickTheButton()
2325
Assert.Equal("Clicked", await Page.EvaluateExpressionAsync<string>("result"));
2426
}
2527

28+
[PuppeteerTest("click.spec.ts", "Page.click", "should click svg")]
2629
[Fact(Timeout = TestConstants.DefaultTestTimeout)]
2730
public async Task ShouldClickSvg()
2831
{
@@ -35,6 +38,7 @@ await Page.SetContentAsync($@"
3538
Assert.Equal(42, await Page.EvaluateFunctionAsync<int>("() => window.__CLICKED"));
3639
}
3740

41+
[PuppeteerTest("click.spec.ts", "Page.click", "should click the button if window.Node is removed")]
3842
[SkipBrowserFact(skipFirefox: true)]
3943
public async Task ShouldClickTheButtonIfWindowNodeIsRemoved()
4044
{
@@ -44,6 +48,7 @@ public async Task ShouldClickTheButtonIfWindowNodeIsRemoved()
4448
Assert.Equal("Clicked", await Page.EvaluateExpressionAsync("result"));
4549
}
4650

51+
[PuppeteerTest("click.spec.ts", "Page.click", "should click on a span with an inline element inside")]
4752
[Fact(Skip = "See https://github.com/GoogleChrome/puppeteer/issues/4281")]
4853
public async Task ShouldClickOnASpanWithAnInlineElementInside()
4954
{
@@ -62,6 +67,7 @@ await Page.SetContentAsync($@"
6267
/// <summary>
6368
/// This test is called ShouldNotThrowUnhandledPromiseRejectionWhenPageCloses in puppeteer.
6469
/// </summary>
70+
[PuppeteerTest("click.spec.ts", "Page.click", "should not throw UnhandledPromiseRejection when page closes")]
6571
[Fact(Skip = "We don't need this test")]
6672
public async Task ShouldGracefullyFailWhenPageCloses()
6773
{
@@ -71,6 +77,7 @@ await Task.WhenAll(
7177
newPage.Mouse.ClickAsync(1, 2));
7278
}
7379

80+
[PuppeteerTest("click.spec.ts", "Page.click", "should click the button after navigation ")]
7481
[Fact(Timeout = TestConstants.DefaultTestTimeout)]
7582
public async Task ShouldClickTheButtonAfterNavigation()
7683
{
@@ -81,6 +88,7 @@ public async Task ShouldClickTheButtonAfterNavigation()
8188
Assert.Equal("Clicked", await Page.EvaluateExpressionAsync<string>("result"));
8289
}
8390

91+
[PuppeteerTest("click.spec.ts", "Page.click", "should click with disabled javascript")]
8492
[SkipBrowserFact(skipFirefox: true)]
8593
public async Task ShouldClickWithDisabledJavascript()
8694
{
@@ -93,6 +101,7 @@ await Task.WhenAll(
93101
Assert.Equal(TestConstants.ServerUrl + "/wrappedlink.html#clicked", Page.Url);
94102
}
95103

104+
[PuppeteerTest("click.spec.ts", "Page.click", "should click when one of inline box children is outside of viewport")]
96105
[Fact(Timeout = TestConstants.DefaultTestTimeout)]
97106
public async Task ShouldClickWhenOneOfInlineBoxChildrenIsOutsideOfViewport()
98107
{
@@ -110,6 +119,7 @@ await Page.SetContentAsync($@"
110119
Assert.Equal(42, await Page.EvaluateFunctionAsync<int>("() => window.CLICKED"));
111120
}
112121

122+
[PuppeteerTest("click.spec.ts", "Page.click", "should select the text by triple clicking")]
113123
[Fact(Timeout = TestConstants.DefaultTestTimeout)]
114124
public async Task ShouldSelectTheTextByTripleClicking()
115125
{
@@ -129,6 +139,7 @@ public async Task ShouldSelectTheTextByTripleClicking()
129139
}"));
130140
}
131141

142+
[PuppeteerTest("click.spec.ts", "Page.click", "should click offscreen buttons")]
132143
[Fact(Timeout = TestConstants.DefaultTestTimeout)]
133144
public async Task ShouldClickOffscreenButtons()
134145
{
@@ -158,6 +169,7 @@ public async Task ShouldClickOffscreenButtons()
158169
}, messages);
159170
}
160171

172+
[PuppeteerTest("click.spec.ts", "Page.click", "should click wrapped links")]
161173
[Fact(Timeout = TestConstants.DefaultTestTimeout)]
162174
public async Task ShouldClickWrappedLinks()
163175
{
@@ -166,6 +178,7 @@ public async Task ShouldClickWrappedLinks()
166178
Assert.True(await Page.EvaluateExpressionAsync<bool>("window.__clicked"));
167179
}
168180

181+
[PuppeteerTest("click.spec.ts", "Page.click", "should click on checkbox input and toggle")]
169182
[Fact(Timeout = TestConstants.DefaultTestTimeout)]
170183
public async Task ShouldClickOnCheckboxInputAndToggle()
171184
{
@@ -187,6 +200,7 @@ public async Task ShouldClickOnCheckboxInputAndToggle()
187200
Assert.False(await Page.EvaluateExpressionAsync<bool>("result.check"));
188201
}
189202

203+
[PuppeteerTest("click.spec.ts", "Page.click", "should click on checkbox label and toggle")]
190204
[SkipBrowserFact(skipFirefox: true)]
191205
public async Task ShouldClickOnCheckboxLabelAndToggle()
192206
{
@@ -203,6 +217,7 @@ public async Task ShouldClickOnCheckboxLabelAndToggle()
203217
Assert.False(await Page.EvaluateExpressionAsync<bool>("result.check"));
204218
}
205219

220+
[PuppeteerTest("click.spec.ts", "Page.click", "should fail to click a missing button")]
206221
[Fact(Timeout = TestConstants.DefaultTestTimeout)]
207222
public async Task ShouldFailToClickAMissingButton()
208223
{
@@ -213,6 +228,18 @@ public async Task ShouldFailToClickAMissingButton()
213228
Assert.Equal("button.does-not-exist", exception.Selector);
214229
}
215230

231+
// https://github.com/GoogleChrome/puppeteer/issues/161
232+
[PuppeteerTest("click.spec.ts", "Page.click", "should not hang with touch-enabled viewports")]
233+
[SkipBrowserFact(skipFirefox: true)]
234+
public async Task ShouldNotHangWithTouchEnabledViewports()
235+
{
236+
await Page.SetViewportAsync(TestConstants.IPhone.ViewPort);
237+
await Page.Mouse.DownAsync();
238+
await Page.Mouse.MoveAsync(100, 10);
239+
await Page.Mouse.UpAsync();
240+
}
241+
242+
[PuppeteerTest("click.spec.ts", "Page.click", "should scroll and click the button")]
216243
[Fact(Timeout = TestConstants.DefaultTestTimeout)]
217244
public async Task ShouldScrollAndClickTheButton()
218245
{
@@ -223,6 +250,7 @@ public async Task ShouldScrollAndClickTheButton()
223250
Assert.Equal("clicked", await Page.EvaluateExpressionAsync<string>("document.querySelector(\"#button-80\").textContent"));
224251
}
225252

253+
[PuppeteerTest("click.spec.ts", "Page.click", "should double click the button")]
226254
[Fact(Timeout = TestConstants.DefaultTestTimeout)]
227255
public async Task ShouldDoubleClickTheButton()
228256
{
@@ -240,6 +268,7 @@ await Page.EvaluateExpressionAsync(@"{
240268
Assert.Equal("Clicked", await Page.EvaluateExpressionAsync<string>("result"));
241269
}
242270

271+
[PuppeteerTest("click.spec.ts", "Page.click", "should click a partially obscured button")]
243272
[Fact(Timeout = TestConstants.DefaultTestTimeout)]
244273
public async Task ShouldClickAPartiallyObscuredButton()
245274
{
@@ -254,6 +283,7 @@ await Page.EvaluateExpressionAsync(@"{
254283
Assert.Equal("Clicked", await Page.EvaluateExpressionAsync<string>("result"));
255284
}
256285

286+
[PuppeteerTest("click.spec.ts", "Page.click", "should click a rotated button")]
257287
[Fact(Timeout = TestConstants.DefaultTestTimeout)]
258288
public async Task ShouldClickARotatedButton()
259289
{
@@ -262,6 +292,7 @@ public async Task ShouldClickARotatedButton()
262292
Assert.Equal("Clicked", await Page.EvaluateExpressionAsync<string>("result"));
263293
}
264294

295+
[PuppeteerTest("click.spec.ts", "Page.click", "should fire contextmenu event on right click")]
265296
[Fact(Timeout = TestConstants.DefaultTestTimeout)]
266297
public async Task ShouldFireContextmenuEventOnRightClick()
267298
{
@@ -271,6 +302,7 @@ public async Task ShouldFireContextmenuEventOnRightClick()
271302
}
272303

273304
// @see https://github.com/GoogleChrome/puppeteer/issues/206
305+
[PuppeteerTest("click.spec.ts", "Page.click", "should click links which cause navigation")]
274306
[Fact(Timeout = TestConstants.DefaultTestTimeout)]
275307
public async Task ShouldClickLinksWhichCauseNavigation()
276308
{
@@ -279,6 +311,7 @@ public async Task ShouldClickLinksWhichCauseNavigation()
279311
await Page.ClickAsync("a");
280312
}
281313

314+
[PuppeteerTest("click.spec.ts", "Page.click", "should click the button inside an iframe")]
282315
[SkipBrowserFact(skipFirefox: true)]
283316
public async Task ShouldClickTheButtonInsideAnIframe()
284317
{
@@ -291,6 +324,7 @@ public async Task ShouldClickTheButtonInsideAnIframe()
291324
Assert.Equal("Clicked", await frame.EvaluateExpressionAsync<string>("window.result"));
292325
}
293326

327+
[PuppeteerTest("click.spec.ts", "Page.click", "should click the button with fixed position inside an iframe")]
294328
[Fact(Skip = "see https://github.com/GoogleChrome/puppeteer/issues/4110")]
295329
public async Task ShouldClickTheButtonWithFixedPositionInsideAnIframe()
296330
{
@@ -308,6 +342,7 @@ await Page.SetViewportAsync(new ViewPortOptions
308342
Assert.Equal("Clicked", await frame.EvaluateExpressionAsync<string>("window.result"));
309343
}
310344

345+
[PuppeteerTest("click.spec.ts", "Page.click", "should click the button with deviceScaleFactor set")]
311346
[SkipBrowserFact(skipFirefox: true)]
312347
public async Task ShouldClickTheButtonWithDeviceScaleFactorSet()
313348
{

lib/PuppeteerSharp.Tests/JSCoverageTests/JSCoverageTests.cs renamed to lib/PuppeteerSharp.Tests/CoverageTests/JSCoverageTests.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
using Newtonsoft.Json;
66
using PuppeteerSharp.PageCoverage;
77
using PuppeteerSharp.Tests.Attributes;
8+
using PuppeteerSharp.Xunit;
89
using Xunit;
910
using Xunit.Abstractions;
1011

11-
namespace PuppeteerSharp.Tests.JSCoverageTests
12+
namespace PuppeteerSharp.Tests.CoverageTests
1213
{
1314
[Collection(TestConstants.TestFixtureCollectionName)]
1415
public class JSCoverageTests : PuppeteerPageBaseTest
@@ -17,6 +18,7 @@ public JSCoverageTests(ITestOutputHelper output) : base(output)
1718
{
1819
}
1920

21+
[PuppeteerTest("coverage.spec.ts", "JSCoverage", "should work")]
2022
[SkipBrowserFact(skipFirefox: true)]
2123
public async Task ShouldWork()
2224
{
@@ -40,6 +42,7 @@ public async Task ShouldWork()
4042
}, coverage[0].Ranges);
4143
}
4244

45+
[PuppeteerTest("coverage.spec.ts", "JSCoverage", "should report sourceURLs")]
4346
[SkipBrowserFact(skipFirefox: true)]
4447
public async Task ShouldReportSourceUrls()
4548
{
@@ -50,6 +53,7 @@ public async Task ShouldReportSourceUrls()
5053
Assert.Equal("nicename.js", coverage[0].Url);
5154
}
5255

56+
[PuppeteerTest("coverage.spec.ts", "JSCoverage", "should ignore eval() scripts by default")]
5357
[SkipBrowserFact(skipFirefox: true)]
5458
public async Task ShouldIgnoreEvalScriptsByDefault()
5559
{
@@ -59,6 +63,7 @@ public async Task ShouldIgnoreEvalScriptsByDefault()
5963
Assert.Single(coverage);
6064
}
6165

66+
[PuppeteerTest("coverage.spec.ts", "JSCoverage", "shouldn't ignore eval() scripts if reportAnonymousScripts is true")]
6267
[SkipBrowserFact(skipFirefox: true)]
6368
public async Task ShouldntIgnoreEvalScriptsIfReportAnonymousScriptsIsTrue()
6469
{
@@ -72,6 +77,7 @@ await Page.Coverage.StartJSCoverageAsync(new CoverageStartOptions
7277
Assert.Equal(2, coverage.Count());
7378
}
7479

80+
[PuppeteerTest("coverage.spec.ts", "JSCoverage", "should ignore pptr internal scripts if reportAnonymousScripts is true")]
7581
[SkipBrowserFact(skipFirefox: true)]
7682
public async Task ShouldIgnorePptrInternalScriptsIfReportAnonymousScriptsIsTrue()
7783
{
@@ -86,6 +92,7 @@ await Page.Coverage.StartJSCoverageAsync(new CoverageStartOptions
8692
Assert.Empty(coverage);
8793
}
8894

95+
[PuppeteerTest("coverage.spec.ts", "JSCoverage", "should report multiple scripts")]
8996
[SkipBrowserFact(skipFirefox: true)]
9097
public async Task ShouldReportMultipleScripts()
9198
{
@@ -98,6 +105,7 @@ public async Task ShouldReportMultipleScripts()
98105
Assert.Contains("/jscoverage/script2.js", orderedList.ElementAt(1).Url);
99106
}
100107

108+
[PuppeteerTest("coverage.spec.ts", "JSCoverage", "should report right ranges")]
101109
[SkipBrowserFact(skipFirefox: true)]
102110
public async Task ShouldReportRightRanges()
103111
{
@@ -111,6 +119,7 @@ public async Task ShouldReportRightRanges()
111119
Assert.Equal("console.log('used!');", entry.Text.Substring(range.Start, range.End - range.Start));
112120
}
113121

122+
[PuppeteerTest("coverage.spec.ts", "JSCoverage", "should report scripts that have no coverage")]
114123
[SkipBrowserFact(skipFirefox: true)]
115124
public async Task ShouldReportScriptsThatHaveNoCoverage()
116125
{
@@ -123,6 +132,7 @@ public async Task ShouldReportScriptsThatHaveNoCoverage()
123132
Assert.Empty(entry.Ranges);
124133
}
125134

135+
[PuppeteerTest("coverage.spec.ts", "JSCoverage", "should work with conditionals")]
126136
[SkipBrowserFact(skipFirefox: true)]
127137
public async Task ShouldWorkWithConditionals()
128138
{
@@ -162,6 +172,7 @@ public async Task ShouldWorkWithConditionals()
162172
Regex.Replace(TestUtils.CompressText(JsonConvert.SerializeObject(coverage)), @"\d{4}\/", "<PORT>/"));
163173
}
164174

175+
[PuppeteerTest("coverage.spec.ts", "JSCoverage", "should not hang when there is a debugger statement")]
165176
[Fact(Skip = "Skipped in puppeteer")]
166177
public async Task ShouldNotHangWhenThereIsADebuggerStatement()
167178
{

lib/PuppeteerSharp.Tests/JSCoverageTests/JSResetOnNavigationTests.cs renamed to lib/PuppeteerSharp.Tests/CoverageTests/JSResetOnNavigationTests.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
using Newtonsoft.Json;
55
using PuppeteerSharp.PageCoverage;
66
using PuppeteerSharp.Tests.Attributes;
7+
using PuppeteerSharp.Xunit;
78
using Xunit;
89
using Xunit.Abstractions;
910

10-
namespace PuppeteerSharp.Tests.JSCoverageTests
11+
namespace PuppeteerSharp.Tests.CoverageTests
1112
{
1213
[Collection(TestConstants.TestFixtureCollectionName)]
1314
public class JSResetOnNavigationTests : PuppeteerPageBaseTest
@@ -16,6 +17,7 @@ public JSResetOnNavigationTests(ITestOutputHelper output) : base(output)
1617
{
1718
}
1819

20+
[PuppeteerTest("coverage.spec.ts", "resetOnNavigation", "should report scripts across navigations when disabled")]
1921
[SkipBrowserFact(skipFirefox: true)]
2022
public async Task ShouldReportScriptsAcrossNavigationsWhenDisabled()
2123
{
@@ -29,6 +31,7 @@ await Page.Coverage.StartJSCoverageAsync(new CoverageStartOptions
2931
Assert.Equal(2, coverage.Length);
3032
}
3133

34+
[PuppeteerTest("coverage.spec.ts", "resetOnNavigation", "should NOT report scripts across navigations when enabled")]
3235
[SkipBrowserFact(skipFirefox: true)]
3336
public async Task ShouldNotReportScriptsAcrossNavigationsWhenEnabled()
3437
{

lib/PuppeteerSharp.Tests/InputTests/FileChooserAcceptTests.cs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Threading.Tasks;
33
using PuppeteerSharp.Mobile;
44
using PuppeteerSharp.Tests.Attributes;
5+
using PuppeteerSharp.Xunit;
56
using Xunit;
67
using Xunit.Abstractions;
78

@@ -14,19 +15,7 @@ public FileChooserAcceptTests(ITestOutputHelper output) : base(output)
1415
{
1516
}
1617

17-
[SkipBrowserFact(skipFirefox: true)]
18-
public async Task ShouldWorkWhenFileInputIsAttachedToDOM()
19-
{
20-
await Page.SetContentAsync("<input type=file>");
21-
var waitForTask = Page.WaitForFileChooserAsync();
22-
23-
await Task.WhenAll(
24-
waitForTask,
25-
Page.ClickAsync("input"));
26-
27-
Assert.NotNull(waitForTask.Result);
28-
}
29-
18+
[PuppeteerTest("input.spec.ts", "FileChooser.accept", "should accept single file")]
3019
[SkipBrowserFact(skipFirefox: true)]
3120
public async Task ShouldAcceptSingleFile()
3221
{
@@ -50,6 +39,7 @@ await Task.WhenAll(
5039
await Page.QuerySelectorAsync("input").EvaluateFunctionAsync<string>("input => input.files[0].name"));
5140
}
5241

42+
[PuppeteerTest("input.spec.ts", "FileChooser.accept", "should be able to read selected file")]
5343
[SkipBrowserFact(skipFirefox: true)]
5444
public async Task ShouldBeAbleToReadSelectedFile()
5545
{
@@ -69,6 +59,7 @@ await Page.QuerySelectorAsync("input").EvaluateFunctionAsync<string>(@"async pic
6959
}"));
7060
}
7161

62+
[PuppeteerTest("input.spec.ts", "FileChooser.accept", "should be able to reset selected files with empty file list")]
7263
[SkipBrowserFact(skipFirefox: true)]
7364
public async Task ShouldBeAbleToResetSelectedFilesWithEmptyFileList()
7465
{
@@ -96,6 +87,7 @@ await Page.QuerySelectorAsync("input").EvaluateFunctionAsync<int>(@"async picker
9687
}"));
9788
}
9889

90+
[PuppeteerTest("input.spec.ts", "FileChooser.accept", "should not accept multiple files for single-file input")]
9991
[SkipBrowserFact(skipFirefox: true)]
10092
public async Task ShouldNotAcceptMultipleFilesForSingleFileInput()
10193
{
@@ -111,6 +103,7 @@ await Assert.ThrowsAsync<PuppeteerException>(() => waitForTask.Result.AcceptAsyn
111103
"./assets/pptr.png"));
112104
}
113105

106+
[PuppeteerTest("input.spec.ts", "FileChooser.accept", "should fail when accepting file chooser twice")]
114107
[SkipBrowserFact(skipFirefox: true)]
115108
public async Task ShouldFailWhenAcceptingFileChooserTwice()
116109
{

0 commit comments

Comments
 (0)