Skip to content

Commit e2b9191

Browse files
kblokMeir017
authored andcommitted
New ignored tests + new extension functions (#663)
* New ignored tests + new extension functions * CodeFactor
1 parent 5214cef commit e2b9191

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

lib/PuppeteerSharp.Tests/PageTests/SetRequestInterceptionTests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,25 @@ public async Task ShouldIntercept()
4040
Assert.Equal(TestConstants.Port, response.RemoteAddress.Port);
4141
}
4242

43+
[Fact(Skip = "Ignored on Puppeteer")]
44+
public async Task ShouldWorkWhenPostIsEedirectedWith302()
45+
{
46+
Server.SetRedirect("/rredirect", "/empty.html");
47+
await Page.GoToAsync(TestConstants.EmptyPage);
48+
await Page.SetRequestInterceptionAsync(true);
49+
Page.Request += async (sender, e) => await e.Request.ContinueAsync();
50+
51+
await Page.SetContentAsync(@"
52+
<form action='/rredirect' method='post'>
53+
<input type='hidden' id='foo' name='foo' value='FOOBAR'>
54+
</form>
55+
");
56+
await Task.WhenAll(
57+
Page.QuerySelectorAsync("form").EvaluateFunctionAsync("form => form.submit()"),
58+
Page.WaitForNavigationAsync()
59+
);
60+
}
61+
4362
[Fact]
4463
public async Task ShouldContainRefererHeader()
4564
{

lib/PuppeteerSharp/Extensions.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ namespace PuppeteerSharp
77
/// </summary>
88
public static class Extensions
99
{
10+
/// <summary>
11+
/// Runs <paramref name="pageFunction"/> within the frame and passes it the outcome of <paramref name="elementHandleTask"/> as the first argument
12+
/// </summary>
13+
/// <param name="elementHandleTask">A task that returns an <see cref="ElementHandle"/> that will be used as the first argument in <paramref name="pageFunction"/></param>
14+
/// <param name="pageFunction">Function to be evaluated in browser context</param>
15+
/// <param name="args">Arguments to pass to <c>pageFunction</c></param>
16+
/// <returns>Task</returns>
17+
/// <exception cref="SelectorException">If <paramref name="elementHandleTask"/> resolves to <c>null</c></exception>
18+
public static Task EvaluateFunctionAsync(this Task<ElementHandle> elementHandleTask, string pageFunction, params object[] args)
19+
=> elementHandleTask.EvaluateFunctionAsync<object>(pageFunction, args);
20+
1021
/// <summary>
1122
/// Runs <paramref name="pageFunction"/> within the frame and passes it the outcome of <paramref name="elementHandleTask"/> as the first argument
1223
/// </summary>
@@ -51,6 +62,16 @@ public static async Task<T> EvaluateFunctionAsync<T>(this ElementHandle elementH
5162
return result;
5263
}
5364

65+
/// <summary>
66+
/// Runs <paramref name="pageFunction"/> within the frame and passes it the outcome of <paramref name="arrayHandleTask"/> as the first argument. Use only after <see cref="Page.QuerySelectorAllHandleAsync(string)"/>
67+
/// </summary>
68+
/// <param name="arrayHandleTask">A task that returns an <see cref="JSHandle"/> that represents an array of <see cref="ElementHandle"/> that will be used as the first argument in <paramref name="pageFunction"/></param>
69+
/// <param name="pageFunction">Function to be evaluated in browser context</param>
70+
/// <param name="args">Arguments to pass to <c>pageFunction</c></param>
71+
/// <returns>Task</returns>
72+
public static Task EvaluateFunctionAsync(this Task<JSHandle> arrayHandleTask, string pageFunction, params object[] args)
73+
=> arrayHandleTask.EvaluateFunctionAsync<object>(pageFunction, args);
74+
5475
/// <summary>
5576
/// Runs <paramref name="pageFunction"/> within the frame and passes it the outcome of <paramref name="arrayHandleTask"/> as the first argument. Use only after <see cref="Page.QuerySelectorAllHandleAsync(string)"/>
5677
/// </summary>
@@ -82,4 +103,4 @@ public static async Task<T> EvaluateFunctionAsync<T>(this JSHandle arrayHandle,
82103
return result;
83104
}
84105
}
85-
}
106+
}

0 commit comments

Comments
 (0)