How to use ShouldFireForFetches method of PuppeteerSharp.Tests.NetworkTests.PageEventRequestTests class

Best Puppeteer-sharp code snippet using PuppeteerSharp.Tests.NetworkTests.PageEventRequestTests.ShouldFireForFetches

Run Puppeteer-sharp automation tests on LambdaTest cloud grid

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

PageEventRequestTests.cs

Source: PageEventRequestTests.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 PageEventRequestTests : PuppeteerPageBaseTest
12    {
13        public PageEventRequestTests(ITestOutputHelper output) : base(output)
14        {
15        }
16
17        [Fact]
18        public async Task ShouldFireForNavigationRequests()
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        }
32
33        [Fact]
34        public async Task ShouldFireForIframes()
35        {
36            var requests = new List<Request>();
37            Page.Request += (sender, e) =>
38            {
39                if (!TestUtils.IsFavicon(e.Request))
40                {
41                    requests.Add(e.Request);
42                }
43            };
44
45            await Page.GoToAsync(TestConstants.EmptyPage);
46
47            await FrameUtils.AttachFrameAsync(Page, "frame1", TestConstants.EmptyPage);
48            Assert.Equal(2, requests.Count);
49        }
50
51        [Fact]
52        public async Task ShouldFireForFetches()
53        {
54            var requests = new List<Request>();
55            Page.Request += (sender, e) =>
56            {
57                if (!TestUtils.IsFavicon(e.Request))
58                {
59                    requests.Add(e.Request);
60                }
61            };
62
63            await Page.GoToAsync(TestConstants.EmptyPage);
64            await Page.EvaluateExpressionAsync("fetch('/empty.html')");
65            Assert.Equal(2, requests.Count);
66        }
67    }
68}
69
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 ShouldFireForFetches code on LambdaTest Cloud Grid

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