Last active
August 19, 2021 07:19
-
-
Save YevgeniyShunevych/ec74f7ade13d3fdfde17e6a783e23d3e to your computer and use it in GitHub Desktop.
Select2<T, TOwner> control
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Atata | |
{ | |
/// <summary> | |
/// Represents the "Select 2" dropdown control (class: "select2-container"). | |
/// </summary> | |
/// <typeparam name="T">The type of the control's data.</typeparam> | |
/// <typeparam name="TOwner">The type of the owner.</typeparam> | |
[ControlDefinition(ContainingClass = "select2-container", ComponentTypeName = "select")] | |
public class Select2<T, TOwner> : EditableField<T, TOwner> | |
where TOwner : PageObject<TOwner> | |
{ | |
[FindByClass("select2-selection__rendered")] | |
[TraceLog] | |
protected Text<TOwner> SelectedValue { get; private set; } | |
[FindByClass("select2-results", ScopeSource = ScopeSource.Page)] | |
[TraceLog] | |
protected UnorderedList<ListItem<TOwner>, TOwner> Options { get; private set; } | |
protected override T GetValue() | |
{ | |
string valueAsString = SelectedValue.Value; | |
return ConvertStringToValue(valueAsString); | |
} | |
protected override void SetValue(T value) | |
{ | |
string valueAsString = ConvertValueToString(value); | |
Click(); | |
Options[x => x.Content == valueAsString].Click(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment