|
22 | 22 | * SOFTWARE.
|
23 | 23 | */
|
24 | 24 |
|
| 25 | +using System; |
25 | 26 | using System.Text.RegularExpressions;
|
26 | 27 | using System.Threading.Tasks;
|
27 | 28 | using NUnit.Framework;
|
@@ -124,5 +125,32 @@ public async Task ShouldFilterByRegexandRegexpFlags()
|
124 | 125 | await Page.SetContentAsync("<div>Hello \"world\"</div><div>Hello world</div>");
|
125 | 126 | StringAssert.Contains(await Page.Locator("div", new() { HasTextRegex = new Regex("hElLo \"wOrld\"", RegexOptions.IgnoreCase) }).InnerTextAsync(), "Hello \"world\"");
|
126 | 127 | }
|
| 128 | + |
| 129 | + [PlaywrightTest("locator-query.spec.ts", "should support has:locator")] |
| 130 | + public async Task ShouldSupportHasLocator() |
| 131 | + { |
| 132 | + await Page.SetContentAsync("<div><span>hello</span></div><div><span>world</span></div>"); |
| 133 | + Assert.AreEqual(1, await Page.Locator("div", new() { Has = Page.Locator("text=world") }).CountAsync()); |
| 134 | + Assert.AreEqual("<div><span>world</span></div>", await Page.Locator("div", new() { Has = Page.Locator("text=world") }).EvaluateAsync<string>("e => e.outerHTML")); |
| 135 | + Assert.AreEqual(1, await Page.Locator("div", new() { Has = Page.Locator("text=hello") }).CountAsync()); |
| 136 | + Assert.AreEqual("<div><span>hello</span></div>", await Page.Locator("div", new() { Has = Page.Locator("text=hello") }).EvaluateAsync<string>("e => e.outerHTML")); |
| 137 | + Assert.AreEqual(2, await Page.Locator("div", new() { Has = Page.Locator("xpath=./span") }).CountAsync()); |
| 138 | + Assert.AreEqual(1, await Page.Locator("div", new() { Has = Page.Locator("span", new() { HasTextString = "wor" }) }).CountAsync()); |
| 139 | + Assert.AreEqual("<div><span>world</span></div>", await Page.Locator("div", new() { Has = Page.Locator("span", new() { HasTextString = "wor" }) }).EvaluateAsync<string>("e => e.outerHTML")); |
| 140 | + Assert.AreEqual(1, await Page.Locator("div", new() { HasTextString = "wor", Has = Page.Locator("span") }).CountAsync()); |
| 141 | + } |
| 142 | + |
| 143 | + [PlaywrightTest("locator-query.spec.ts", "should enforce same frame for has:locator'")] |
| 144 | + public async Task ShouldEnforceSameFrameForHasLocator() |
| 145 | + { |
| 146 | + await Page.GotoAsync(Server.Prefix + "/frames/two-frames.html"); |
| 147 | + var child = Page.Frames[1]; |
| 148 | + var exception = await PlaywrightAssert.ThrowsAsync<ArgumentException>(() => |
| 149 | + { |
| 150 | + Page.Locator("div", new() { Has = child.Locator("span") }); |
| 151 | + return Task.CompletedTask; |
| 152 | + }); |
| 153 | + Assert.AreEqual(exception.Message, "Inner \"has\" locator must belong to the same frame."); |
| 154 | + } |
127 | 155 | }
|
128 | 156 | }
|
0 commit comments