33using System . Threading . Tasks ;
44using PuppeteerSharp . Input ;
55using PuppeteerSharp . Tests . Attributes ;
6+ using PuppeteerSharp . Xunit ;
67using Xunit ;
78using 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 {
0 commit comments