How to use OfflineModeTests method of PuppeteerSharp.Tests.PageTests.OfflineModeTests class

Best Puppeteer-sharp code snippet using PuppeteerSharp.Tests.PageTests.OfflineModeTests.OfflineModeTests

Run Puppeteer-sharp automation tests on LambdaTest cloud grid

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

OfflineModeTests.cs

Source: OfflineModeTests.cs Github

copy
1using System.Net;
2using System.Threading.Tasks;
3using Xunit;
4using Xunit.Abstractions;
5
6namespace PuppeteerSharp.Tests.PageTests
7{
8    [Collection("PuppeteerLoaderFixture collection")]
9    public class OfflineModeTests : PuppeteerPageBaseTest
10    {
11        public OfflineModeTests(ITestOutputHelper output) : base(output)
12        {
13        }
14
15        [Fact]
16        public async Task ShouldWork()
17        {
18            await Page.SetOfflineModeAsync(true);
19            await Assert.ThrowsAsync<NavigationException>(async () => await Page.GoToAsync(TestConstants.EmptyPage));
20
21            await Page.SetOfflineModeAsync(false);
22            var response = await Page.ReloadAsync();
23            Assert.Equal(HttpStatusCode.OK, response.Status);
24        }
25
26        [Fact]
27        public async Task ShouldEmulateNavigatorOnLine()
28        {
29            Assert.True(await Page.EvaluateExpressionAsync<bool>("window.navigator.onLine"));
30
31            await Page.SetOfflineModeAsync(true);
32            Assert.False(await Page.EvaluateExpressionAsync<bool>("window.navigator.onLine"));
33
34            await Page.SetOfflineModeAsync(false);
35            Assert.True(await Page.EvaluateExpressionAsync<bool>("window.navigator.onLine"));
36        }
37    }
38}
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 method in OfflineModeTests

Trigger OfflineModeTests code on LambdaTest Cloud Grid

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