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

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

Run Puppeteer-sharp automation tests on LambdaTest cloud grid

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


Source: SetJavaScriptEnabledTests.cs Github

1using System;
2using System.Threading.Tasks;
3using Xunit;
4using Xunit.Abstractions;
6namespace PuppeteerSharp.Tests.PageTests
8    [Collection("PuppeteerLoaderFixture collection")]
9    public class SetJavaScriptEnabledTests : PuppeteerPageBaseTest
10    {
11        public SetJavaScriptEnabledTests(ITestOutputHelper output) : base(output)
12        {
13        }
15        [Fact]
16        public async Task ShouldWork()
17        {
18            await Page.SetJavaScriptEnabledAsync(false);
19            await Page.GoToAsync("data:text/html, <script>var something = 'forbidden'</script>");
21            var exception = await Assert.ThrowsAnyAsync<Exception>(async () => await Page.EvaluateExpressionAsync("something"));
22            Assert.Contains("something is not defined", exception.Message);
24            await Page.SetJavaScriptEnabledAsync(true);
25            await Page.GoToAsync("data:text/html, <script>var something = 'forbidden'</script>");
26            Assert.Equal("forbidden", await Page.EvaluateExpressionAsync<string>("something"));
27        }
28    }
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 SetJavaScriptEnabledTests

Trigger SetJavaScriptEnabledTests code on LambdaTest Cloud Grid

Execute automation tests with SetJavaScriptEnabledTests on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

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)