Skip to content

Commit 2ddf7d6

Browse files
authored
Add missing click tests (#2299)
1 parent 3b06092 commit 2ddf7d6

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

lib/PuppeteerSharp.TestServer/wwwroot/input/scrollable.html

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,26 @@
1212
button.id = 'button-' + i;
1313
button.onclick = () => button.textContent = 'clicked';
1414
button.oncontextmenu = event => {
15+
if (![2].includes(event.button)) {
16+
return;
17+
}
1518
event.preventDefault();
1619
button.textContent = 'context menu';
1720
}
21+
button.onmouseup = event => {
22+
if (![1,3,4].includes(event.button)) {
23+
return;
24+
}
25+
event.preventDefault();
26+
button.textContent = {
27+
3: 'back click',
28+
4: 'forward click',
29+
1: 'aux click',
30+
}[event.button];
31+
}
1832
document.body.appendChild(button);
1933
document.body.appendChild(document.createElement('br'));
2034
}
2135
</script>
2236
</body>
23-
</html>
37+
</html>

lib/PuppeteerSharp.Tests/ClickTests/ClickTests.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,21 @@ await Task.WhenAll(
9999
Assert.AreEqual(TestConstants.ServerUrl + "/wrappedlink.html#clicked", Page.Url);
100100
}
101101

102+
[PuppeteerTest("click.spec.ts", "Page.click", "should scroll and click with disabled javascript")]
103+
[Skip(SkipAttribute.Targets.Firefox)]
104+
public async Task ShouldScrollAndClickWithDisabledJavascript()
105+
{
106+
await Page.SetJavaScriptEnabledAsync(false);
107+
await Page.GoToAsync(TestConstants.ServerUrl + "/wrappedlink.html");
108+
var body = await Page.WaitForSelectorAsync("body");
109+
await body.EvaluateFunctionAsync("body => body.style.paddingTop = '3000px'", body);
110+
await Task.WhenAll(
111+
Page.ClickAsync("a"),
112+
Page.WaitForNavigationAsync()
113+
);
114+
Assert.AreEqual(TestConstants.ServerUrl + "/wrappedlink.html#clicked", Page.Url);
115+
}
116+
102117
[PuppeteerTest("click.spec.ts", "Page.click", "should click when one of inline box children is outside of viewport")]
103118
[PuppeteerTimeout]
104119
public async Task ShouldClickWhenOneOfInlineBoxChildrenIsOutsideOfViewport()
@@ -303,6 +318,33 @@ public async Task ShouldFireContextmenuEventOnRightClick()
303318
Assert.AreEqual("context menu", await Page.EvaluateExpressionAsync<string>("document.querySelector('#button-8').textContent"));
304319
}
305320

321+
[PuppeteerTest("click.spec.ts", "Page.click", "should fire aux event on middle click")]
322+
[PuppeteerTimeout]
323+
public async Task ShouldFireAuxEventOnMiddleClick()
324+
{
325+
await Page.GoToAsync(TestConstants.ServerUrl + "/input/scrollable.html");
326+
await Page.ClickAsync("#button-8", new ClickOptions { Button = MouseButton.Middle });
327+
Assert.AreEqual("aux click", await Page.EvaluateExpressionAsync<string>("document.querySelector('#button-8').textContent"));
328+
}
329+
330+
[PuppeteerTest("click.spec.ts", "Page.click", "should fire back click")]
331+
[PuppeteerTimeout]
332+
public async Task ShouldFireBackClick()
333+
{
334+
await Page.GoToAsync(TestConstants.ServerUrl + "/input/scrollable.html");
335+
await Page.ClickAsync("#button-8", new ClickOptions { Button = MouseButton.Back });
336+
Assert.AreEqual("back click", await Page.EvaluateExpressionAsync<string>("document.querySelector('#button-8').textContent"));
337+
}
338+
339+
[PuppeteerTest("click.spec.ts", "Page.click", "should fire forward click")]
340+
[PuppeteerTimeout]
341+
public async Task ShouldFireForwardClick()
342+
{
343+
await Page.GoToAsync(TestConstants.ServerUrl + "/input/scrollable.html");
344+
await Page.ClickAsync("#button-8", new ClickOptions { Button = MouseButton.Forward });
345+
Assert.AreEqual("forward click", await Page.EvaluateExpressionAsync<string>("document.querySelector('#button-8').textContent"));
346+
}
347+
306348
// @see https://github.com/GoogleChrome/puppeteer/issues/206
307349
[PuppeteerTest("click.spec.ts", "Page.click", "should click links which cause navigation")]
308350
[PuppeteerTimeout]

0 commit comments

Comments
 (0)