How to use ShouldQueryExistingElement method of PuppeteerSharp.Tests.QuerySelectorTests.PageXPathTests class

Best Puppeteer-sharp code snippet using PuppeteerSharp.Tests.QuerySelectorTests.PageXPathTests.ShouldQueryExistingElement

Run Puppeteer-sharp automation tests on LambdaTest cloud grid

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

PageXPathTests.cs

Source: PageXPathTests.cs Github

copy
1using System.Threading.Tasks;
2using PuppeteerSharp.Tests.Attributes;
3using PuppeteerSharp.Xunit;
4using Xunit;
5using Xunit.Abstractions;
6
7namespace PuppeteerSharp.Tests.QuerySelectorTests
8{
9    [Collection(TestConstants.TestFixtureCollectionName)]
10    public class PageXPathTests : PuppeteerPageBaseTest
11    {
12        public PageXPathTests(ITestOutputHelper output) : base(output)
13        {
14        }
15
16        [PuppeteerTest("queryselector.spec.ts", "Path.$x", "should query existing element")]
17        [PuppeteerFact]
18        public async Task ShouldQueryExistingElement()
19        {
20            await Page.SetContentAsync("<section>test</section>");
21            var elements = await Page.XPathAsync("/html/body/section");
22            Assert.NotNull(elements[0]);
23            Assert.Single(elements);
24        }
25
26        [PuppeteerTest("queryselector.spec.ts", "Path.$x", "should return empty array for non-existing element")]
27        [PuppeteerFact]
28        public async Task ShouldReturnEmptyArrayForNonExistingElement()
29        {
30            var elements = await Page.XPathAsync("/html/body/non-existing-element");
31            Assert.Empty(elements);
32        }
33
34        [PuppeteerTest("queryselector.spec.ts", "Path.$x", "should return multiple elements")]
35        [PuppeteerFact]
36        public async Task ShouldReturnMultipleElements()
37        {
38            await Page.SetContentAsync("<div></div><div></div>");
39            var elements = await Page.XPathAsync("/html/body/div");
40            Assert.Equal(2, elements.Length);
41        }
42    }
43}
44
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 ShouldQueryExistingElement code on LambdaTest Cloud Grid

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