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

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

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

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

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