How to use ShouldNotCheckTheCheckedBox method of Microsoft.Playwright.Tests.PageCheckTests class

Best Playwright-dotnet code snippet using Microsoft.Playwright.Tests.PageCheckTests.ShouldNotCheckTheCheckedBox

Run Playwright-dotnet automation tests on LambdaTest cloud grid

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

PageCheckTests.cs

Source: PageCheckTests.cs Github

copy
1/*
2 * MIT License
3 *
4 * Copyright (c) Microsoft Corporation.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24
25using System.Threading.Tasks;
26using Microsoft.Playwright.NUnit;
27using NUnit.Framework;
28
29namespace Microsoft.Playwright.Tests
30{
31    public class PageCheckTests : PageTestEx
32    {
33        [PlaywrightTest("page-check.spec.ts", "should check the box")]
34        public async Task ShouldCheckTheBox()
35        {
36            await Page.SetContentAsync("<input id='checkbox' type='checkbox'></input>");
37            await Page.CheckAsync("input");
38            Assert.True(await Page.EvaluateAsync<bool?>("checkbox.checked"));
39        }
40
41        [PlaywrightTest("page-check.spec.ts", "should not check the checked box")]
42        public async Task ShouldNotCheckTheCheckedBox()
43        {
44            await Page.SetContentAsync("<input id='checkbox' type='checkbox' checked></input>");
45            await Page.CheckAsync("input");
46            Assert.True(await Page.EvaluateAsync<bool?>("checkbox.checked"));
47        }
48
49        [PlaywrightTest("page-check.spec.ts", "should uncheck the box")]
50        public async Task ShouldUncheckTheBox()
51        {
52            await Page.SetContentAsync("<input id='checkbox' type='checkbox' checked></input>");
53            await Page.UncheckAsync("input");
54            Assert.False(await Page.EvaluateAsync<bool?>("checkbox.checked"));
55        }
56
57        [PlaywrightTest("page-check.spec.ts", "should check the box by label")]
58        public async Task ShouldCheckTheBoxByLabel()
59        {
60            await Page.SetContentAsync("<label for='checkbox'><input id='checkbox' type='checkbox'></input></label>");
61            await Page.CheckAsync("label");
62            Assert.True(await Page.EvaluateAsync<bool?>("checkbox.checked"));
63        }
64
65        [PlaywrightTest("page-check.spec.ts", "should check the box outside label")]
66        public async Task ShouldCheckTheBoxOutsideLabel()
67        {
68            await Page.SetContentAsync("<label for='checkbox'>Text</label><div><input id='checkbox' type='checkbox'></input></div>");
69            await Page.CheckAsync("label");
70            Assert.True(await Page.EvaluateAsync<bool?>("checkbox.checked"));
71        }
72
73        [PlaywrightTest("page-check.spec.ts", "should check the box inside label w/o id")]
74        public async Task ShouldCheckTheBoxInsideLabelWoId()
75        {
76            await Page.SetContentAsync("<label>Text<span><input id='checkbox' type='checkbox'></input></span></label>");
77            await Page.CheckAsync("label");
78            Assert.True(await Page.EvaluateAsync<bool?>("checkbox.checked"));
79        }
80
81        [PlaywrightTest("page-check.spec.ts", "should check radio")]
82        public async Task ShouldCheckRadio()
83        {
84            await Page.SetContentAsync(@"
85                <input type='radio'>one</input>
86                <input id='two' type='radio'>two</input>
87                <input type='radio'>three</input>");
88            await Page.CheckAsync("#two");
89            Assert.True(await Page.EvaluateAsync<bool?>("two.checked"));
90        }
91
92        [PlaywrightTest("page-check.spec.ts", "should check the box by aria role")]
93        public async Task ShouldCheckTheBoxByAriaRole()
94        {
95            await Page.SetContentAsync(@"
96                <div role='checkbox' id='checkbox'>CHECKBOX</div>
97                <script>
98                checkbox.addEventListener('click', () => checkbox.setAttribute('aria-checked', 'true'));
99                </script>");
100            await Page.CheckAsync("div");
101            Assert.AreEqual("true", await Page.EvaluateAsync<string>("checkbox.getAttribute('aria-checked')"));
102        }
103
104        [PlaywrightTest("page-check.spec.ts", "trial run should not check")]
105        public async Task TrialRunShouldNotCheck()
106        {
107            await Page.SetContentAsync("<input id='checkbox' type='checkbox'></input>");
108            await Page.CheckAsync("input", new() { Trial = true });
109            Assert.False(await Page.EvaluateAsync<bool>("window['checkbox'].checked"));
110        }
111
112        [PlaywrightTest("page-check.spec.ts", "trial run should not uncheck")]
113        public async Task TrialRunShouldNotUncheck()
114        {
115            await Page.SetContentAsync("<input id='checkbox' type='checkbox' checked></input>");
116            await Page.CheckAsync("input", new() { Trial = true });
117            Assert.True(await Page.EvaluateAsync<bool>("window['checkbox'].checked"));
118        }
119
120        [PlaywrightTest("page-check.spec.ts", "should check the box using setChecked")]
121        public async Task ShouldCheckTheBoxUsingSetChecked()
122        {
123            await Page.SetContentAsync("<input id='checkbox' type='checkbox'></input>");
124            await Page.SetCheckedAsync("input", true);
125            Assert.IsTrue(await Page.EvaluateAsync<bool>("checkbox.checked"));
126            await Page.SetCheckedAsync("input", false);
127            Assert.IsFalse(await Page.EvaluateAsync<bool>("checkbox.checked"));
128        }
129
130    }
131}
132
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 ShouldNotCheckTheCheckedBox code on LambdaTest Cloud Grid

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