-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAutocomplete.cs
More file actions
98 lines (77 loc) · 4.25 KB
/
Autocomplete.cs
File metadata and controls
98 lines (77 loc) · 4.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using System;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Microsoft.Playwright;
using Playwright.ReactUI.Controls.Assertions;
using Playwright.ReactUI.Controls.Constants;
using Playwright.ReactUI.Controls.Extensions;
using Playwright.ReactUI.Controls.Providers;
namespace Playwright.ReactUI.Controls;
public class Autocomplete : ControlBase
{
private readonly Portal portal;
public Autocomplete(ILocator rootLocator)
: base(rootLocator)
{
portal = new Portal(rootLocator.Locator("noscript"));
InputLocator = rootLocator.Locator("input");
}
public ILocator InputLocator { get; }
public async Task<bool> IsDisabledAsync(LocatorIsDisabledOptions? options = default)
=> await InputLocator.IsDisabledAsync(options).ConfigureAwait(false);
public async Task<string> GetValueAsync(LocatorInputValueOptions? options = default)
=> await InputLocator.InputValueAsync(options).ConfigureAwait(false);
public async Task FillAsync(string value, LocatorFillOptions? options = default)
{
await FocusAsync(new LocatorFocusOptions { Timeout = options?.Timeout }).ConfigureAwait(false);
await ClearAsync(new LocatorClearOptions { Timeout = options?.Timeout }).ConfigureAwait(false);
await InputLocator.FillAsync(value, options).ConfigureAwait(false);
}
public async Task PressAsync(string value, LocatorPressOptions? options = default)
=> await InputLocator.PressAsync(value, options).ConfigureAwait(false);
public async Task PressSequentiallyAsync(string value, LocatorPressSequentiallyOptions? options = default)
=> await InputLocator.PressSequentiallyAsync(value, options).ConfigureAwait(false);
public async Task ClearAsync(LocatorClearOptions? options = default)
=> await InputLocator.ClearAsync(options).ConfigureAwait(false);
public async Task FocusAsync(LocatorFocusOptions? options = default)
{
await ExpectV2()
.ToBeEnabledAsync(new LocatorAssertionsToBeEnabledOptions { Timeout = options?.Timeout })
.ConfigureAwait(false);
await InputLocator.FocusAsync(options).ConfigureAwait(false);
}
public async Task BlurAsync(LocatorBlurOptions? options = default)
=> await InputLocator.BlurAsync(options).ConfigureAwait(false);
public override async Task ClickAsync(LocatorClickOptions? options = default)
=> await InputLocator.ClickAsync(options).ConfigureAwait(false);
public async Task SelectFirstSuggestionAsync(LocatorClickOptions? options = default)
{
var suggestions = await GetSuggestionsAsync().ConfigureAwait(false);
await suggestions.First.ClickAsync(options).ConfigureAwait(false);
}
public async Task SelectSuggestionAsync(int index, LocatorClickOptions? options = default)
{
var suggestions = await GetSuggestionsAsync().ConfigureAwait(false);
await suggestions.Nth(index).ClickAsync(options).ConfigureAwait(false);
}
public async Task SelectSuggestionAsync(string text, LocatorClickOptions? options = default)
{
var suggestions = await GetSuggestionsAsync().ConfigureAwait(false);
await suggestions.GetByText(text).ClickAsync(options).ConfigureAwait(false);
}
public async Task SelectSuggestionAsync(Regex regex, LocatorClickOptions? options = default)
{
var suggestions = await GetSuggestionsAsync().ConfigureAwait(false);
await suggestions.GetByText(regex).ClickAsync(options).ConfigureAwait(false);
}
public async Task<Tooltip> GetTooltipAsync(TooltipType type)
=> await TooltipProvider.GetTooltipAsync(type, this).ConfigureAwait(false);
[Obsolete("Используй ExpectV2. В будущих версиях этот метод будет удален")]
public override ILocatorAssertions Expect() => new InputAssertions(RootLocator.Expect(), InputLocator.Expect());
public new AutocompleteAssertionsV2 ExpectV2() => new(this);
private async Task<ILocator> GetSuggestionsAsync()
{
var container = await portal.GetContainerAsync().ConfigureAwait(false);
return container.Locator("[data-tid='MenuItem__root']");
}
}