Skip to content

Commit fe0513d

Browse files
Fix PageGotoTests (#2238)
* Fix PageGotoTests' flakyness. See puppeteer/puppeteer#8717 * Fix PageGotoTests.ShouldWorkWhenNavigatingTo404 when executed in headful mode. See puppeteer/puppeteer#9577
1 parent 8b92b87 commit fe0513d

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

lib/PuppeteerSharp.Tests/NavigationTests/PageGotoTests.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,36 @@ public async Task ShouldWorkWhenNavigatingTo404()
294294
Assert.Equal(HttpStatusCode.NotFound, response.Status);
295295
}
296296

297+
[PuppeteerTest("navigation.spec.ts", "Page.goto", "should not throw an error for a 404 response with an empty body")]
298+
[PuppeteerFact]
299+
public async Task ShouldNotThrowAnErrorForA404ResponseWithAnEmptyBody()
300+
{
301+
Server.SetRoute("/404-error", context =>
302+
{
303+
context.Response.StatusCode = 404;
304+
return Task.CompletedTask;
305+
});
306+
307+
var response = await Page.GoToAsync(TestConstants.ServerUrl + "/404-error");
308+
Assert.False(response.Ok);
309+
Assert.Equal(HttpStatusCode.NotFound, response.Status);
310+
}
311+
312+
[PuppeteerTest("navigation.spec.ts", "Page.goto", "should not throw an error for a 500 response with an empty body")]
313+
[PuppeteerFact]
314+
public async Task ShouldNotThrowAnErrorForA500ResponseWithAnEmptyBody()
315+
{
316+
Server.SetRoute("/500-error", context =>
317+
{
318+
context.Response.StatusCode = 500;
319+
return Task.CompletedTask;
320+
});
321+
322+
var response = await Page.GoToAsync(TestConstants.ServerUrl + "/500-error");
323+
Assert.False(response.Ok);
324+
Assert.Equal(HttpStatusCode.InternalServerError, response.Status);
325+
}
326+
297327
[PuppeteerTest("navigation.spec.ts", "Page.goto", "should return last response in redirect chain")]
298328
[PuppeteerFact]
299329
public async Task ShouldReturnLastResponseInRedirectChain()

lib/PuppeteerSharp/FrameManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ private async Task NavigateAsync(CDPSession client, string url, string referrer,
193193

194194
_ensureNewDocumentNavigation = !string.IsNullOrEmpty(response.LoaderId);
195195

196-
if (!string.IsNullOrEmpty(response.ErrorText))
196+
if (!string.IsNullOrEmpty(response.ErrorText) && response.ErrorText != "net::ERR_HTTP_RESPONSE_CODE_FAILURE")
197197
{
198198
throw new NavigationException(response.ErrorText, url);
199199
}

0 commit comments

Comments
 (0)