How to use ShouldWorkForFetchRequests method of PuppeteerSharp.Tests.NetworkTests.RequestFrameTests class

Best Puppeteer-sharp code snippet using PuppeteerSharp.Tests.NetworkTests.RequestFrameTests.ShouldWorkForFetchRequests

Run Puppeteer-sharp automation tests on LambdaTest cloud grid

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

RequestFrameTests.cs

Source: RequestFrameTests.cs Github

copy
1using System;
2using System.Linq;
3using System.Collections.Generic;
4using System.Threading.Tasks;
5using Xunit;
6using Xunit.Abstractions;
7
8namespace PuppeteerSharp.Tests.NetworkTests
9{
10    [Collection("PuppeteerLoaderFixture collection")]
11    public class RequestFrameTests : PuppeteerPageBaseTest
12    {
13        public RequestFrameTests(ITestOutputHelper output) : base(output)
14        {
15        }
16
17        [Fact]
18        public async Task ShouldWorkForMainFrameNavigationRequests()
19        {
20            var requests = new List<Request>();
21            Page.Request += (sender, e) =>
22            {
23                if (!TestUtils.IsFavicon(e.Request))
24                {
25                    requests.Add(e.Request);
26                }
27            };
28
29            await Page.GoToAsync(TestConstants.EmptyPage);
30            Assert.Single(requests);
31            Assert.Equal(Page.MainFrame, requests[0].Frame);
32        }
33
34        [Fact]
35        public async Task ShouldWorkForSubframeNavigationRequest()
36        {
37            var requests = new List<Request>();
38            Page.Request += (sender, e) =>
39            {
40                if (!TestUtils.IsFavicon(e.Request))
41                {
42                    requests.Add(e.Request);
43                }
44            };
45
46            await Page.GoToAsync(TestConstants.EmptyPage);
47
48            await FrameUtils.AttachFrameAsync(Page, "frame1", TestConstants.EmptyPage);
49            Assert.Equal(2, requests.Count);
50            Assert.Equal(Page.FirstChildFrame(), requests[1].Frame);
51        }
52
53        [Fact]
54        public async Task ShouldWorkForFetchRequests()
55        {
56            var requests = new List<Request>();
57            Page.Request += (sender, e) =>
58            {
59                if (!TestUtils.IsFavicon(e.Request))
60                {
61                    requests.Add(e.Request);
62                }
63            };
64
65            await Page.GoToAsync(TestConstants.EmptyPage);
66            await Page.EvaluateExpressionAsync("fetch('/empty.html')");
67            Assert.Equal(2, requests.Count);
68            Assert.Equal(Page.MainFrame, requests[0].Frame);
69        }
70    }
71}
72
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 ShouldWorkForFetchRequests code on LambdaTest Cloud Grid

Execute automation tests with ShouldWorkForFetchRequests 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)