Skip to content

Instantly share code, notes, and snippets.

@YevgeniyShunevych
Created February 11, 2020 14:18
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/2732c2d989b4bf880d393eb9cd73e64f to your computer and use it in GitHub Desktop.
Save YevgeniyShunevych/2732c2d989b4bf880d393eb9cd73e64f to your computer and use it in GitHub Desktop.
Atata component for AngularJS Material Select
namespace Atata.AngularJS.Material
{
[ControlDefinition("md-option", ComponentTypeName = "option")]
public class MDOption<T, TOwner> : Field<T, TOwner>
where TOwner : PageObject<TOwner>
{
[FindByClass("md-text")]
public Text<TOwner> Text { get; private set; }
protected override T GetValue()
{
return ConvertStringToValueUsingGetFormat(Text.Value);
}
}
}
namespace Atata.AngularJS.Material
{
[ControlDefinition("md-select", ComponentTypeName = "select")]
[ControlFinding(FindTermBy.Label)]
public class MDSelect<T, TOwner> : EditableField<T, TOwner>
where TOwner : PageObject<TOwner>
{
[ControlDefinition("div", ContainingClass = "md-select-menu-container", ComponentTypeName = "drop-down menu")]
[FindFirst(ScopeSource = ScopeSource.Page)]
public ItemsControl<MDOption<T, TOwner>, TOwner> Options { get; private set; }
[ControlDefinition("md-select-value", ComponentTypeName = "selected value text")]
protected Text<TOwner> SelectedValueText { get; private set; }
protected override T GetValue()
{
string valueAsString = SelectedValueText.Value;
return ConvertStringToValueUsingGetFormat(valueAsString);
}
protected override void SetValue(T value)
{
Click();
string valueAsString = ConvertValueToStringUsingSetFormat(value);
var option = Options.Items.GetByXPathCondition(valueAsString, $"normalize-space(.) = '{valueAsString}'");
option.Click();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment