forked from hardkoded/puppeteer-sharp
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add missing IgnoreHttpsErrors tests (hardkoded#1954)
- Loading branch information
Showing
3 changed files
with
95 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,25 @@ | ||
# How to log network requests | ||
_Contributors: [Meir Blachman](https://github.com/meir017)_ | ||
|
||
## Problem | ||
|
||
You need to monitor the outgoing network requests. | ||
|
||
## Solution | ||
|
||
Use `Page.Request` event to monitor network requests. | ||
|
||
|
||
```cs | ||
using var browser = await Puppeteer.LaunchAsync(new () { Headless = true }); | ||
var page = await browser.NewPageAsync(); | ||
page.Request += (sender, e) => | ||
{ | ||
Console.WriteLine($"Request: {e.Request.Method} {e.Request.Url}"); | ||
foreach (var header in e.Request.Headers) | ||
{ | ||
Console.WriteLine($"{header.Key}: {header.Value}"); | ||
} | ||
}; | ||
await page.GoToAsync("https://example.com"); | ||
``` | ||
# How to log network requests | ||
_Contributors: [Meir Blachman](https://github.com/meir017)_ | ||
|
||
## Problem | ||
|
||
You need to monitor the outgoing network requests. | ||
|
||
## Solution | ||
|
||
Use `Page.Request` event to monitor network requests. | ||
|
||
|
||
```cs | ||
using var browser = await Puppeteer.LaunchAsync(new () { Headless = true }); | ||
var page = await browser.NewPageAsync(); | ||
page.Request += (sender, e) => | ||
{ | ||
Console.WriteLine($"Request: {e.Request.Method} {e.Request.Url}"); | ||
foreach (var header in e.Request.Headers) | ||
{ | ||
Console.WriteLine($"{header.Key}: {header.Value}"); | ||
} | ||
}; | ||
await page.GoToAsync("https://example.com"); | ||
``` |
61 changes: 61 additions & 0 deletions
61
lib/PuppeteerSharp.Tests/IgnoreHttpsErrorsTests/IgnoreHttpsErrorsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Net; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Connections.Features; | ||
using Microsoft.AspNetCore.Http; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
using PuppeteerSharp.Helpers; | ||
using PuppeteerSharp.Tests.Attributes; | ||
using PuppeteerSharp.Xunit; | ||
|
||
namespace PuppeteerSharp.Tests.IgnoreHttpsErrorsTests | ||
{ | ||
[Collection(TestConstants.TestFixtureCollectionName)] | ||
public class IgnoreHttpsErrorsTests : PuppeteerPageBaseTest | ||
{ | ||
public IgnoreHttpsErrorsTests(ITestOutputHelper output) : base(output) | ||
{ | ||
DefaultOptions = TestConstants.DefaultBrowserOptions(); | ||
DefaultOptions.IgnoreHTTPSErrors = true; | ||
} | ||
|
||
[PuppeteerTest("ignorehttpserrors.spec.ts", "ignoreHTTPSErrors", "should work")] | ||
[SkipBrowserFact(skipFirefox: true)] | ||
public async Task ShouldWork() | ||
{ | ||
var response = await Page.GoToAsync($"{TestConstants.HttpsPrefix}/empty.html"); | ||
Assert.True(response.Ok); | ||
} | ||
|
||
[PuppeteerTest("ignorehttpserrors.spec.ts", "ignoreHTTPSErrors", "should work with request interception")] | ||
[SkipBrowserFact(skipFirefox: true)] | ||
public async Task ShouldWorkWithRequestInterception() | ||
{ | ||
await Page.SetRequestInterceptionAsync(true); | ||
Page.Request += async (_, e) => await e.Request.ContinueAsync(); | ||
var response = await Page.GoToAsync(TestConstants.EmptyPage); | ||
Assert.Equal(HttpStatusCode.OK, response.Status); | ||
} | ||
|
||
[PuppeteerTest("ignorehttpserrors.spec.ts", "ignoreHTTPSErrors", "should work with mixed content")] | ||
[SkipBrowserFact(skipFirefox: true)] | ||
public async Task ShouldWorkWithMixedContent() | ||
{ | ||
HttpsServer.SetRoute("/mixedcontent.html", async (context) => | ||
{ | ||
await context.Response.WriteAsync($"<iframe src='{TestConstants.EmptyPage}'></iframe>"); | ||
}); | ||
await Page.GoToAsync(TestConstants.HttpsPrefix + "/mixedcontent.html", new NavigationOptions | ||
{ | ||
WaitUntil = new[] { WaitUntilNavigation.Load } | ||
}); | ||
Assert.Equal(2, Page.Frames.Length); | ||
// Make sure blocked iframe has functional execution context | ||
// @see https://github.com/GoogleChrome/puppeteer/issues/2709 | ||
Assert.Equal(3, await Page.MainFrame.EvaluateExpressionAsync<int>("1 + 2")); | ||
Assert.Equal(5, await Page.FirstChildFrame().EvaluateExpressionAsync<int>("2 + 3")); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters