Exemple #1
0
 public int RightClick(String windowName, String objName, String text)
 {
     if (String.IsNullOrEmpty(text))
     {
         throw new XmlRpcFaultException(123, "Argument cannot be empty.");
     }
     ControlType[] type;
     AutomationElement elementItem;
     AutomationElement childHandle = GetObjectHandle(windowName,
         objName);
     if (!utils.IsEnabled(childHandle))
     {
         childHandle = null;
         throw new XmlRpcFaultException(123,
             "Object state is disabled");
     }
     Mouse mouse = new Mouse(utils);
     try
     {
         childHandle.SetFocus();
         type = new ControlType[2] { ControlType.TreeItem,
             ControlType.ListItem };
         elementItem = utils.GetObjectHandle(childHandle,
             text, type, true);
         if (elementItem != null)
         {
             elementItem.SetFocus();
             LogMessage(elementItem.Current.Name + " : " +
                 elementItem.Current.ControlType.ProgrammaticName);
             Rect rect = elementItem.Current.BoundingRectangle;
             mouse.GenerateMouseEvent((int)(rect.X + rect.Width / 2),
                 (int)(rect.Y + rect.Height / 2), "b3c");
             return 1;
         }
     }
     catch (Exception ex)
     {
         LogMessage(ex);
         if (ex is XmlRpcFaultException)
             throw;
         else
             throw new XmlRpcFaultException(123,
                 "Unhandled exception: " + ex.Message);
     }
     finally
     {
         type = null;
         mouse = null;
         elementItem = childHandle = null;
     }
     throw new XmlRpcFaultException(123,
         "Unable to find the item in list: " + text);
 }
Exemple #2
0
        public String GetCellValue(String windowName,
            String objName, int row, int column = 0)
        {
            AutomationElement childHandle = GetObjectHandle(windowName,
                objName);
            if (!utils.IsEnabled(childHandle))
            {
                childHandle = null;
                throw new XmlRpcFaultException(123,
                    "Object state is disabled");
            }
            AutomationElement element = null;
            Condition prop1 = new PropertyCondition(
                AutomationElement.ControlTypeProperty, ControlType.ListItem);
            Condition prop2 = new PropertyCondition(
                AutomationElement.ControlTypeProperty, ControlType.TreeItem);
            Condition prop3 = new PropertyCondition(
                AutomationElement.ControlTypeProperty, ControlType.DataItem);
            Condition prop4 = new PropertyCondition(
                AutomationElement.ControlTypeProperty, ControlType.Text);
            Condition prop5 = new PropertyCondition(
                AutomationElement.ControlTypeProperty, ControlType.Custom);
            Condition condition1 = new OrCondition(prop1, prop2, prop3, prop5);
            Condition condition2 = new OrCondition(prop4, prop5);
            try
            {
                childHandle.SetFocus();
                AutomationElementCollection c = childHandle.FindAll(
                    TreeScope.Children, condition1);
                element = c[row];
                c = element.FindAll(TreeScope.Children, condition2);
                element = c[column];
                c = null;
                if (element != null)
                {
                    if (element.Current.ControlType == ControlType.Text)
                        return element.Current.Name;
                    else
                    {
                        // Specific to DataGrid of Windows Forms
                        element.SetFocus();
                        Mouse mouse = new Mouse(utils);
                        Rect rect = element.Current.BoundingRectangle;
                        utils.InternalWait(1);
                        mouse.GenerateMouseEvent((int)(rect.X + rect.Width / 2),
                            (int)(rect.Y + rect.Height / 2), "b1c");
                        utils.InternalWait(1);
                        // Only on second b1c, it becomes edit control
                        // though the edit control is not under current widget
                        // its created in different hierarchy altogether
                        // So, its required to do (from python)
                        // gettextvalue("Window Name", "txtEditingControl")
                        mouse.GenerateMouseEvent((int)(rect.X + rect.Width / 2),
                            (int)(rect.Y + rect.Height / 2), "b1c");

                        return "";
                    }
                }
            }
            catch (IndexOutOfRangeException ex)
            {
                LogMessage(ex);
                throw new XmlRpcFaultException(123,
                    "Index out of range: " + "(" + row + ", " + column + ")");
            }
            catch (ArgumentException ex)
            {
                LogMessage(ex);
                throw new XmlRpcFaultException(123,
                    "Index out of range: " + "(" + row + ", " + column + ")");
            }
            catch (Exception ex)
            {
                LogMessage(ex);
                throw new XmlRpcFaultException(123,
                    "Index out of range: " + "(" + row + ", " + column + ")");
            }
            finally
            {
                element = childHandle = null;
                prop1 = prop2 = prop3 = prop4 = prop5 = null;
                condition1 = condition2 = null;
            }
            throw new XmlRpcFaultException(123,
                "Unable to get item value.");
        }
Exemple #3
0
 public int DoubleClickRow(String windowName, String objName, String text)
 {
     if (String.IsNullOrEmpty(text))
     {
         throw new XmlRpcFaultException(123, "Argument cannot be empty.");
     }
     Object pattern;
     ControlType[] type;
     AutomationElement elementItem;
     AutomationElement childHandle = GetObjectHandle(windowName,
         objName);
     if (!utils.IsEnabled(childHandle))
     {
         childHandle = null;
         throw new XmlRpcFaultException(123,
             "Object state is disabled");
     }
     try
     {
         try
         {
             childHandle.SetFocus();
         }
         catch (InvalidOperationException ex)
         {
             LogMessage(ex);
         }
         type = new ControlType[2] { ControlType.TreeItem,
             ControlType.ListItem };
         elementItem = utils.GetObjectHandle(childHandle,
             text, type, true);
         if (elementItem != null)
         {
             elementItem.SetFocus();
             LogMessage(elementItem.Current.Name + " : " +
                 elementItem.Current.ControlType.ProgrammaticName);
             if (elementItem.TryGetCurrentPattern(
                 SelectionItemPattern.Pattern, out pattern))
             {
                 LogMessage("SelectionItemPattern");
                 //((SelectionItemPattern)pattern).Select();
                 // NOTE: Work around, as the above doesn't seem to work
                 // with UIAComWrapper and UIAComWrapper is required
                 // to Edit value in Spin control
                 Mouse mouse = new Mouse(utils);
                 Rect rect = elementItem.Current.BoundingRectangle;
                 mouse.GenerateMouseEvent((int)(rect.X + rect.Width / 2),
                     (int)(rect.Y + rect.Height / 2), "b1d");
                 return 1;
             }
             else if (elementItem.TryGetCurrentPattern(
                 ExpandCollapsePattern.Pattern, out pattern))
             {
                 LogMessage("ExpandCollapsePattern");
                 ((ExpandCollapsePattern)pattern).Expand();
                 return 1;
             }
             else
             {
                 throw new XmlRpcFaultException(123,
                     "Unsupported pattern.");
             }
         }
     }
     catch (Exception ex)
     {
         LogMessage(ex);
         if (ex is XmlRpcFaultException)
             throw;
         else
             throw new XmlRpcFaultException(123,
                 "Unhandled exception: " + ex.Message);
     }
     finally
     {
         type = null;
         pattern = null;
         elementItem = childHandle = null;
     }
     throw new XmlRpcFaultException(123,
         "Unable to find the item in list: " + text);
 }
Exemple #4
0
 public int DoubleClickRowIndex(String windowName, String objName,
     int row, int column = 0)
 {
     AutomationElement childHandle = GetObjectHandle(windowName,
         objName);
     if (!utils.IsEnabled(childHandle))
     {
         childHandle = null;
         throw new XmlRpcFaultException(123,
             "Object state is disabled");
     }
     AutomationElement element = null;
     Condition prop1 = new PropertyCondition(
         AutomationElement.ControlTypeProperty, ControlType.ListItem);
     Condition prop2 = new PropertyCondition(
         AutomationElement.ControlTypeProperty, ControlType.TreeItem);
     Condition prop3 = new PropertyCondition(
         AutomationElement.ControlTypeProperty, ControlType.DataItem);
     Condition prop4 = new PropertyCondition(
         AutomationElement.ControlTypeProperty, ControlType.Text);
     Condition prop5 = new PropertyCondition(
         AutomationElement.ControlTypeProperty, ControlType.Custom);
     Condition condition1 = new OrCondition(prop1, prop2, prop3, prop5);
     Condition condition2 = new OrCondition(prop4, prop5);
     try
     {
         childHandle.SetFocus();
         AutomationElementCollection c = childHandle.FindAll(
             TreeScope.Children, condition1);
         element = c[row];
         c = element.FindAll(TreeScope.Children, condition2);
         element = c[column];
         c = null;
         if (element != null)
         {
             Mouse mouse = new Mouse(utils);
             Rect rect = element.Current.BoundingRectangle;
             mouse.GenerateMouseEvent((int)(rect.X + rect.Width / 2),
                 (int)(rect.Y + rect.Height / 2), "b1d");
             return 1;
         }
     }
     catch (IndexOutOfRangeException)
     {
         throw new XmlRpcFaultException(123,
             "Index out of range: " + "(" + row + ", " + column + ")");
     }
     catch (ArgumentException)
     {
         throw new XmlRpcFaultException(123,
             "Index out of range: " + "(" + row + ", " + column + ")");
     }
     catch (Exception ex)
     {
         LogMessage(ex);
         throw new XmlRpcFaultException(123,
             "Index out of range: " + "(" + row + ", " + column + ")");
     }
     finally
     {
         element = childHandle = null;
         prop1 = prop2 = prop3 = prop4 = prop5 = null;
         condition1 = condition2 = null;
     }
     throw new XmlRpcFaultException(123,
         "Unable to find the item in list: " + row);
 }