public static void AppendValue(AutomationElement element, string value) { StringBuilder sb = new StringBuilder(); sb.Append(AutomationPatternHelper.GetValuePattern(element).Current.Value); sb.Append(value); SetValue(element, sb.ToString()); }
public static void Expand(AutomationElement element) { ExpandCollapsePattern currentPattern = AutomationPatternHelper.GetExpandCollapsePattern(element); if (currentPattern.Current.ExpandCollapseState == ExpandCollapseState.Collapsed) { currentPattern.Expand(); } }
public static void Minimize(AutomationElement element) { WindowPattern currentPattern = AutomationPatternHelper.GetWindowPattern(element); if (currentPattern.Current.CanMinimize) { currentPattern.SetWindowVisualState(WindowVisualState.Minimized); } }
public static void AssertRangeValue(AutomationElement element, double expected) { RangeValuePattern currentPattern = AutomationPatternHelper.GetRangeValuePattern(element); double num = currentPattern.Current.Value; if (expected != num) { throw new Exception(string.Format("RangeValue is not as expected. Expected: {0}, Actual: {1}. ({2})", expected, num, element.ToString())); } }
public static void AssertReadyForUserInteraction(AutomationElement element) { WindowPattern currentPattern = AutomationPatternHelper.GetWindowPattern(element); WindowInteractionState windowInteractionState = currentPattern.Current.WindowInteractionState; if (windowInteractionState != WindowInteractionState.ReadyForUserInteraction) { throw new Exception(string.Format("Window is not ready for user interaction. State is {0}. ({1})", windowInteractionState.ToString(), element.ToString())); } }
public static void AssertSelected(AutomationElement element, bool expected) { SelectionItemPattern currentPattern = AutomationPatternHelper.GetSelectionItemPattern(element); bool isSelected = currentPattern.Current.IsSelected; if (expected != isSelected) { throw new Exception(string.Format("Selected is not as expected. Expected: {0}, Actual: {1}. ({2})", expected, isSelected, element.ToString())); } }
public static string GetWindowState(AutomationElement element) { try { WindowPattern currentPattern = AutomationPatternHelper.GetWindowPattern(element); return(currentPattern.Current.WindowInteractionState.ToString()); } catch (Exception exception) { return("Unable to retrieve window state. " + exception.Message); } }
public static void Toggle(AutomationElement element, bool toggle) { TogglePattern currentPattern = AutomationPatternHelper.GetTogglePattern(element); ToggleState indeterminate = ToggleState.Indeterminate; if (toggle == true) { indeterminate = ToggleState.On; } else if (toggle == false) { indeterminate = ToggleState.Off; } while (currentPattern.Current.ToggleState != indeterminate) { currentPattern.Toggle(); } }
public static void AssertChecked(AutomationElement element, bool expected) { TogglePattern currentPattern = AutomationPatternHelper.GetTogglePattern(element); ToggleState indeterminate = ToggleState.Indeterminate; if (expected == true) { indeterminate = ToggleState.On; } else if (expected == false) { indeterminate = ToggleState.Off; } ToggleState toggleState = currentPattern.Current.ToggleState; if (indeterminate != toggleState) { throw new Exception(string.Format("ToggleState is not as expected. Expected: {0}, Actual: {1}. ({2})", indeterminate.ToString(), toggleState.ToString(), element.ToString())); } }
public static void Select(AutomationElement element) { AutomationPatternHelper.GetSelectionItemPattern(element).Select(); }
public static string GetText(AutomationElement element) { TextPattern currentPattern = AutomationPatternHelper.GetTextPattern(element); return(currentPattern.DocumentRange.GetText(-1)); }
// Methods public static void AddToSelection(AutomationElement element) { AutomationPatternHelper.GetSelectionItemPattern(element).AddToSelection(); }
public static string GetValue(AutomationElement element) { ValuePattern currentPattern = AutomationPatternHelper.GetValuePattern(element); return(currentPattern.Current.Value); }
public static void Invoke(AutomationElement element) { AutomationPatternHelper.GetInvokePattern(element).Invoke(); }
public static void Restore(AutomationElement element) { AutomationPatternHelper.GetWindowPattern(element).SetWindowVisualState(WindowVisualState.Normal); }
public static void SetValue(AutomationElement element, string value) { AutomationPatternHelper.GetValuePattern(element).SetValue(value); }
public static void SetRangeValue(AutomationElement element, double valueToSet) { AutomationPatternHelper.GetRangeValuePattern(element).SetValue(valueToSet); }