How to use PageEmulateNetworkConditionsTests class of PuppeteerSharp.Tests.EmulationTests package

Best Puppeteer-sharp code snippet using PuppeteerSharp.Tests.EmulationTests.PageEmulateNetworkConditionsTests

Run Puppeteer-sharp automation tests on LambdaTest cloud grid

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


Source: PageEmulateNetworkConditionsTests.cs Github

1using System.Threading.Tasks;
2using PuppeteerSharp.Tests.Attributes;
3using PuppeteerSharp.Xunit;
4using Xunit;
5using Xunit.Abstractions;
7namespace PuppeteerSharp.Tests.EmulationTests
9    [Collection(TestConstants.TestFixtureCollectionName)]
10    public class PageEmulateNetworkConditionsTests : PuppeteerPageBaseTest
11    {
12        public PageEmulateNetworkConditionsTests(ITestOutputHelper output) : base(output)
13        {
14        }
16        [PuppeteerTest("emulation.spec.ts", "Page.emulateNetworkConditions", "should change navigator.connection.effectiveType")]
17        [SkipBrowserFact(skipFirefox: true)]
18        public async Task ShouldChangeNavigatorConnectionEffectiveType()
19        {
20            var slow3G = Puppeteer.NetworkConditions[NetworkConditions.Slow3G];
21            var fast3G = Puppeteer.NetworkConditions[NetworkConditions.Fast3G];
23            Assert.Equal("4g", await Page.EvaluateExpressionAsync<string>("window.navigator.connection.effectiveType").ConfigureAwait(false));
24            await Page.EmulateNetworkConditionsAsync(fast3G);
25            Assert.Equal("3g", await Page.EvaluateExpressionAsync<string>("window.navigator.connection.effectiveType").ConfigureAwait(false));
26            await Page.EmulateNetworkConditionsAsync(slow3G);
27            Assert.Equal("2g", await Page.EvaluateExpressionAsync<string>("window.navigator.connection.effectiveType").ConfigureAwait(false));
28            await Page.EmulateNetworkConditionsAsync(null);
29        }
30    }
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

Most used methods in PageEmulateNetworkConditionsTests

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

Test now for Free

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

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)