예제 #1
0
        public override void Selection(IShipmentAutomationControl control, string text)
        {
            if (Selection(control) == text)
            {
                return;
            }

            if (control.IsCharInputRequired)
            {
                Win32ApiHelper.SendMessage(control.NativeHwnd, 335, 1, null);
                Win32ApiHelper.SendMessage(control.NativeHwnd, Win32ApiHelper.CB_SELECTSTRING, Win32ApiHelper.SEARCH_ALL, text);
                Win32ApiHelper.SendChars(control.NativeHwnd, text, 10);
                Win32ApiHelper.SendMessage(control.NativeHwnd, 335, 0, null);
                return;
            }

            var contents = GetListBoxContents(control.NativeHwnd);
            var item     = contents.FirstOrDefault(c => string.Equals(c, text, StringComparison.CurrentCultureIgnoreCase));
            var index    = contents.IndexOf(item);

            if (item != null && index > -1)
            {
                Win32ApiHelper.SendMessage(control.NativeHwnd, Win32ApiHelper.CB_SETCURSEL, index, null);
            }
            else
            {
                Text(control, text);
            }
        }
예제 #2
0
 protected static void TypeTextWithFocus(IShipmentAutomationControl control, string text)
 {
     Wait(control.AutomationElement.Current.IsKeyboardFocusable);
     control.AutomationElement.SetFocus();
     SendKeys.SendWait(text);
     Keyboard.Type(Key.Enter);
 }
예제 #3
0
        public override void Text(IShipmentAutomationControl control, string text)
        {
            if (control.IsTypedInputRequired)
            {
                TypeTextWithFocus(control, text);
                Keyboard.Type(Key.Enter);
                return;
            }

            if (control.IsCharInputRequired)
            {
                control.AutomationElement.SetFocus();
                Thread.Sleep(1000);
                Keyboard.Type(Key.Back);
                Win32ApiHelper.SendChars(control.NativeHwnd, text, 70);
                Keyboard.Type(Key.Enter);
                return;
            }

            Win32ApiHelper.SendMessage(control.NativeHwnd, Win32ApiHelper.WM_SETTEXT, 0, text);
            if (control.IsFocusedInputRequired)
            {
                control.AutomationElement.SetFocus();
                Keyboard.Type(Key.Enter);
            }
        }
예제 #4
0
        public override string Selection(IShipmentAutomationControl control)
        {
            try
            {
                //Combobox
                if (control.AutomationElement.GetSupportedPatterns().Any(p => p.ProgrammaticName == ValuePattern.Pattern.ProgrammaticName))
                {
                    return(control.AutomationElement.GetValue());
                }

                //Listbox
                var comboboxList  = control.AutomationElement.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.List));
                var comboboxItems = comboboxList.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ListItem));
                if (comboboxItems.Count > 0)
                {
                    return((from AutomationElement comboboxItem in comboboxItems
                            where comboboxItem.GetSelectionItemPattern().Current.IsSelected
                            select comboboxItem.Current.Name).FirstOrDefault());
                }

                return(null);
            }
            catch (Exception)
            {
                return(null);
            }
        }
예제 #5
0
 public override bool Checked(IShipmentAutomationControl control)
 {
     try
     {
         return(control.AutomationElement.GetTogglePattern().Current.ToggleState == ToggleState.On);
     }
     catch (Exception)
     {
         return(false);
     }
 }
예제 #6
0
 public override string Text(IShipmentAutomationControl control)
 {
     try
     {
         return(control.AutomationElement.GetValue());
     }
     catch (Exception)
     {
         return(null);
     }
 }
예제 #7
0
 public override bool Checked(IShipmentAutomationControl control)
 {
     try
     {
         var state = Win32ApiHelper.SendMessage(control.NativeHwnd, Win32ApiHelper.BM_GETCHECK, 0, IntPtr.Zero);
         return(state == new IntPtr(Win32ApiHelper.BST_CHECKED));
     }
     catch (Exception)
     {
         return(false);
     }
 }
예제 #8
0
        public override void Checked(IShipmentAutomationControl control, bool value)
        {
            if (control.IsTypedInputRequired)
            {
                var current = Checked(control);
                if (current != value)
                {
                    control.AutomationElement.SetFocus();
                    Keyboard.Type(Key.Space);
                }
                return;
            }

            var bsd = value ? Win32ApiHelper.BST_CHECKED : Win32ApiHelper.BST_UNCHECKED;

            Win32ApiHelper.SendMessage(control.NativeHwnd, Win32ApiHelper.BM_SETCHECK, bsd, IntPtr.Zero);
        }
예제 #9
0
        public override void Checked(IShipmentAutomationControl control, bool value)
        {
            if (!control.AutomationElement.Current.IsEnabled)
            {
                return;
            }

            if (value && control.AutomationElement.GetTogglePattern().Current.ToggleState == ToggleState.Off)
            {
                control.AutomationElement.GetTogglePattern().Toggle();
            }

            if (!value && control.AutomationElement.GetTogglePattern().Current.ToggleState == ToggleState.On)
            {
                control.AutomationElement.GetTogglePattern().Toggle();
            }
        }
예제 #10
0
 public override string Text(IShipmentAutomationControl control)
 {
     try
     {
         var length = Win32ApiHelper.SendMessage(control.NativeHwnd, Win32ApiHelper.WM_GETTEXTLENGTH, 0, 0);
         if (length > 0)
         {
             var text = new StringBuilder(length + 1);
             Win32ApiHelper.SendMessage(control.NativeHwnd, Win32ApiHelper.WM_GETTEXT, text.Capacity, text);
             return(text.ToString());
         }
         return(null);
     }
     catch (Exception)
     {
         return(null);
     }
 }
예제 #11
0
        public override string Selection(IShipmentAutomationControl control)
        {
            try
            {
                var index = Win32ApiHelper.SendRefMessage(control.NativeHwnd, Win32ApiHelper.CB_GETCURSEL, 0, null).ToInt32();
                if (index > 1)
                {
                    var ssb = new StringBuilder(256, 256);
                    Win32ApiHelper.SendRefMessage(control.NativeHwnd, Win32ApiHelper.CB_GETLBTEXT, index, ssb);
                    return(ssb.ToString());
                }

                return(Text(control));
            }
            catch (Exception)
            {
                return(string.Empty);
            }
        }
예제 #12
0
        public override void Selection(IShipmentAutomationControl control, string text)
        {
            Wait(control.AutomationElement.Current.IsEnabled);
            if (!control.AutomationElement.Current.IsEnabled)
            {
                return;
            }

            //Set focus if required
            if ((control.IsFocusedInputRequired || control.IsTypedInputRequired) && control.AutomationElement.Current.IsKeyboardFocusable)
            {
                control.AutomationElement.SetFocus();
            }

            //Try set with value pattern  - COMBOBOX
            if (control.IsValueRequired && control.AutomationElement.GetSupportedPatterns().Any(p => p.ProgrammaticName == ValuePattern.Pattern.ProgrammaticName))
            {
                control.AutomationElement.SetValue(text);
                return;
            }

            //OR LISTBOX
            var comboboxList = control.AutomationElement.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.List));

            //Get the all the listitems in List control
            var comboboxItems = comboboxList.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ListItem));

            if (comboboxItems.Count < 1)
            {
                return;
            }

            //Index to set in combo box
            var itemToSelect = comboboxItems.Cast <AutomationElement>().FirstOrDefault(e => e.Current.Name.StartsWith(text));


            //Finding the pattern which need to select
            itemToSelect?.GetSelectionItemPattern()?.Select();
        }
예제 #13
0
        public override void Text(IShipmentAutomationControl control, string text)
        {
            Wait(control.AutomationElement.Current.IsEnabled);
            if (!control.AutomationElement.Current.IsEnabled)
            {
                return;
            }

            if (control.IsTypedInputRequired)
            {
                TypeTextWithFocus(control, text);
                return;
            }

            control.AutomationElement.SetValue(text);

            if (control.IsFocusedInputRequired && control.AutomationElement.Current.IsKeyboardFocusable)
            {
                control.AutomationElement.SetFocus();
                Keyboard.Type(Key.Enter);
            }
        }
예제 #14
0
 public abstract string Selection(IShipmentAutomationControl control);
예제 #15
0
 public abstract bool Checked(IShipmentAutomationControl control);
예제 #16
0
 public abstract void Checked(IShipmentAutomationControl control, bool value);
예제 #17
0
 public abstract string Text(IShipmentAutomationControl control);
예제 #18
0
 public abstract void Selection(IShipmentAutomationControl control, string text);