public override EnumActionResult Execute() { string tmp = _vm.variables.Get(m_params[1]); string[] path = tmp.Split('|'); AutomationElement treeItem = null; foreach (string name in path) { treeItem = UtilAutomation.FindTreeItem(_vm.host.aeCurrent, name); if (null == treeItem) { _vm.host.WriteLog("TreeItem '" + name + "' NOT found."); return(EnumActionResult.ERROR); } _vm.host.WriteLog("TreeItem '" + name + "' found."); _vm.host.aeCurrent = treeItem; if (DoWork("Expand") == false) { if (DoWork("Expand") == false) { return(EnumActionResult.ERROR); } } Util.UtilSys.Wait(500); } return(EnumActionResult.OK); }
private void CollapseAll(AutomationElement tree) { ControlUltraTree utree = _vm.GetUltraTree(); if (null == utree) { string msg = "'CollapseAll' command is used in pair with 'ExpandAll'."; _vm.host.WriteLog(msg); return; } List <AutomationElement> list = new List <AutomationElement>(); foreach (KeyValuePair <string, AutomationElement> item in utree.Roots) { list.Add(item.Value); } for (int i = list.Count - 1; i > -1; --i) { _vm.host.UpdateMarker(list[i].Current.BoundingRectangle); UtilAutomation.ClickOn(list[i].Current.BoundingRectangle, true); UtilSys.Wait(40); } _vm.RemoveControl(tree.Current.Name); }
public override EnumActionResult Execute() { ControlUltraTree utree = _vm.GetUltraTree(); if (null == utree) { _vm.host.WriteLog("No ultra tree object."); return(EnumActionResult.ERROR); } string key = _vm.variables.Get(m_params[1]); if (false == utree.Children.ContainsKey(key)) { _vm.host.WriteLog("Ultra Tree Children doesn't contain key: '" + key + "'"); return(EnumActionResult.ERROR); } AutomationElement treeItem = utree.Children[key]; _vm.host.UpdateMarker(treeItem.Current.BoundingRectangle); UtilAutomation.ClickOn(treeItem.Current.BoundingRectangle, false); return(EnumActionResult.OK); }
public override EnumActionResult Execute() { AutomationElement head = Finder.GetDataGridHeader(_vm.host.aeCurrent); if (null == head) { UtilSys.MessageBox("Unable to find grid header."); return(EnumActionResult.ERROR); } int i = 0; string[] colNames = Finder.GetDataGridHeadNames(head); ControlGrid grd = new ControlGrid(); grd.Name = "griiid"; _vm.AddControl(grd); ControlGrid grid = _vm.GetGrid(); grid.Rows.Clear(); grid.aeRows = UtilAutomation.GetDataGridRows(_vm.host.aeCurrent); if (null == grid.aeRows) { _vm.host.WriteLog("no DataGrid items???"); return(EnumActionResult.ERROR); } _vm.host.WriteLog("Listing DataGridItems: " + grid.aeRows.Count); _vm.host.WriteLog("----------------------------- Begin"); foreach (AutomationElement item in grid.aeRows) { _vm.host.UpdateMarker(item.Current.BoundingRectangle); i = 0; AutomationElementCollection cells = Finder.GetDataGridRowCells(item); Dictionary <string, string> d = new Dictionary <string, string>(); foreach (AutomationElement cell in cells) { //string msg = colNames[i] + ": " + cell.Current.Name; //_vm.host.WriteLog(msg); d.Add(colNames[i], cell.Current.Name); ++i; } grid.Rows.Add(d); } _vm.host.WriteLog("----------------------------- End"); return(EnumActionResult.OK); }
public static AutomationElement GetControlFromClientPos(AutomationElement window, int x, int y) { Point ptScr = UtilAutomation.Convert2Screen(window, new System.Windows.Point(x, y)); System.Windows.Point pp = new System.Windows.Point(); pp.X = ptScr.X; pp.Y = ptScr.Y; return(AutomationElement.FromPoint(pp)); }
public override EnumActionResult Execute() { string posX = _vm.variables.Get(m_params[1]); string posY = _vm.variables.Get(m_params[3]); pos.X = Convert.ToDouble(posX); pos.Y = Convert.ToDouble(posY); UtilAutomation.WindowMove(_vm.host.TargetWindow, pos); return(EnumActionResult.OK); }
public override EnumActionResult Execute() { string width = _vm.variables.Get(m_params[1]); string height = _vm.variables.Get(m_params[3]); pos.X = Convert.ToDouble(width); pos.Y = Convert.ToDouble(height); UtilAutomation.WindowResize(_vm.host.TargetWindow, pos); return(EnumActionResult.OK); }
public override EnumActionResult Execute() { Rect rc = _vm.host.TargetWindow.Current.BoundingRectangle; System.Windows.Point pos = new System.Windows.Point(); pos.X = rc.Left + (rc.Right - rc.Left) / 2; pos.Y = rc.Top + (rc.Bottom - rc.Top) / 2; UtilAutomation.ScreenClick(pos, false); return(EnumActionResult.OK); }
public override EnumActionResult Execute() { string name = _vm.variables.Get(m_params[1]); AutomationElementCollection col = Finder.GetToolBarButtons(_vm.host.aeCurrent); foreach (AutomationElement elem in col) { if (name == elem.Current.Name) { _vm.host.aeCurrent = elem; _vm.host.WriteLog("ToolbarButton: '" + elem.Current.Name + "' found."); return(EnumActionResult.OK); } } // workaround, sometimes this simply isn't enough to find that button inside a control System.Windows.Point p = new System.Windows.Point(); AutomationElement ae = null; for (int i = (int)_vm.host.aeCurrent.Current.BoundingRectangle.Left; i < (int)_vm.host.aeCurrent.Current.BoundingRectangle.Right; i += 10) { p.X = i; p.Y = _vm.host.aeCurrent.Current.BoundingRectangle.Top + 2; System.Windows.Point pos = p; UtilAutomation.SetCursorPos(p); ae = AutomationElement.FromPoint(pos); UtilSys.Wait(250); if (null != ae) { _vm.host.UpdateMarker(ae.Current.BoundingRectangle); if (ae.Current.Name == name) { if (ae.Current.ControlType == ControlType.Button) { _vm.host.aeCurrent = ae; _vm.host.WriteLog("ToolbarButton: '" + ae.Current.Name + "' found."); return(EnumActionResult.OK); } } } } _vm.PushError("ToolbarButton: '" + name + "' NOT found."); return(EnumActionResult.ERROR); }
public override EnumActionResult Execute() { try { UtilAutomation.CloseWindow(_vm.host.TargetWindow); Thread.Sleep(10); } catch (System.Exception ex) { _vm.host.WriteLog(ex.Message); return(EnumActionResult.ERROR); } return(EnumActionResult.OK); }
public override EnumActionResult Execute() { string id = _vm.variables.Get(m_params[1]); AutomationElement tree = UtilAutomation.FindTree(_vm.host.TargetWindow, id); if (null == tree) { _vm.PushError("Tree '" + id + "' NOT found."); return(EnumActionResult.ERROR); } _vm.host.WriteLog("Tree '" + id + "' found."); _vm.host.aeCurrent = tree; return(EnumActionResult.OK); }
public override EnumActionResult Execute() { string curValue = UtilAutomation.GetText(_vm.host.aeCurrent); string expValue = _vm.variables.Get(m_params[1]); string msg = "Test -> Current/Expected ('" + curValue + "'/'" + expValue + "')"; if (curValue != expValue) { _vm.host.WriteLog(msg + " - Failed."); return(EnumActionResult.TEST_FAILED); } _vm.host.WriteLog(msg + " - Succeeded."); return(EnumActionResult.TEST_OK); }
public override EnumActionResult Execute() { try { string key = string.Empty; int indexToFind = int.Parse(_vm.variables.Get(m_params[1])); ControlGrid grd = _vm.GetGrid(); _vm.host.aeCurrent = grd.aeRows[indexToFind]; _vm.host.UpdateMarker(_vm.host.aeCurrent.Current.BoundingRectangle); AutomationPattern.ScrollIntoView(_vm.host.aeCurrent); _vm.host.aeCurrent.SetFocus(); AutomationElement row = grd.aeRows[indexToFind]; AutomationElementCollection cells = row.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Text)); key = _vm.variables.Get(m_params[3]); Dictionary <string, string> dic = grd.Rows[indexToFind]; int j = 0; foreach (string k in dic.Keys) { if (k == key) { UtilAutomation.ClickOn(cells[j].Current.BoundingRectangle, true); UtilSys.Wait(500); string value = _vm.variables.Get(m_params[5]); value += "+{ENTER}"; System.Windows.Forms.SendKeys.SendWait(value); return(EnumActionResult.OK); } ++j; } return(EnumActionResult.ERROR); } catch (Exception) { throw; } }
public override EnumActionResult Execute() { string forbiddenValue = _vm.variables.Get(m_params[1]); string curValue = UtilAutomation.GetText(_vm.host.aeCurrent); if (curValue.Contains(forbiddenValue)) { _vm.host.WriteLog(curValue); _vm.host.WriteLog("Contain text: '" + forbiddenValue + "'"); return(EnumActionResult.TEST_FAILED); } else { return(EnumActionResult.TEST_OK); } }
public override EnumActionResult Execute() { string name = _vm.variables.Get(m_params[1]); AutomationElementCollection col = UtilAutomation.GetComboBoxItems(_vm.host.aeCurrent); foreach (AutomationElement elem in col) { if (name == elem.Current.Name) { UtilAutomation.MakeSelectionItem(elem); return(EnumActionResult.OK); } } return(EnumActionResult.OK); }
public override EnumActionResult Execute() { string name = _vm.variables.Get(m_params[1]); AutomationElement treeItem = UtilAutomation.FindTreeItem(_vm.host.aeCurrent, name); if (null == treeItem) { _vm.PushError("TreeItem '" + name + "' NOT found."); return(EnumActionResult.ERROR); } _vm.host.WriteLog("TreeItem '" + name + "' found."); _vm.host.aeCurrent = treeItem; return(EnumActionResult.OK); }
public override EnumActionResult Execute() { System.Windows.Point pt = new System.Windows.Point(); pt.X = (int)_vm.host.aeCurrent.Current.BoundingRectangle.Left + ((int)_vm.host.aeCurrent.Current.BoundingRectangle.Width / 2); pt.Y = (int)_vm.host.aeCurrent.Current.BoundingRectangle.Top + ((int)_vm.host.aeCurrent.Current.BoundingRectangle.Height / 2); Point ptScreen = UtilAutomation.Convert2Client(_vm.host.TargetWindow, pt); if (false == _vm.host.InitTipDialog(ptScreen.X, ptScreen.Y, m_params[3], Convert.ToInt32(m_params[1]))) { return(EnumActionResult.ERROR); } _vm.host.ShowTipDialog(); return(EnumActionResult.OK); }
private bool DoWork(string cmd) { switch (cmd) { case "Expand": { for (int i = 0; i < 3; i++) { try { UtilAutomation.Expand(_vm.host.aeCurrent); return(true); } catch (System.InvalidOperationException) { return(true); } catch (System.Exception ex) { _vm.host.WriteLog(ex.Message); UtilSys.Wait(1000); } } } return(false); case "Collapse": UtilAutomation.Collapse(_vm.host.aeCurrent); break; case "Select": AutomationPattern.Select(_vm.host.aeCurrent); break; default: _vm.host.WriteLog("Unrecognized TreeItem Command: '" + cmd + "'"); return(false); } return(true); }
public override EnumActionResult Execute() { AutomationElementCollection col = UtilAutomation.GetComboBoxItems(_vm.host.aeCurrent); if (null != col) { _vm.host.WriteLog("Listing ComboBoxItems: " + col.Count); _vm.host.WriteLog("----------------------------- Begin"); foreach (AutomationElement item in col) { _vm.host.WriteLog(item.Current.Name); } _vm.host.WriteLog("----------------------------- End"); return(EnumActionResult.OK); } else { _vm.host.WriteLog("No ComboBox items."); } return(EnumActionResult.ERROR); }
private void ExpandAll(AutomationElement tree) { PropertyCondition typeTreeItem = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.TreeItem); AutomationElementCollection col = tree.FindAll(TreeScope.Descendants, typeTreeItem); if (0 == col.Count) { _vm.host.WriteLog("No elements nothing to expand"); return; } double LeftParent = col[0].Current.BoundingRectangle.Left; bool hasChildren = false; for (int i = col.Count - 1; i > -1; --i) { AutomationElement cur = col[i]; _vm.host.UpdateMarker(cur.Current.BoundingRectangle); UtilSys.Wait(50); double LeftCurrent = cur.Current.BoundingRectangle.Left; if (LeftCurrent == LeftParent) // root element { if (!hasChildren) { UtilAutomation.ClickOn(cur.Current.BoundingRectangle, true); UtilSys.Wait(100); } hasChildren = false; } else // child element { hasChildren = true; } } }
public override EnumActionResult Execute() { string value = _vm.variables.Get(m_params[1]); switch (value) { case "Min": UtilAutomation.SetWindowVisualState(_vm.host.TargetWindow, System.Windows.Automation.WindowVisualState.Minimized); break; case "Max": UtilAutomation.SetWindowVisualState(_vm.host.TargetWindow, System.Windows.Automation.WindowVisualState.Maximized); break; case "Norm": UtilAutomation.SetWindowVisualState(_vm.host.TargetWindow, System.Windows.Automation.WindowVisualState.Normal); break; default: _vm.host.WriteLog("Unrecognized visaul state: ('" + value + "')"); return(EnumActionResult.ERROR); } return(EnumActionResult.OK); }
public override EnumActionResult Execute() { string state = _vm.variables.Get(m_params[1]); switch (state) { case "On": UtilAutomation.ToggleCheckBox(_vm.host.aeCurrent, ToggleState.On); break; case "Off": UtilAutomation.ToggleCheckBox(_vm.host.aeCurrent, ToggleState.Off); break; case "Indeter": UtilAutomation.ToggleCheckBox(_vm.host.aeCurrent, ToggleState.Indeterminate); break; default: // this should never happen -> parse _vm.host.WriteLog("Unrecognized toggle value: '" + state + "'."); return(EnumActionResult.ERROR); } return(EnumActionResult.OK); }
public override EnumActionResult Execute() { string posX = string.Empty; string posY = string.Empty; System.Windows.Point pos = new System.Windows.Point(); string type = m_params[0]; switch (type) { case "mouse.SetDragSource": _aeDrag = _vm.host.aeCurrent; break; case "mouse.SetDropSource": _aeDrop = _vm.host.aeCurrent; break; case "mouse.DoDragAndDrop": UtilAutomation.MouseHover(_aeDrag); UtilSys.Wait(1000); UtilAutomation.MouseLeftDown(); UtilSys.Wait(1000); UtilAutomation.MouseHover(_aeDrop); UtilSys.Wait(1000); UtilAutomation.MouseLeftUp(); break; case "mouse.RightClickOn": if (_vm.host.IsRegion) { _vm.host.LeftClickPos = UtilAutomation.RightClickOn(_vm.host.ImageRegion); } else { _vm.host.LeftClickPos = UtilAutomation.RightClickOn(_vm.host.aeCurrent.Current.BoundingRectangle); } break; case "mouse.RightClickClient": { posX = _vm.variables.Get(m_params[1]); posY = _vm.variables.Get(m_params[3]); pos.X = Convert.ToDouble(posX); pos.Y = Convert.ToDouble(posY); UtilAutomation.ClientRightClick(_vm.host.TargetWindow, pos, false); } break; case "mouse.RightClickScreen": { posX = _vm.variables.Get(m_params[1]); posY = _vm.variables.Get(m_params[3]); pos.X = Convert.ToDouble(posX); pos.Y = Convert.ToDouble(posY); UtilAutomation.ScreenRightClick(pos, false); } break; case "mouse.ClickOn": if (_vm.host.IsRegion) { if (!UtilAutomation.ClickOn(_vm.host.ImageRegion, false)) { return(EnumActionResult.ERROR); } } else { if (!UtilAutomation.ClickOn(_vm.host.aeCurrent.Current.BoundingRectangle, false)) { return(EnumActionResult.ERROR); } } break; case "mouse.ClickClient": { posX = _vm.variables.Get(m_params[1]); posY = _vm.variables.Get(m_params[3]); pos.X = Convert.ToDouble(posX); pos.Y = Convert.ToDouble(posY); UtilAutomation.ClientClick(_vm.host.TargetWindow, pos, false); } break; case "mouse.ClickScreen": { posX = _vm.variables.Get(m_params[1]); posY = _vm.variables.Get(m_params[3]); pos.X = Convert.ToDouble(posX); pos.Y = Convert.ToDouble(posY); UtilAutomation.ScreenClick(pos, false); } break; case "mouse.DoubleClickOn": if (_vm.host.IsRegion) { if (!UtilAutomation.ClickOn(_vm.host.ImageRegion, true)) { return(EnumActionResult.ERROR); } } else { if (!UtilAutomation.ClickOn(_vm.host.aeCurrent.Current.BoundingRectangle, true)) { return(EnumActionResult.ERROR); } } break; case "mouse.DoubleClickClient": { posX = _vm.variables.Get(m_params[1]); posY = _vm.variables.Get(m_params[3]); pos.X = Convert.ToDouble(posX); pos.Y = Convert.ToDouble(posY); UtilAutomation.ClientClick(_vm.host.TargetWindow, pos, true); } break; case "mouse.DoubleClickScreen": { posX = _vm.variables.Get(m_params[1]); posY = _vm.variables.Get(m_params[3]); pos.X = Convert.ToDouble(posX); pos.Y = Convert.ToDouble(posY); UtilAutomation.ScreenClick(pos, true); } break; default: _vm.host.WriteLog("Actionmouse->Unrecognized command [" + type + "]."); return(EnumActionResult.ERROR); } return(EnumActionResult.OK); }