Skip to content

Commit

Permalink
Fix PageGotoTests (#2238)
Browse files Browse the repository at this point in the history
* Fix PageGotoTests' flakyness.

See puppeteer/puppeteer#8717

* Fix PageGotoTests.ShouldWorkWhenNavigatingTo404 when executed in headful mode.

See puppeteer/puppeteer#9577
  • Loading branch information
leonardo-fernandes committed Jun 15, 2023
1 parent 8b92b87 commit fe0513d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
30 changes: 30 additions & 0 deletions lib/PuppeteerSharp.Tests/NavigationTests/PageGotoTests.cs
Expand Up @@ -294,6 +294,36 @@ public async Task ShouldWorkWhenNavigatingTo404()
Assert.Equal(HttpStatusCode.NotFound, response.Status);
}

[PuppeteerTest("navigation.spec.ts", "Page.goto", "should not throw an error for a 404 response with an empty body")]
[PuppeteerFact]
public async Task ShouldNotThrowAnErrorForA404ResponseWithAnEmptyBody()
{
Server.SetRoute("/404-error", context =>
{
context.Response.StatusCode = 404;
return Task.CompletedTask;
});

var response = await Page.GoToAsync(TestConstants.ServerUrl + "/404-error");
Assert.False(response.Ok);
Assert.Equal(HttpStatusCode.NotFound, response.Status);
}

[PuppeteerTest("navigation.spec.ts", "Page.goto", "should not throw an error for a 500 response with an empty body")]
[PuppeteerFact]
public async Task ShouldNotThrowAnErrorForA500ResponseWithAnEmptyBody()
{
Server.SetRoute("/500-error", context =>
{
context.Response.StatusCode = 500;
return Task.CompletedTask;
});

var response = await Page.GoToAsync(TestConstants.ServerUrl + "/500-error");
Assert.False(response.Ok);
Assert.Equal(HttpStatusCode.InternalServerError, response.Status);
}

[PuppeteerTest("navigation.spec.ts", "Page.goto", "should return last response in redirect chain")]
[PuppeteerFact]
public async Task ShouldReturnLastResponseInRedirectChain()
Expand Down
2 changes: 1 addition & 1 deletion lib/PuppeteerSharp/FrameManager.cs
Expand Up @@ -193,7 +193,7 @@ private async Task NavigateAsync(CDPSession client, string url, string referrer,

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

if (!string.IsNullOrEmpty(response.ErrorText))
if (!string.IsNullOrEmpty(response.ErrorText) && response.ErrorText != "net::ERR_HTTP_RESPONSE_CODE_FAILURE")
{
throw new NavigationException(response.ErrorText, url);
}
Expand Down

0 comments on commit fe0513d

Please sign in to comment.