How to use MultiplePagesShouldNotShareSameScreenshotTaskQueue method of PuppeteerSharp.Tests.Issues.Issue1878 class

Best Puppeteer-sharp code snippet using PuppeteerSharp.Tests.Issues.Issue1878.MultiplePagesShouldNotShareSameScreenshotTaskQueue

Run Puppeteer-sharp automation tests on LambdaTest cloud grid

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

Issue1878.cs

Source: Issue1878.cs Github

copy
1using System.Threading.Tasks;
2using PuppeteerSharp.Tests.Attributes;
3using Xunit;
4using Xunit.Abstractions;
5
6namespace PuppeteerSharp.Tests.Issues
7{
8    [Collection(TestConstants.TestFixtureCollectionName)]
9    public class Issue1878 : PuppeteerBrowserContextBaseTest
10    {
11        public Issue1878(ITestOutputHelper output) : base(output)
12        {
13        }
14
15        [SkipBrowserFact(skipFirefox: true)]
16        public async Task MultiplePagesShouldNotShareSameScreenshotTaskQueue()
17        {
18            // 1st page
19            using (Page page = await Context.NewPageAsync())
20            {
21                var html = "...some html..";
22                await page.GoToAsync($"data:text/html,{html}", new NavigationOptions
23                {
24                    WaitUntil = new[]
25                    {
26                        WaitUntilNavigation.DOMContentLoaded,
27                        WaitUntilNavigation.Load,
28                        WaitUntilNavigation.Networkidle0,
29                        WaitUntilNavigation.Networkidle2
30                    }
31                });
32
33                await page.ScreenshotAsync("...some path...");
34            }
35
36            //2nd page
37            using (Page page = await Context.NewPageAsync())
38            {
39                var html = "...some html...";
40                await page.GoToAsync($"data:text/html,{html}", new NavigationOptions
41                {
42                    WaitUntil = new[]
43                    {
44                        WaitUntilNavigation.DOMContentLoaded,
45                        WaitUntilNavigation.Load,
46                        WaitUntilNavigation.Networkidle0,
47                        WaitUntilNavigation.Networkidle2
48                    }
49                });
50
51                await page.ScreenshotAsync("...some path..."); //<- will throw because Browser TaskQueue is disposed when 1st Page is disposed
52            }
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 MultiplePagesShouldNotShareSameScreenshotTaskQueue code on LambdaTest Cloud Grid

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