How to use ShouldStayDisabledWhenTogglingRequestInterceptionOnOff method of PuppeteerSharp.Tests.PageTests.SetCacheEnabledTests class

Best Puppeteer-sharp code snippet using PuppeteerSharp.Tests.PageTests.SetCacheEnabledTests.ShouldStayDisabledWhenTogglingRequestInterceptionOnOff

Run Puppeteer-sharp automation tests on LambdaTest cloud grid

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

SetCacheEnabledTests.cs

Source: SetCacheEnabledTests.cs Github

copy
1using System.Collections.Generic;
2using System.Linq;
3using System.Threading.Tasks;
4using Xunit;
5using Xunit.Abstractions;
6
7namespace PuppeteerSharp.Tests.PageTests
8{
9    [Collection("PuppeteerLoaderFixture collection")]
10    public class SetCacheEnabledTests : PuppeteerPageBaseTest
11    {
12        public SetCacheEnabledTests(ITestOutputHelper output) : base(output)
13        {
14        }
15
16        [Fact]
17        public async Task ShouldEnableOrDisableTheCacheBasedOnTheStatePassed()
18        {
19            await Page.GoToAsync(TestConstants.ServerUrl + "/cached/one-style.html");
20            var waitForRequestTask = Server.WaitForRequest<string>("/cached/one-style.html", (request) => request.Headers["if-modified-since"]);
21
22            await Task.WhenAll(
23                waitForRequestTask,
24                Page.ReloadAsync());
25
26            Assert.False(string.IsNullOrEmpty(waitForRequestTask.Result));
27
28            await Page.SetCacheEnabledAsync(false);
29            waitForRequestTask = Server.WaitForRequest<string>("/cached/one-style.html", (request) => request.Headers["if-modified-since"]);
30
31            await Task.WhenAll(
32                waitForRequestTask,
33                Page.ReloadAsync());
34
35            Assert.True(string.IsNullOrEmpty(waitForRequestTask.Result));
36        }
37
38        [Fact]
39        public async Task ShouldStayDisabledWhenTogglingRequestInterceptionOnOff()
40        {
41            await Page.SetCacheEnabledAsync(false);
42            await Page.SetRequestInterceptionAsync(true);
43            await Page.SetRequestInterceptionAsync(false);
44
45            await Page.GoToAsync(TestConstants.ServerUrl + "/cached/one-style.html");
46            var waitForRequestTask = Server.WaitForRequest<string>("/cached/one-style.html", (request) => request.Headers["if-modified-since"]);
47
48            await Task.WhenAll(
49              waitForRequestTask,
50              Page.ReloadAsync());
51
52            Assert.True(string.IsNullOrEmpty(waitForRequestTask.Result));
53        }
54    }
55}
56
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 ShouldStayDisabledWhenTogglingRequestInterceptionOnOff code on LambdaTest Cloud Grid

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