Skip to content

Commit

Permalink
Undo some changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kblok committed Nov 16, 2023
1 parent 9d841fa commit 71c6603
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 18 deletions.
8 changes: 4 additions & 4 deletions lib/PuppeteerSharp.Tests/ElementHandleTests/ClickTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ public async Task ShouldWorkForShadowDomV1()
Assert.True(await Page.EvaluateExpressionAsync<bool>("clicked"));
}

[PuppeteerTest("elementhandle.spec.ts", "ElementHandle.click", "should work for TextNodes")]
[PuppeteerTest("elementhandle.spec.ts", "ElementHandle.click", "should not work for TextNodes")]
[PuppeteerTimeout]
public async Task ShouldWorkForTextNodes()
public async Task ShouldNotWorkForTextNodes()
{
await Page.GoToAsync(TestConstants.ServerUrl + "/input/button.html");
var buttonTextNode = (IElementHandle)await Page.EvaluateExpressionHandleAsync(
"document.querySelector('button').firstChild");
var exception = Assert.ThrowsAsync<PuppeteerException>(async () => await buttonTextNode.ClickAsync());
Assert.AreEqual("Node is not of type HTMLElement", exception.Message);
var exception = Assert.ThrowsAsync<EvaluationFailedException>(async () => await buttonTextNode.ClickAsync());
Assert.That(exception.Message, Does.Contain("is not of type 'Element'"));
}

[PuppeteerTest("elementhandle.spec.ts", "ElementHandle.click", "should throw for detached nodes")]
Expand Down
3 changes: 1 addition & 2 deletions lib/PuppeteerSharp/ElementHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -694,8 +694,7 @@ await handle.EvaluateFunctionAsync(
behavior: 'instant',
});
}",
null,
true).ConfigureAwait(false);
null).ConfigureAwait(false);
}

return handle;
Expand Down
2 changes: 1 addition & 1 deletion lib/PuppeteerSharp/IElementHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public interface IElementHandle : IJSHandle
/// </summary>
/// <param name="threshold">A number between 0 and 1 specifying the fraction of the element's area that must be visible to pass the check.</param>
/// <returns>A task which resolves to true if the element is visible in the current viewport.</returns>
Task<bool> IsIntersectingViewportAsync(int threshold = 1);
Task<bool> IsIntersectingViewportAsync(int threshold = 0);

/// <summary>
/// Focuses the element, and then uses <see cref="IKeyboard.DownAsync(string, DownOptions)"/> and <see cref="IKeyboard.UpAsync(string)"/>.
Expand Down
19 changes: 8 additions & 11 deletions lib/PuppeteerSharp/JSHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,14 @@ public Task<IJSHandle> EvaluateFunctionHandleAsync(string pageFunction, params o
}

/// <inheritdoc/>
public Task<JToken> EvaluateFunctionAsync(string script, params object[] args)
=> EvaluateFunctionAsync(script, args, false);
public async Task<JToken> EvaluateFunctionAsync(string script, params object[] args)
{
var list = new List<object>(args);
var adoptedThis = await Realm.AdoptHandleAsync(this).ConfigureAwait(false);
list.Insert(0, adoptedThis);
return await Realm.EvaluateFunctionAsync<JToken>(script, list.ToArray())
.ConfigureAwait(false);
}

/// <inheritdoc/>
public Task<T> EvaluateFunctionAsync<T>(string script, params object[] args)
Expand All @@ -149,14 +155,5 @@ public Task<T> EvaluateFunctionAsync<T>(string script, params object[] args)
list.Insert(0, this);
return Realm.EvaluateFunctionAsync<T>(script, list.ToArray());
}

internal async Task<JToken> EvaluateFunctionAsync(string script, object[] args, bool adopt)
{
var list = new List<object>(args);
var adoptedThis = await Frame.IsolatedRealm.AdoptHandleAsync(this).ConfigureAwait(false);
list.Insert(0, adoptedThis);
return await Frame.IsolatedRealm.EvaluateFunctionAsync<JToken>(script, list.ToArray())
.ConfigureAwait(false);
}
}
}

0 comments on commit 71c6603

Please sign in to comment.