Beispiel #1
0
        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());
        }
Beispiel #2
0
        public static void Expand(AutomationElement element)
        {
            ExpandCollapsePattern currentPattern = AutomationPatternHelper.GetExpandCollapsePattern(element);

            if (currentPattern.Current.ExpandCollapseState == ExpandCollapseState.Collapsed)
            {
                currentPattern.Expand();
            }
        }
Beispiel #3
0
        public static void Minimize(AutomationElement element)
        {
            WindowPattern currentPattern = AutomationPatternHelper.GetWindowPattern(element);

            if (currentPattern.Current.CanMinimize)
            {
                currentPattern.SetWindowVisualState(WindowVisualState.Minimized);
            }
        }
Beispiel #4
0
        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()));
            }
        }
Beispiel #5
0
        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()));
            }
        }
Beispiel #6
0
        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()));
            }
        }
Beispiel #7
0
 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);
     }
 }
Beispiel #8
0
        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();
            }
        }
Beispiel #9
0
        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()));
            }
        }
Beispiel #10
0
 public static void Select(AutomationElement element)
 {
     AutomationPatternHelper.GetSelectionItemPattern(element).Select();
 }
Beispiel #11
0
        public static string GetText(AutomationElement element)
        {
            TextPattern currentPattern = AutomationPatternHelper.GetTextPattern(element);

            return(currentPattern.DocumentRange.GetText(-1));
        }
Beispiel #12
0
 // Methods
 public static void AddToSelection(AutomationElement element)
 {
     AutomationPatternHelper.GetSelectionItemPattern(element).AddToSelection();
 }
Beispiel #13
0
        public static string GetValue(AutomationElement element)
        {
            ValuePattern currentPattern = AutomationPatternHelper.GetValuePattern(element);

            return(currentPattern.Current.Value);
        }
Beispiel #14
0
 public static void Invoke(AutomationElement element)
 {
     AutomationPatternHelper.GetInvokePattern(element).Invoke();
 }
Beispiel #15
0
 public static void Restore(AutomationElement element)
 {
     AutomationPatternHelper.GetWindowPattern(element).SetWindowVisualState(WindowVisualState.Normal);
 }
Beispiel #16
0
 public static void SetValue(AutomationElement element, string value)
 {
     AutomationPatternHelper.GetValuePattern(element).SetValue(value);
 }
Beispiel #17
0
 public static void SetRangeValue(AutomationElement element, double valueToSet)
 {
     AutomationPatternHelper.GetRangeValuePattern(element).SetValue(valueToSet);
 }