How to use LocatorAssertionsToHaveCountOptions method of Microsoft.Playwright.LocatorAssertionsToHaveCountOptions class

Best Playwright-dotnet code snippet using Microsoft.Playwright.LocatorAssertionsToHaveCountOptions.LocatorAssertionsToHaveCountOptions

Run Playwright-dotnet automation tests on LambdaTest cloud grid

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

LocatorAssertionsToHaveCountOptions.cs

Source: LocatorAssertionsToHaveCountOptions.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;
26using System.Collections.Generic;
27using System.ComponentModel.DataAnnotations;
28using System.Drawing;
29using System.Globalization;
30using System.IO;
31using System.Runtime.Serialization;
32using System.Text.Json;
33using System.Text.Json.Serialization;
34using System.Text.RegularExpressions;
35using System.Threading;
36using System.Threading.Tasks;
37
38#nullable enable
39
40namespace Microsoft.Playwright
41{
42    public class LocatorAssertionsToHaveCountOptions
43    {
44        public LocatorAssertionsToHaveCountOptions() { }
45
46        public LocatorAssertionsToHaveCountOptions(LocatorAssertionsToHaveCountOptions clone)
47        {
48            if (clone == null)
49            {
50                return;
51            }
52
53            Timeout = clone.Timeout;
54        }
55
56        /// <summary><para>Time to retry the assertion for.</para></summary>
57        [JsonPropertyName("timeout")]
58        public float? Timeout { get; set; }
59    }
60}
61
62#nullable disable
63
Full Screen

LocatorAssertions.cs

Source: LocatorAssertions.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.Collections.Generic;
26using System.Linq;
27using System.Text.RegularExpressions;
28using System.Threading.Tasks;
29using Microsoft.Playwright.Transport.Protocol;
30
31namespace Microsoft.Playwright.Core
32{
33    internal class LocatorAssertions : AssertionsBase, ILocatorAssertions
34    {
35        public LocatorAssertions(ILocator locator, bool isNot) : base(locator, isNot)
36        {
37        }
38
39        public ILocatorAssertions Not => new LocatorAssertions(ActualLocator, !IsNot);
40
41        public Task ToBeCheckedAsync(LocatorAssertionsToBeCheckedOptions options = null)
42        {
43            var isChecked = options == null || options.Checked == null || options.Checked == true;
44            return ExpectTrueAsync(isChecked ? "to.be.checked" : "to.be.unchecked", $"Locator expected {(!isChecked ? "not " : string.Empty)}to be checked", ConvertToFrameExpectOptions(options));
45        }
46
47        public Task ToBeDisabledAsync(LocatorAssertionsToBeDisabledOptions options = null) => ExpectTrueAsync("to.be.disabled", "Locator expected to be disabled", ConvertToFrameExpectOptions(options));
48
49        public Task ToBeEditableAsync(LocatorAssertionsToBeEditableOptions options = null) => ExpectTrueAsync("to.be.editable", "Locator expected to be editable", ConvertToFrameExpectOptions(options));
50
51        public Task ToBeEmptyAsync(LocatorAssertionsToBeEmptyOptions options = null) => ExpectTrueAsync("to.be.empty", "Locator expected to be empty", ConvertToFrameExpectOptions(options));
52
53        public Task ToBeEnabledAsync(LocatorAssertionsToBeEnabledOptions options = null) => ExpectTrueAsync("to.be.enabled", "Locator expected to be enabled", ConvertToFrameExpectOptions(options));
54
55        public Task ToBeFocusedAsync(LocatorAssertionsToBeFocusedOptions options = null) => ExpectTrueAsync("to.be.focused", "Locator expected to be focused", ConvertToFrameExpectOptions(options));
56
57        public Task ToBeHiddenAsync(LocatorAssertionsToBeHiddenOptions options = null) => ExpectTrueAsync("to.be.hidden", "Locator expected to be hidden", ConvertToFrameExpectOptions(options));
58
59        public Task ToBeVisibleAsync(LocatorAssertionsToBeVisibleOptions options = null) => ExpectTrueAsync("to.be.visible", "Locator expected to be visible", ConvertToFrameExpectOptions(options));
60
61        private Task ExpectTrueAsync(string expression, string message, FrameExpectOptions options)
62        {
63            ExpectedTextValue[] expectedText = null;
64            return ExpectImplAsync(expression, expectedText, null, message, options);
65        }
66
67        public Task ToContainTextAsync(string expected, LocatorAssertionsToContainTextOptions options = null) =>
68            ExpectImplAsync("to.have.text", new ExpectedTextValue() { String = expected, MatchSubstring = true, NormalizeWhiteSpace = true }, expected, "Locator expected to contain text", ConvertToFrameExpectOptions(options));
69
70        public Task ToContainTextAsync(Regex expected, LocatorAssertionsToContainTextOptions options = null) =>
71            ExpectImplAsync("to.have.text", ExpectedRegex(expected, new() { MatchSubstring = true, NormalizeWhiteSpace = true }), expected, "Locator expected text matching regex", ConvertToFrameExpectOptions(options));
72
73        public Task ToContainTextAsync(IEnumerable<string> expected, LocatorAssertionsToContainTextOptions options = null) =>
74            ExpectImplAsync("to.contain.text.array", expected.Select(text => new ExpectedTextValue() { String = text, MatchSubstring = true, NormalizeWhiteSpace = true }).ToArray(), expected, "Locator expected to contain text", ConvertToFrameExpectOptions(options));
75
76        public Task ToContainTextAsync(IEnumerable<Regex> expected, LocatorAssertionsToContainTextOptions options = null) =>
77            ExpectImplAsync("to.contain.text.array", expected.Select(regex => ExpectedRegex(regex, new() { MatchSubstring = true, NormalizeWhiteSpace = true })).ToArray(), expected, "Locator expected text matching regex", ConvertToFrameExpectOptions(options));
78
79        public Task ToHaveAttributeAsync(string name, string value, LocatorAssertionsToHaveAttributeOptions options = null) =>
80            ToHaveAttributeAsync(name, new() { String = value }, value, options);
81
82        public Task ToHaveAttributeAsync(string name, Regex value, LocatorAssertionsToHaveAttributeOptions options = null) =>
83            ToHaveAttributeAsync(name, ExpectedRegex(value), value, options);
84
85        private Task ToHaveAttributeAsync(string name, ExpectedTextValue expectedText, object expectedValue, LocatorAssertionsToHaveAttributeOptions options = null)
86        {
87            var commonOptions = ConvertToFrameExpectOptions(options);
88            commonOptions.ExpressionArg = name;
89            string message = $"Locator expected to have attribute '{name}'";
90            if (expectedValue is Regex)
91            {
92                message += " matching regex";
93            }
94            return ExpectImplAsync("to.have.attribute", expectedText, expectedValue, message, commonOptions);
95        }
96
97        public Task ToHaveClassAsync(string expected, LocatorAssertionsToHaveClassOptions options = null) =>
98            ExpectImplAsync("to.have.class", new ExpectedTextValue() { String = expected }, expected, "Locator expected to have class", ConvertToFrameExpectOptions(options));
99
100        public Task ToHaveClassAsync(Regex expected, LocatorAssertionsToHaveClassOptions options = null) =>
101            ExpectImplAsync("to.have.class", ExpectedRegex(expected), expected, "Locator expected matching regex", ConvertToFrameExpectOptions(options));
102
103        public Task ToHaveClassAsync(IEnumerable<string> expected, LocatorAssertionsToHaveClassOptions options = null) =>
104            ExpectImplAsync("to.have.class.array", expected.Select(text => new ExpectedTextValue() { String = text }).ToArray(), expected, "Locator expected to have class", ConvertToFrameExpectOptions(options));
105
106        public Task ToHaveClassAsync(IEnumerable<Regex> expected, LocatorAssertionsToHaveClassOptions options = null) =>
107            ExpectImplAsync("to.have.class.array", expected.Select(regex => ExpectedRegex(regex)).ToArray(), expected, "Locator expected to have class matching regex", ConvertToFrameExpectOptions(options));
108
109        public Task ToHaveCountAsync(int count, LocatorAssertionsToHaveCountOptions options = null)
110        {
111            ExpectedTextValue[] expectedText = null;
112            var commonOptions = ConvertToFrameExpectOptions(options);
113            commonOptions.ExpectedNumber = count;
114            return ExpectImplAsync("to.have.count", expectedText, count, "Locator expected to have count", commonOptions);
115        }
116
117        public Task ToHaveCSSAsync(string name, string value, LocatorAssertionsToHaveCSSOptions options = null) =>
118            ToHaveCSSAsync(name, new ExpectedTextValue() { String = value }, value, options);
119
120        public Task ToHaveCSSAsync(string name, Regex value, LocatorAssertionsToHaveCSSOptions options = null) =>
121            ToHaveCSSAsync(name, ExpectedRegex(value), value, options);
122
123        internal Task ToHaveCSSAsync(string name, ExpectedTextValue expectedText, object expectedValue, LocatorAssertionsToHaveCSSOptions options = null)
124        {
125            var commonOptions = ConvertToFrameExpectOptions(options);
126            commonOptions.ExpressionArg = name;
127            var message = $"Locator expected to have CSS property '{name}'";
128            if (expectedValue is Regex)
129            {
130                message += " matching regex";
131            }
132            return ExpectImplAsync("to.have.css", expectedText, expectedValue, message, commonOptions);
133        }
134
135        public Task ToHaveIdAsync(string id, LocatorAssertionsToHaveIdOptions options = null) =>
136            ExpectImplAsync("to.have.id", new ExpectedTextValue() { String = id }, id, "Locator expected to have ID", ConvertToFrameExpectOptions(options));
137
138        public Task ToHaveIdAsync(Regex id, LocatorAssertionsToHaveIdOptions options = null) =>
139            ExpectImplAsync("to.have.id", ExpectedRegex(id), id, "Locator expected to have ID", ConvertToFrameExpectOptions(options));
140
141        public Task ToHaveJSPropertyAsync(string name, object value, LocatorAssertionsToHaveJSPropertyOptions options = null)
142        {
143            var commonOptions = ConvertToFrameExpectOptions(options);
144            commonOptions.ExpressionArg = name;
145            commonOptions.ExpectedValue = ScriptsHelper.SerializedArgument(value);
146            ExpectedTextValue[] expectedText = null;
147            return ExpectImplAsync("to.have.property", expectedText, value, $"Locator expected to have JavaScript property '{name}'", commonOptions);
148        }
149
150        public Task ToHaveTextAsync(string expected, LocatorAssertionsToHaveTextOptions options = null) =>
151            ExpectImplAsync("to.have.text", new ExpectedTextValue() { String = expected, NormalizeWhiteSpace = true }, expected, "Locator expected to have text", ConvertToFrameExpectOptions(options));
152
153        public Task ToHaveTextAsync(Regex expected, LocatorAssertionsToHaveTextOptions options = null) =>
154        ExpectImplAsync("to.have.text", ExpectedRegex(expected, new() { NormalizeWhiteSpace = true }), expected, "Locator expected to have text matching regex", ConvertToFrameExpectOptions(options));
155
156        public Task ToHaveTextAsync(IEnumerable<string> expected, LocatorAssertionsToHaveTextOptions options = null) =>
157            ExpectImplAsync("to.have.text.array", expected.Select(text => new ExpectedTextValue() { String = text, NormalizeWhiteSpace = true }).ToArray(), expected, "Locator expected to have text", ConvertToFrameExpectOptions(options));
158
159        public Task ToHaveTextAsync(IEnumerable<Regex> expected, LocatorAssertionsToHaveTextOptions options = null) =>
160            ExpectImplAsync("to.have.text.array", expected.Select(regex => ExpectedRegex(regex, new() { NormalizeWhiteSpace = true })).ToArray(), expected, "Locator expected to have text", ConvertToFrameExpectOptions(options));
161
162        public Task ToHaveValueAsync(string value, LocatorAssertionsToHaveValueOptions options = null) =>
163            ExpectImplAsync("to.have.value", new ExpectedTextValue() { String = value }, value, "Locator expected to have value", ConvertToFrameExpectOptions(options));
164
165        public Task ToHaveValueAsync(Regex value, LocatorAssertionsToHaveValueOptions options = null) =>
166            ExpectImplAsync("to.have.value", ExpectedRegex(value), value, "Locator expected to have value matching regex", ConvertToFrameExpectOptions(options));
167    }
168}
169
Full Screen

ILocatorAssertions.cs

Source: ILocatorAssertions.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;
26using System.Collections.Generic;
27using System.ComponentModel.DataAnnotations;
28using System.Drawing;
29using System.Globalization;
30using System.IO;
31using System.Runtime.Serialization;
32using System.Text.Json;
33using System.Text.Json.Serialization;
34using System.Text.RegularExpressions;
35using System.Threading;
36using System.Threading.Tasks;
37
38#nullable enable
39
40namespace Microsoft.Playwright
41{
42    /// <summary>
43    /// <para>
44    /// The <see cref="ILocatorAssertions"/> class provides assertion methods that can be
45    /// used to make assertions about the <see cref="ILocator"/> state in the tests. A new
46    /// instance of <see cref="ILocatorAssertions"/> is created by calling <see cref="IPlaywrightAssertions.Expect"/>:
47    /// </para>
48    /// <code>
49    /// using System.Text.RegularExpressions;<br/>
50    /// using System.Threading.Tasks;<br/>
51    /// using Microsoft.Playwright.NUnit;<br/>
52    /// using NUnit.Framework;<br/>
53    /// <br/>
54    /// namespace PlaywrightTests<br/>
55    /// {<br/>
56    ///     public class ExampleTests : PageTest<br/>
57    ///     {<br/>
58    ///         [Test]<br/>
59    ///         public async Task StatusBecomesSubmitted()<br/>
60    ///         {<br/>
61    ///             // ..<br/>
62    ///             await Page.ClickAsync("#submit-button");<br/>
63    ///             await Expect(Page.Locator(".status")).ToHaveTextAsync("Submitted");<br/>
64    ///         }<br/>
65    ///     }<br/>
66    /// }
67    /// </code>
68    /// </summary>
69    public partial interface ILocatorAssertions
70    {
71        /// <summary>
72        /// <para>
73        /// Makes the assertion check for the opposite condition. For example, this code tests
74        /// that the Locator doesn't contain text <c>"error"</c>:
75        /// </para>
76        /// <code>await Expect(locator).Not.ToContainTextAsync("error");</code>
77        /// </summary>
78        public ILocatorAssertions Not { get; }
79
80        /// <summary>
81        /// <para>Ensures the <see cref="ILocator"/> points to a checked input.</para>
82        /// <code>
83        /// var locator = Page.Locator(".subscribe");<br/>
84        /// await Expect(locator).ToBeCheckedAsync();
85        /// </code>
86        /// </summary>
87        /// <param name="options">Call options</param>
88        Task ToBeCheckedAsync(LocatorAssertionsToBeCheckedOptions? options = default);
89
90        /// <summary>
91        /// <para>Ensures the <see cref="ILocator"/> points to a disabled element.</para>
92        /// <code>
93        /// var locator = Page.Locator("button.submit");<br/>
94        /// await Expect(locator).ToBeDisabledAsync();
95        /// </code>
96        /// </summary>
97        /// <param name="options">Call options</param>
98        Task ToBeDisabledAsync(LocatorAssertionsToBeDisabledOptions? options = default);
99
100        /// <summary>
101        /// <para>Ensures the <see cref="ILocator"/> points to an editable element.</para>
102        /// <code>
103        /// var locator = Page.Locator("input");<br/>
104        /// await Expect(locator).ToBeEditableAsync();
105        /// </code>
106        /// </summary>
107        /// <param name="options">Call options</param>
108        Task ToBeEditableAsync(LocatorAssertionsToBeEditableOptions? options = default);
109
110        /// <summary>
111        /// <para>
112        /// Ensures the <see cref="ILocator"/> points to an empty editable element or to a DOM
113        /// node that has no text.
114        /// </para>
115        /// <code>
116        /// var locator = Page.Locator("div.warning");<br/>
117        /// await Expect(locator).ToBeEmptyAsync();
118        /// </code>
119        /// </summary>
120        /// <param name="options">Call options</param>
121        Task ToBeEmptyAsync(LocatorAssertionsToBeEmptyOptions? options = default);
122
123        /// <summary>
124        /// <para>Ensures the <see cref="ILocator"/> points to an enabled element.</para>
125        /// <code>
126        /// var locator = Page.Locator("button.submit");<br/>
127        /// await Expect(locator).toBeEnabledAsync();
128        /// </code>
129        /// </summary>
130        /// <param name="options">Call options</param>
131        Task ToBeEnabledAsync(LocatorAssertionsToBeEnabledOptions? options = default);
132
133        /// <summary>
134        /// <para>Ensures the <see cref="ILocator"/> points to a focused DOM node.</para>
135        /// <code>
136        /// var locator = Page.Locator("input");<br/>
137        /// await Expect(locator).ToBeFocusedAsync();
138        /// </code>
139        /// </summary>
140        /// <param name="options">Call options</param>
141        Task ToBeFocusedAsync(LocatorAssertionsToBeFocusedOptions? options = default);
142
143        /// <summary>
144        /// <para>
145        /// Ensures the <see cref="ILocator"/> points to a hidden DOM node, which is the opposite
146        /// of <a href="https://playwright.dev/dotnet/docs/api/actionability#visible">visible</a>.
147        /// </para>
148        /// <code>
149        /// var locator = Page.Locator(".my-element");<br/>
150        /// await Expect(locator).ToBeHiddenAsync();
151        /// </code>
152        /// </summary>
153        /// <param name="options">Call options</param>
154        Task ToBeHiddenAsync(LocatorAssertionsToBeHiddenOptions? options = default);
155
156        /// <summary>
157        /// <para>
158        /// Ensures the <see cref="ILocator"/> points to a <a href="https://playwright.dev/dotnet/docs/api/actionability#visible">visible</a>
159        /// DOM node.
160        /// </para>
161        /// <code>
162        /// var locator = Page.Locator(".my-element");<br/>
163        /// await Expect(locator).ToBeVisibleAsync();
164        /// </code>
165        /// </summary>
166        /// <param name="options">Call options</param>
167        Task ToBeVisibleAsync(LocatorAssertionsToBeVisibleOptions? options = default);
168
169        /// <summary>
170        /// <para>
171        /// Ensures the <see cref="ILocator"/> points to an element that contains the given
172        /// text. You can use regular expressions for the value as well.
173        /// </para>
174        /// <code>
175        /// var locator = Page.Locator(".title");<br/>
176        /// await Expect(locator).ToContainTextAsync("substring");<br/>
177        /// await Expect(locator).ToContainTextAsync(new Regex("\\d messages"));
178        /// </code>
179        /// <para>
180        /// Note that if array is passed as an expected value, entire lists of elements can
181        /// be asserted:
182        /// </para>
183        /// <code>
184        /// var locator = Page.Locator("list &gt; .list-item");<br/>
185        /// await Expect(locator).ToContainTextAsync(new string[] { "Text 1", "Text 4", "Text 5" });
186        /// </code>
187        /// </summary>
188        /// <param name="expected">Expected substring or RegExp or a list of those.</param>
189        /// <param name="options">Call options</param>
190        Task ToContainTextAsync(string expected, LocatorAssertionsToContainTextOptions? options = default);
191
192        /// <summary>
193        /// <para>
194        /// Ensures the <see cref="ILocator"/> points to an element that contains the given
195        /// text. You can use regular expressions for the value as well.
196        /// </para>
197        /// <code>
198        /// var locator = Page.Locator(".title");<br/>
199        /// await Expect(locator).ToContainTextAsync("substring");<br/>
200        /// await Expect(locator).ToContainTextAsync(new Regex("\\d messages"));
201        /// </code>
202        /// <para>
203        /// Note that if array is passed as an expected value, entire lists of elements can
204        /// be asserted:
205        /// </para>
206        /// <code>
207        /// var locator = Page.Locator("list &gt; .list-item");<br/>
208        /// await Expect(locator).ToContainTextAsync(new string[] { "Text 1", "Text 4", "Text 5" });
209        /// </code>
210        /// </summary>
211        /// <param name="expected">Expected substring or RegExp or a list of those.</param>
212        /// <param name="options">Call options</param>
213        Task ToContainTextAsync(Regex expected, LocatorAssertionsToContainTextOptions? options = default);
214
215        /// <summary>
216        /// <para>
217        /// Ensures the <see cref="ILocator"/> points to an element that contains the given
218        /// text. You can use regular expressions for the value as well.
219        /// </para>
220        /// <code>
221        /// var locator = Page.Locator(".title");<br/>
222        /// await Expect(locator).ToContainTextAsync("substring");<br/>
223        /// await Expect(locator).ToContainTextAsync(new Regex("\\d messages"));
224        /// </code>
225        /// <para>
226        /// Note that if array is passed as an expected value, entire lists of elements can
227        /// be asserted:
228        /// </para>
229        /// <code>
230        /// var locator = Page.Locator("list &gt; .list-item");<br/>
231        /// await Expect(locator).ToContainTextAsync(new string[] { "Text 1", "Text 4", "Text 5" });
232        /// </code>
233        /// </summary>
234        /// <param name="expected">Expected substring or RegExp or a list of those.</param>
235        /// <param name="options">Call options</param>
236        Task ToContainTextAsync(IEnumerable<string> expected, LocatorAssertionsToContainTextOptions? options = default);
237
238        /// <summary>
239        /// <para>
240        /// Ensures the <see cref="ILocator"/> points to an element that contains the given
241        /// text. You can use regular expressions for the value as well.
242        /// </para>
243        /// <code>
244        /// var locator = Page.Locator(".title");<br/>
245        /// await Expect(locator).ToContainTextAsync("substring");<br/>
246        /// await Expect(locator).ToContainTextAsync(new Regex("\\d messages"));
247        /// </code>
248        /// <para>
249        /// Note that if array is passed as an expected value, entire lists of elements can
250        /// be asserted:
251        /// </para>
252        /// <code>
253        /// var locator = Page.Locator("list &gt; .list-item");<br/>
254        /// await Expect(locator).ToContainTextAsync(new string[] { "Text 1", "Text 4", "Text 5" });
255        /// </code>
256        /// </summary>
257        /// <param name="expected">Expected substring or RegExp or a list of those.</param>
258        /// <param name="options">Call options</param>
259        Task ToContainTextAsync(IEnumerable<Regex> expected, LocatorAssertionsToContainTextOptions? options = default);
260
261        /// <summary>
262        /// <para>Ensures the <see cref="ILocator"/> points to an element with given attribute.</para>
263        /// <code>
264        /// var locator = Page.Locator("input");<br/>
265        /// await Expect(locator).ToHaveAttributeAsync("type", "text");
266        /// </code>
267        /// </summary>
268        /// <param name="name">Attribute name.</param>
269        /// <param name="value">Expected attribute value.</param>
270        /// <param name="options">Call options</param>
271        Task ToHaveAttributeAsync(string name, string value, LocatorAssertionsToHaveAttributeOptions? options = default);
272
273        /// <summary>
274        /// <para>Ensures the <see cref="ILocator"/> points to an element with given attribute.</para>
275        /// <code>
276        /// var locator = Page.Locator("input");<br/>
277        /// await Expect(locator).ToHaveAttributeAsync("type", "text");
278        /// </code>
279        /// </summary>
280        /// <param name="name">Attribute name.</param>
281        /// <param name="value">Expected attribute value.</param>
282        /// <param name="options">Call options</param>
283        Task ToHaveAttributeAsync(string name, Regex value, LocatorAssertionsToHaveAttributeOptions? options = default);
284
285        /// <summary>
286        /// <para>Ensures the <see cref="ILocator"/> points to an element with given CSS class.</para>
287        /// <code>
288        /// var locator = Page.Locator("#component");<br/>
289        /// await Expect(locator).ToHaveClassAsync(new Regex("selected"));
290        /// </code>
291        /// <para>
292        /// Note that if array is passed as an expected value, entire lists of elements can
293        /// be asserted:
294        /// </para>
295        /// <code>
296        /// var locator = Page.Locator("list &gt; .component");<br/>
297        /// await Expect(locator).ToHaveClassAsync(new string[]{"component", "component selected", "component"});
298        /// </code>
299        /// </summary>
300        /// <param name="expected">Expected class or RegExp or a list of those.</param>
301        /// <param name="options">Call options</param>
302        Task ToHaveClassAsync(string expected, LocatorAssertionsToHaveClassOptions? options = default);
303
304        /// <summary>
305        /// <para>Ensures the <see cref="ILocator"/> points to an element with given CSS class.</para>
306        /// <code>
307        /// var locator = Page.Locator("#component");<br/>
308        /// await Expect(locator).ToHaveClassAsync(new Regex("selected"));
309        /// </code>
310        /// <para>
311        /// Note that if array is passed as an expected value, entire lists of elements can
312        /// be asserted:
313        /// </para>
314        /// <code>
315        /// var locator = Page.Locator("list &gt; .component");<br/>
316        /// await Expect(locator).ToHaveClassAsync(new string[]{"component", "component selected", "component"});
317        /// </code>
318        /// </summary>
319        /// <param name="expected">Expected class or RegExp or a list of those.</param>
320        /// <param name="options">Call options</param>
321        Task ToHaveClassAsync(Regex expected, LocatorAssertionsToHaveClassOptions? options = default);
322
323        /// <summary>
324        /// <para>Ensures the <see cref="ILocator"/> points to an element with given CSS class.</para>
325        /// <code>
326        /// var locator = Page.Locator("#component");<br/>
327        /// await Expect(locator).ToHaveClassAsync(new Regex("selected"));
328        /// </code>
329        /// <para>
330        /// Note that if array is passed as an expected value, entire lists of elements can
331        /// be asserted:
332        /// </para>
333        /// <code>
334        /// var locator = Page.Locator("list &gt; .component");<br/>
335        /// await Expect(locator).ToHaveClassAsync(new string[]{"component", "component selected", "component"});
336        /// </code>
337        /// </summary>
338        /// <param name="expected">Expected class or RegExp or a list of those.</param>
339        /// <param name="options">Call options</param>
340        Task ToHaveClassAsync(IEnumerable<string> expected, LocatorAssertionsToHaveClassOptions? options = default);
341
342        /// <summary>
343        /// <para>Ensures the <see cref="ILocator"/> points to an element with given CSS class.</para>
344        /// <code>
345        /// var locator = Page.Locator("#component");<br/>
346        /// await Expect(locator).ToHaveClassAsync(new Regex("selected"));
347        /// </code>
348        /// <para>
349        /// Note that if array is passed as an expected value, entire lists of elements can
350        /// be asserted:
351        /// </para>
352        /// <code>
353        /// var locator = Page.Locator("list &gt; .component");<br/>
354        /// await Expect(locator).ToHaveClassAsync(new string[]{"component", "component selected", "component"});
355        /// </code>
356        /// </summary>
357        /// <param name="expected">Expected class or RegExp or a list of those.</param>
358        /// <param name="options">Call options</param>
359        Task ToHaveClassAsync(IEnumerable<Regex> expected, LocatorAssertionsToHaveClassOptions? options = default);
360
361        /// <summary>
362        /// <para>Ensures the <see cref="ILocator"/> resolves to an exact number of DOM nodes.</para>
363        /// <code>
364        /// var locator = Page.Locator("list &gt; .component");<br/>
365        /// await Expect(locator).ToHaveCountAsync(3);
366        /// </code>
367        /// </summary>
368        /// <param name="count">Expected count.</param>
369        /// <param name="options">Call options</param>
370        Task ToHaveCountAsync(int count, LocatorAssertionsToHaveCountOptions? options = default);
371
372        /// <summary>
373        /// <para>
374        /// Ensures the <see cref="ILocator"/> resolves to an element with the given computed
375        /// CSS style.
376        /// </para>
377        /// <code>
378        /// var locator = Page.Locator("button");<br/>
379        /// await Expect(locator).ToHaveCSSAsync("display", "flex");
380        /// </code>
381        /// </summary>
382        /// <param name="name">CSS property name.</param>
383        /// <param name="value">CSS property value.</param>
384        /// <param name="options">Call options</param>
385        Task ToHaveCSSAsync(string name, string value, LocatorAssertionsToHaveCSSOptions? options = default);
386
387        /// <summary>
388        /// <para>
389        /// Ensures the <see cref="ILocator"/> resolves to an element with the given computed
390        /// CSS style.
391        /// </para>
392        /// <code>
393        /// var locator = Page.Locator("button");<br/>
394        /// await Expect(locator).ToHaveCSSAsync("display", "flex");
395        /// </code>
396        /// </summary>
397        /// <param name="name">CSS property name.</param>
398        /// <param name="value">CSS property value.</param>
399        /// <param name="options">Call options</param>
400        Task ToHaveCSSAsync(string name, Regex value, LocatorAssertionsToHaveCSSOptions? options = default);
401
402        /// <summary>
403        /// <para>
404        /// Ensures the <see cref="ILocator"/> points to an element with the given DOM Node
405        /// ID.
406        /// </para>
407        /// <code>
408        /// var locator = Page.Locator("input");<br/>
409        /// await Expect(locator).ToHaveIdAsync("lastname");
410        /// </code>
411        /// </summary>
412        /// <param name="id">Element id.</param>
413        /// <param name="options">Call options</param>
414        Task ToHaveIdAsync(string id, LocatorAssertionsToHaveIdOptions? options = default);
415
416        /// <summary>
417        /// <para>
418        /// Ensures the <see cref="ILocator"/> points to an element with the given DOM Node
419        /// ID.
420        /// </para>
421        /// <code>
422        /// var locator = Page.Locator("input");<br/>
423        /// await Expect(locator).ToHaveIdAsync("lastname");
424        /// </code>
425        /// </summary>
426        /// <param name="id">Element id.</param>
427        /// <param name="options">Call options</param>
428        Task ToHaveIdAsync(Regex id, LocatorAssertionsToHaveIdOptions? options = default);
429
430        /// <summary>
431        /// <para>
432        /// Ensures the <see cref="ILocator"/> points to an element with given JavaScript property.
433        /// Note that this property can be of a primitive type as well as a plain serializable
434        /// JavaScript object.
435        /// </para>
436        /// <code>
437        /// var locator = Page.Locator(".component");<br/>
438        /// await Expect(locator).ToHaveJSPropertyAsync("loaded", true);
439        /// </code>
440        /// </summary>
441        /// <param name="name">Property name.</param>
442        /// <param name="value">Property value.</param>
443        /// <param name="options">Call options</param>
444        Task ToHaveJSPropertyAsync(string name, object value, LocatorAssertionsToHaveJSPropertyOptions? options = default);
445
446        /// <summary>
447        /// <para>
448        /// Ensures the <see cref="ILocator"/> points to an element with the given text. You
449        /// can use regular expressions for the value as well.
450        /// </para>
451        /// <code>
452        /// var locator = Page.Locator(".title");<br/>
453        /// await Expect(locator).ToHaveTextAsync(new Regex("Welcome, Test User"));<br/>
454        /// await Expect(locator).ToHaveTextAsync(new Regex("Welcome, .*"));
455        /// </code>
456        /// <para>
457        /// Note that if array is passed as an expected value, entire lists of elements can
458        /// be asserted:
459        /// </para>
460        /// <code>
461        /// var locator = Page.Locator("list &gt; .component");<br/>
462        /// await Expect(locator).toHaveTextAsync(new string[]{ "Text 1", "Text 2", "Text 3" });
463        /// </code>
464        /// </summary>
465        /// <param name="expected">Expected substring or RegExp or a list of those.</param>
466        /// <param name="options">Call options</param>
467        Task ToHaveTextAsync(string expected, LocatorAssertionsToHaveTextOptions? options = default);
468
469        /// <summary>
470        /// <para>
471        /// Ensures the <see cref="ILocator"/> points to an element with the given text. You
472        /// can use regular expressions for the value as well.
473        /// </para>
474        /// <code>
475        /// var locator = Page.Locator(".title");<br/>
476        /// await Expect(locator).ToHaveTextAsync(new Regex("Welcome, Test User"));<br/>
477        /// await Expect(locator).ToHaveTextAsync(new Regex("Welcome, .*"));
478        /// </code>
479        /// <para>
480        /// Note that if array is passed as an expected value, entire lists of elements can
481        /// be asserted:
482        /// </para>
483        /// <code>
484        /// var locator = Page.Locator("list &gt; .component");<br/>
485        /// await Expect(locator).toHaveTextAsync(new string[]{ "Text 1", "Text 2", "Text 3" });
486        /// </code>
487        /// </summary>
488        /// <param name="expected">Expected substring or RegExp or a list of those.</param>
489        /// <param name="options">Call options</param>
490        Task ToHaveTextAsync(Regex expected, LocatorAssertionsToHaveTextOptions? options = default);
491
492        /// <summary>
493        /// <para>
494        /// Ensures the <see cref="ILocator"/> points to an element with the given text. You
495        /// can use regular expressions for the value as well.
496        /// </para>
497        /// <code>
498        /// var locator = Page.Locator(".title");<br/>
499        /// await Expect(locator).ToHaveTextAsync(new Regex("Welcome, Test User"));<br/>
500        /// await Expect(locator).ToHaveTextAsync(new Regex("Welcome, .*"));
501        /// </code>
502        /// <para>
503        /// Note that if array is passed as an expected value, entire lists of elements can
504        /// be asserted:
505        /// </para>
506        /// <code>
507        /// var locator = Page.Locator("list &gt; .component");<br/>
508        /// await Expect(locator).toHaveTextAsync(new string[]{ "Text 1", "Text 2", "Text 3" });
509        /// </code>
510        /// </summary>
511        /// <param name="expected">Expected substring or RegExp or a list of those.</param>
512        /// <param name="options">Call options</param>
513        Task ToHaveTextAsync(IEnumerable<string> expected, LocatorAssertionsToHaveTextOptions? options = default);
514
515        /// <summary>
516        /// <para>
517        /// Ensures the <see cref="ILocator"/> points to an element with the given text. You
518        /// can use regular expressions for the value as well.
519        /// </para>
520        /// <code>
521        /// var locator = Page.Locator(".title");<br/>
522        /// await Expect(locator).ToHaveTextAsync(new Regex("Welcome, Test User"));<br/>
523        /// await Expect(locator).ToHaveTextAsync(new Regex("Welcome, .*"));
524        /// </code>
525        /// <para>
526        /// Note that if array is passed as an expected value, entire lists of elements can
527        /// be asserted:
528        /// </para>
529        /// <code>
530        /// var locator = Page.Locator("list &gt; .component");<br/>
531        /// await Expect(locator).toHaveTextAsync(new string[]{ "Text 1", "Text 2", "Text 3" });
532        /// </code>
533        /// </summary>
534        /// <param name="expected">Expected substring or RegExp or a list of those.</param>
535        /// <param name="options">Call options</param>
536        Task ToHaveTextAsync(IEnumerable<Regex> expected, LocatorAssertionsToHaveTextOptions? options = default);
537
538        /// <summary>
539        /// <para>
540        /// Ensures the <see cref="ILocator"/> points to an element with the given input value.
541        /// You can use regular expressions for the value as well.
542        /// </para>
543        /// <code>
544        /// var locator = Page.Locator("input[type=number]");<br/>
545        /// await Expect(locator).ToHaveValueAsync(new Regex("[0-9]"));
546        /// </code>
547        /// </summary>
548        /// <param name="value">Expected value.</param>
549        /// <param name="options">Call options</param>
550        Task ToHaveValueAsync(string value, LocatorAssertionsToHaveValueOptions? options = default);
551
552        /// <summary>
553        /// <para>
554        /// Ensures the <see cref="ILocator"/> points to an element with the given input value.
555        /// You can use regular expressions for the value as well.
556        /// </para>
557        /// <code>
558        /// var locator = Page.Locator("input[type=number]");<br/>
559        /// await Expect(locator).ToHaveValueAsync(new Regex("[0-9]"));
560        /// </code>
561        /// </summary>
562        /// <param name="value">Expected value.</param>
563        /// <param name="options">Call options</param>
564        Task ToHaveValueAsync(Regex value, LocatorAssertionsToHaveValueOptions? options = default);
565    }
566}
567
568#nullable disable
569
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

Most used method in LocatorAssertionsToHaveCountOptions

Trigger LocatorAssertionsToHaveCountOptions code on LambdaTest Cloud Grid

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