How to use ResponseSecurityDetailsTests method of PuppeteerSharp.Tests.IgnoreHttpsErrorsTests.ResponseSecurityDetailsTests class

Best Puppeteer-sharp code snippet using PuppeteerSharp.Tests.IgnoreHttpsErrorsTests.ResponseSecurityDetailsTests.ResponseSecurityDetailsTests

Run Puppeteer-sharp automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

ResponseSecurityDetailsTests.cs

Source: ResponseSecurityDetailsTests.cs Github

copy
1using System;
2using System.Collections.Generic;
3using System.Net;
4using System.Threading.Tasks;
5using Microsoft.AspNetCore.Connections.Features;
6using Microsoft.AspNetCore.Http;
7using Xunit;
8using Xunit.Abstractions;
9using PuppeteerSharp.Helpers;
10using PuppeteerSharp.Tests.Attributes;
11using PuppeteerSharp.Xunit;
12
13namespace PuppeteerSharp.Tests.IgnoreHttpsErrorsTests
14{
15    [Collection(TestConstants.TestFixtureCollectionName)]
16    public class ResponseSecurityDetailsTests : PuppeteerPageBaseTest
17    {
18        public ResponseSecurityDetailsTests(ITestOutputHelper output) : base(output)
19        {
20            DefaultOptions = TestConstants.DefaultBrowserOptions();
21            DefaultOptions.IgnoreHTTPSErrors = true;
22        }
23
24        [PuppeteerTest("ignorehttpserrors.spec.ts", "Response.securityDetails", "Should Work")]
25        [SkipBrowserFact(skipFirefox: true)]
26        public async Task ShouldWork()
27        {
28            var requestTask = HttpsServer.WaitForRequest(
29                "/empty.html",
30                request => request?.HttpContext?.Features?.Get<ITlsHandshakeFeature>()?.Protocol);
31            var responseTask = Page.GoToAsync(TestConstants.HttpsPrefix + "/empty.html");
32
33            await Task.WhenAll(
34                requestTask,
35                responseTask).WithTimeout();
36
37            var response = responseTask.Result;
38            Assert.Equal(HttpStatusCode.OK, response.Status);
39            Assert.NotNull(response.SecurityDetails);
40            Assert.Equal(
41                TestUtils.CurateProtocol(requestTask.Result.ToString()),
42                TestUtils.CurateProtocol(response.SecurityDetails.Protocol));
43        }
44
45        [PuppeteerTest("ignorehttpserrors.spec.ts", "Response.securityDetails", "Network redirects should report SecurityDetails")]
46        [SkipBrowserFact(skipFirefox: true)]
47        public async Task NetworkRedirectsShouldReportSecurityDetails()
48        {
49            var responses = new List<Response>();
50            HttpsServer.SetRedirect("/plzredirect", "/empty.html");
51
52            Page.Response += (_, e) => responses.Add(e.Response);
53
54            var requestTask = HttpsServer.WaitForRequest(
55                "/empty.html",
56                request => request?.HttpContext?.Features?.Get<ITlsHandshakeFeature>()?.Protocol);
57            var responseTask = Page.GoToAsync(TestConstants.HttpsPrefix + "/plzredirect");
58
59            await Task.WhenAll(
60                requestTask,
61                responseTask).WithTimeout();
62
63            var response = responseTask.Result;
64
65            Assert.Equal(2, responses.Count);
66            Assert.Equal(HttpStatusCode.Found, responses[0].Status);
67            Assert.Equal(
68                TestUtils.CurateProtocol(requestTask.Result.ToString()),
69                TestUtils.CurateProtocol(response.SecurityDetails.Protocol));
70        }
71
72        [PuppeteerTest("ignorehttpserrors.spec.ts", "Response.securityDetails", "should work with request interception")]
73        [SkipBrowserFact(skipFirefox: true)]
74        public async Task ShouldWorkWithRequestInterception()
75        {
76            await Page.SetRequestInterceptionAsync(true);
77            Page.Request += async (_, e) => await e.Request.ContinueAsync();
78            var response = await Page.GoToAsync(TestConstants.EmptyPage);
79            Assert.Equal(HttpStatusCode.OK, response.Status);
80        }
81
82        [PuppeteerTest("ignorehttpserrors.spec.ts", "Response.securityDetails", "should work with mixed content")]
83        [SkipBrowserFact(skipFirefox: true)]
84        public async Task ShouldWorkWithMixedContent()
85        {
86            HttpsServer.SetRoute("/mixedcontent.html", async (context) =>
87            {
88                await context.Response.WriteAsync($"<iframe src='{TestConstants.EmptyPage}'></iframe>");
89            });
90            await Page.GoToAsync(TestConstants.HttpsPrefix + "/mixedcontent.html", new NavigationOptions
91            {
92                WaitUntil = new[] { WaitUntilNavigation.Load }
93            });
94            Assert.Equal(2, Page.Frames.Length);
95            // Make sure blocked iframe has functional execution context
96            // @see https://github.com/GoogleChrome/puppeteer/issues/2709
97            Assert.Equal(3, await Page.MainFrame.EvaluateExpressionAsync<int>("1 + 2"));
98            Assert.Equal(5, await Page.FirstChildFrame().EvaluateExpressionAsync<int>("2 + 3"));
99        }
100    }
101}
102
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Trigger ResponseSecurityDetailsTests code on LambdaTest Cloud Grid

Execute automation tests with ResponseSecurityDetailsTests on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)