Skip to content

Instantly share code, notes, and snippets.

@YevgeniyShunevych
Last active August 19, 2021 07:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YevgeniyShunevych/ec74f7ade13d3fdfde17e6a783e23d3e to your computer and use it in GitHub Desktop.
Save YevgeniyShunevych/ec74f7ade13d3fdfde17e6a783e23d3e to your computer and use it in GitHub Desktop.
Select2<T, TOwner> control
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