Skip to content

Commit

Permalink
Mouse.ClickAsync improvements (#1190)
Browse files Browse the repository at this point in the history
  • Loading branch information
kblok authored Jun 28, 2019
1 parent bd5c52f commit 281d13e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
13 changes: 13 additions & 0 deletions lib/PuppeteerSharp.Tests/InputTests/ClickTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ await Page.SetContentAsync($@"
Assert.Equal(42, await Page.EvaluateFunctionAsync<int>("() => window.CLICKED"));
}

/// <summary>
/// This test is called ShouldNotThrowUnhandledPromiseRejectionWhenPageCloses in puppeteer.
/// </summary>
[Fact]
public async Task ShouldGracefullyFailWhenPageCloses()
{
var newPage = await Browser.NewPageAsync();
await Assert.ThrowsAsync<TargetClosedException>(() => Task.WhenAll(
newPage.CloseAsync(),
newPage.Mouse.ClickAsync(1, 2)
));
}

[Fact]
public async Task ShouldClickTheButtonAfterNavigation()
{
Expand Down
18 changes: 14 additions & 4 deletions lib/PuppeteerSharp/Input/Mouse.cs
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,24 @@ public async Task ClickAsync(decimal x, decimal y, ClickOptions options = null)
{
options = options ?? new ClickOptions();

await MoveAsync(x, y).ConfigureAwait(false);
await DownAsync(options).ConfigureAwait(false);

if (options.Delay > 0)
{
await Task.WhenAll(
MoveAsync(x, y),
DownAsync(options)
).ConfigureAwait(false);

await Task.Delay(options.Delay).ConfigureAwait(false);
await UpAsync(options).ConfigureAwait(false);
}
else
{
await Task.WhenAll(
MoveAsync(x, y),
DownAsync(options),
UpAsync(options)
).ConfigureAwait(false);
}
await UpAsync(options).ConfigureAwait(false);
}

/// <summary>
Expand Down

0 comments on commit 281d13e

Please sign in to comment.