Example #1
0
 public static void Value(AutomationElement automationElement, string value)
 {
     try
     {
         if (automationElement.ControlType == ControlType.Edit)
         {
             automationElement.AsTextBox().Text.Should().Be(value);
         }
         if (automationElement.ControlType == ControlType.ComboBox)
         {
             automationElement.AsComboBox().SelectedItem.Text.Trim().Should().Be(value);
         }
         if (automationElement.ControlType == ControlType.List)
         {
             automationElement.AsListBox().SelectedItem.Text.Trim().Should().Be(value);
         }
         if (automationElement.ControlType == ControlType.Tree)
         {
             automationElement.AsTree().SelectedTreeItem.Text.Trim().Should().Be(value);
         }
     }
     catch (Exception)
     {
         var sb = new StringBuilder();
         sb.Append(automationElement.Name);
         sb.Append(' ');
         sb.Append(automationElement.ControlType.ToString());
         sb.Append("'s value should be '");
         sb.Append(value);
         sb.Append("'");
         throw new AssertionException(sb.ToString());
     }
 }
Example #2
0
        //TODO
        public static void By(AutomationElement element, string text, VirtualKeyShort?virtualKeyShort = VirtualKeyShort.TAB)
        {
            var logger = InjectionHelper.GetInstance <DesktopLogger>();

            if (element.ControlType == ControlType.ComboBox)
            {
                Wait.UntilResponsive(element);
                var combo = element.AsComboBox();
                combo.Focus();
                combo.Expand();
                combo.Select(text);
                combo.Collapse();
                Keyboard.Press(virtualKeyShort.Value);

                logger.Write(combo, "has been selected");
            }
            if (element.ControlType == ControlType.List)
            {
                var list = element.AsListBox();

                if (virtualKeyShort == null)
                {
                    var item = list.FindFirstChild(c => c.ByName(text));
                    Click.On(item);
                }
                else
                {
                    list.Select(text);
                    Keyboard.Press(virtualKeyShort.Value);
                }

                logger.Write(list, "has been selected");
            }
        }
Example #3
0
        // DEPRECATED
        public static void ByAndWait(AutomationElement elementOne, string textOne, AutomationElement elementTwo, string textTwo)
        {
            if (elementOne.ControlType == ControlType.ComboBox && elementTwo.ControlType == ControlType.ComboBox)
            {
                var combo = elementOne.AsComboBox();
                combo.Expand();
                combo.Select(textOne);
                combo.Collapse();
                Keyboard.Press(VirtualKeyShort.ENTER);

                Retry.WhileTrue(() => elementTwo.AsComboBox().Items.Length == 0,
                                TimeSpan.FromSeconds(30), TimeSpan.FromMilliseconds(250));

                combo = elementTwo.AsComboBox();
                combo.Expand();
                combo.Select(textTwo);
                combo.Collapse();
                Keyboard.Press(VirtualKeyShort.ENTER);
            }
        }
Example #4
0
 public static void Values(AutomationElement automationElement, string[] values)
 {
     try
     {
         if (automationElement.ControlType == ControlType.ComboBox)
         {
             automationElement.AsComboBox().Items.Select(i => i.Text).ToList().Should().BeEquivalentTo(values.ToList());
         }
     }
     catch (Exception)
     {
         var sb = new StringBuilder();
         sb.Append(automationElement.Name);
         sb.Append(' ');
         sb.Append(automationElement.ControlType.ToString());
         sb.Append("'s items should be '");
         sb.Append(values);
         sb.Append("'");
         throw new AssertionException(sb.ToString());
     }
 }
Example #5
0
        //TODO
        public static void By(AutomationElement element, int index, VirtualKeyShort virtualKeyShort = VirtualKeyShort.TAB)
        {
            var logger = InjectionHelper.GetInstance <DesktopLogger>();

            if (element.ControlType == ControlType.ComboBox)
            {
                var combo = element.AsComboBox();
                combo.Expand();
                combo.Select(index);
                combo.Collapse();
                Keyboard.Press(virtualKeyShort);

                logger.Write(combo, "has been selected");
            }
            if (element.ControlType == ControlType.Tree)
            {
                var tree = element.AsTree();
                var item = tree.FindChildAt(index);
                Click.On(item);

                logger.Write(tree, "has been selected");
            }
        }