How to use ShouldWork method of PuppeteerSharp.Tests.ElementHandleTests.BoundingBoxTests class

Best Puppeteer-sharp code snippet using PuppeteerSharp.Tests.ElementHandleTests.BoundingBoxTests.ShouldWork

Run Puppeteer-sharp automation tests on LambdaTest cloud grid

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

BoundingBoxTests.cs

Source: BoundingBoxTests.cs Github

copy
1using System.Threading.Tasks;
2using Xunit;
3using Xunit.Abstractions;
4
5namespace PuppeteerSharp.Tests.ElementHandleTests
6{
7    [Collection("PuppeteerLoaderFixture collection")]
8    public class BoundingBoxTests : PuppeteerPageBaseTest
9    {
10        public BoundingBoxTests(ITestOutputHelper output) : base(output)
11        {
12        }
13
14        [Fact]
15        public async Task ShouldWork()
16        {
17            await Page.SetViewportAsync(new ViewPortOptions
18            {
19                Width = 500,
20                Height = 500
21            });
22            await Page.GoToAsync(TestConstants.ServerUrl + "/grid.html");
23            var elementHandle = await Page.QuerySelectorAsync(".box:nth-of-type(13)");
24            var box = await elementHandle.BoundingBoxAsync();
25            Assert.Equal(new BoundingBox(100, 50, 50, 50), box);
26        }
27
28        [Fact]
29        public async Task ShouldHandleNestedFrames()
30        {
31            await Page.SetViewportAsync(new ViewPortOptions
32            {
33                Width = 500,
34                Height = 500
35            });
36            await Page.GoToAsync(TestConstants.ServerUrl + "/frames/nested-frames.html");
37            var nestedFrame = Page.Frames[1].ChildFrames[1];
38            var elementHandle = await nestedFrame.QuerySelectorAsync("div");
39            var box = await elementHandle.BoundingBoxAsync();
40            Assert.Equal(new BoundingBox(28, 260, 264, 18), box);
41        }
42
43        [Fact]
44        public async Task ShouldReturnNullForInvisibleElements()
45        {
46            await Page.SetContentAsync("<div style='display:none'>hi</div>");
47            var elementHandle = await Page.QuerySelectorAsync("div");
48            Assert.Null(await elementHandle.BoundingBoxAsync());
49        }
50    }
51}
52
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 ShouldWork code on LambdaTest Cloud Grid

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