How to use ShouldSelectMultipleOptions method of PuppeteerSharp.Tests.PageTests.SelectTests class

Best Puppeteer-sharp code snippet using PuppeteerSharp.Tests.PageTests.SelectTests.ShouldSelectMultipleOptions

Run Puppeteer-sharp automation tests on LambdaTest cloud grid

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

SelectTests.cs

Source: SelectTests.cs Github

copy
1using System;
2using System.Threading.Tasks;
3using Xunit;
4using Xunit.Abstractions;
5
6namespace PuppeteerSharp.Tests.PageTests
7{
8    [Collection("PuppeteerLoaderFixture collection")]
9    public class SelectTests : PuppeteerPageBaseTest
10    {
11        public SelectTests(ITestOutputHelper output) : base(output)
12        {
13        }
14
15        [Fact]
16        public async Task ShouldSelectSingleOption()
17        {
18            await Page.GoToAsync(TestConstants.ServerUrl + "/input/select.html");
19            await Page.SelectAsync("select", "blue");
20            Assert.Equal(new string[] { "blue" }, await Page.EvaluateExpressionAsync<string[]>("result.onInput"));
21            Assert.Equal(new string[] { "blue" }, await Page.EvaluateExpressionAsync<string[]>("result.onChange"));
22        }
23
24        [Fact]
25        public async Task ShouldSelectMultipleOptions()
26        {
27            await Page.GoToAsync(TestConstants.ServerUrl + "/input/select.html");
28            await Page.EvaluateExpressionAsync("makeMultiple()");
29            await Page.SelectAsync("select", "blue", "green", "red");
30            Assert.Equal(new string[] { "blue", "green", "red" },
31                         await Page.EvaluateExpressionAsync<string[]>("result.onInput"));
32            Assert.Equal(new string[] { "blue", "green", "red" },
33                         await Page.EvaluateExpressionAsync<string[]>("result.onChange"));
34        }
35
36        [Fact]
37        public async Task ShouldRespectEventBubbling()
38        {
39            await Page.GoToAsync(TestConstants.ServerUrl + "/input/select.html");
40            await Page.SelectAsync("select", "blue");
41            Assert.Equal(new string[] { "blue" }, await Page.EvaluateExpressionAsync<string[]>("result.onBubblingInput"));
42            Assert.Equal(new string[] { "blue" }, await Page.EvaluateExpressionAsync<string[]>("result.onBubblingChange"));
43        }
44
45        [Fact]
46        public async Task ShouldThrowWhenElementIsNotASelect()
47        {
48            await Page.GoToAsync(TestConstants.ServerUrl + "/input/select.html");
49            var exception = await Assert.ThrowsAsync<EvaluationFailedException>(async () => await Page.SelectAsync("body", ""));
50            Assert.Contains("Element is not a <select> element.", exception.Message);
51        }
52
53        [Fact]
54        public async Task ShouldReturnEmptyArrayOnNoMatchedValues()
55        {
56            await Page.GoToAsync(TestConstants.ServerUrl + "/input/select.html");
57            var result = await Page.SelectAsync("select", "42", "abc");
58            Assert.Empty(result);
59        }
60
61        [Fact]
62        public async Task ShouldReturnAnArrayOfMatchedValues()
63        {
64            await Page.GoToAsync(TestConstants.ServerUrl + "/input/select.html");
65            await Page.EvaluateExpressionAsync("makeMultiple()");
66            var result = await Page.SelectAsync("select", "blue", "black", "magenta");
67            Array.Sort(result);
68            Assert.Equal(new string[] { "black", "blue", "magenta" }, result);
69        }
70
71        [Fact]
72        public async Task ShouldReturnAnArrayOfOneElementWhenMultipleIsNotSet()
73        {
74            await Page.GoToAsync(TestConstants.ServerUrl + "/input/select.html");
75            Assert.Single(await Page.SelectAsync("select", "42", "blue", "black", "magenta"));
76        }
77
78        [Fact]
79        public async Task ShouldReturnEmptyArrayOnNoValues()
80        {
81            await Page.GoToAsync(TestConstants.ServerUrl + "/input/select.html");
82            Assert.Empty(await Page.SelectAsync("select"));
83        }
84
85        [Fact]
86        public async Task ShouldDeselectAllOptionsWhenPassedNoValuesForAMultipleSelect()
87        {
88            await Page.GoToAsync(TestConstants.ServerUrl + "/input/select.html");
89            await Page.EvaluateExpressionAsync("makeMultiple()");
90            await Page.SelectAsync("select", "blue", "black", "magenta");
91            await Page.SelectAsync("select");
92            Assert.True(await Page.QuerySelectorAsync("select").EvaluateFunctionAsync<bool>(
93                "select => Array.from(select.options).every(option => !option.selected)"));
94        }
95
96        [Fact]
97        public async Task ShouldDeselectAllOptionsWhenPassedNoValuesForASelectWithoutMultiple()
98        {
99            await Page.GoToAsync(TestConstants.ServerUrl + "/input/select.html");
100            await Page.SelectAsync("select", "blue", "black", "magenta");
101            await Page.SelectAsync("select");
102            Assert.True(await Page.QuerySelectorAsync("select").EvaluateFunctionAsync<bool>(
103                "select => Array.from(select.options).every(option => !option.selected)"));
104        }
105    }
106}
107
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
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)