private double ScrollList(AutomationWrapper items, ScrollAmount amount) { ScrollPattern sp = items.AutomationElement.GetCurrentPattern(ScrollPattern.Pattern) as ScrollPattern; if (sp.Current.VerticallyScrollable) { sp.ScrollVertical(amount); } double percent = sp.Current.VerticalScrollPercent; return(percent); }
public void ShowXslt() { if (xslOutputTab == null) { AutomationWrapper tabControl = this.window.FindDescendant("tabControlViews"); xslOutputTab = tabControl.FindDescendant("XSL Output"); } var bounds = xslOutputTab.Bounds; Trace.WriteLine("Select XSL output tab"); Mouse.MouseClick(new Point(bounds.Left + (bounds.Right - bounds.Left) / 2, bounds.Top + 5), MouseButtons.Left); Sleep(1000); }
private void SetCheckedState(string name, bool state) { if (this.GetCheckedState(name) == state) { return; } // seems to be a bug in the AutomationElement mapping, checkbox is not supporting the TogglePattern! AutomationWrapper s = w.FindDescendant(name); Rectangle r = s.Bounds; Mouse.MouseClick(r.Center(), MouseButtons.Left); Thread.Sleep(200); }
internal void ShowXmlTree() { if (xmlTreeViewTab == null) { AutomationWrapper tabControl = this.window.FindDescendant("tabControlViews"); xmlTreeViewTab = tabControl.FindDescendant("Tree View"); } var bounds = xmlTreeViewTab.Bounds; Trace.WriteLine("Select XML tree view tab"); Mouse.MouseClick(new Point(bounds.Left + (bounds.Right - bounds.Left) / 2, bounds.Top + 5), MouseButtons.Left); Sleep(100); }
public static void MouseWheel(AutomationWrapper w, int clicks) { var c = Cursor.Position; if (w != null) { c = w.PhysicalToLogicalPoint(c); } MouseInput input = GetAbsoluteMouseInput(c.X, c.Y); input.mouseData = clicks; input.dwFlags |= (int)MouseFlags.MOUSEEVENTF_WHEEL; SendInput(input); }
public void LoadXmlAddress(string url, string expectedXmlPrefix) { Trace.WriteLine("Click in the combo box location field"); AutomationWrapper comboBoxLocation = this.window.FindDescendant("comboBoxLocation"); Rectangle bounds = comboBoxLocation.Bounds; Mouse.MouseClick(bounds.Center(), MouseButtons.Left); Trace.WriteLine("Loading: " + url); this.window.SendKeystrokes("{END}+{HOME}" + url + "{ENTER}"); Trace.WriteLine("Wait for rss to be loaded"); WaitForText("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); }
private bool GetCheckedState(string name) { AutomationWrapper s = w.FindDescendant(name); foreach (var p in s.AutomationElement.GetSupportedProperties()) { if (p.ProgrammaticName == "TogglePatternIdentifiers.ToggleStateProperty") { var value = s.AutomationElement.GetCurrentPropertyValue(p); if (value != null && value.ToString() == "On") { return(true); } } } return(false); }
public Window(Process p, string className, string rootElementName) { this._process = p; IntPtr h = p.Handle; while (h == IntPtr.Zero || !p.Responding) { Sleep(1000); p.WaitForInputIdle(); h = p.Handle; if (p.HasExited) { throw new InvalidOperationException(string.Format("Process '{0}' has exited!", p.StartInfo.FileName)); } } p.WaitForInputIdle(); p.Exited += new EventHandler(OnExited); int id = p.Id; if (this._acc == null) { // p.MainWindowHandle always returns 0 for some unknown reason... int retries = 20; while (retries-- > 0 && this._acc == null) { try { this._acc = FindWindowForProcessId(id, className, rootElementName); } catch (Exception ex) { Debug.WriteLine("Error finding window for process id : " + ex.Message); } Sleep(1000); } if (this._acc == null) { throw new Exception("Process as no window handle"); } this._handle = this._acc.Hwnd; } }
public static void MouseWheel(AutomationWrapper w, int clicks) { var c = Cursor.Position; if (w != null) { c = w.PhysicalToLogicalPoint(c); } MouseInput input = new MouseInput(); input.type = (int)InputType.INPUT_MOUSE; input.mouseData = clicks; MouseFlags flags = MouseFlags.MOUSEEVENTF_WHEEL; input.dwFlags = (int)flags; input.dx = c.X; input.dy = c.Y; SendInput(input); }
void ReloadMenuItems(string name) { if (_menuItems == null) { _menuItems = new Dictionary <string, AutomationWrapper>(); } if (_menuItems.Count == 0 || !_menuItems.ContainsKey(name)) { int retries = 5; while (retries-- > 0 && _menuItems.Count == 0) { // load the menu items foreach (var menuItem in this._acc.AutomationElement.FindAll(TreeScope.Descendants, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.MenuItem))) { AutomationElement e = menuItem as AutomationElement; if (e != null) { string itemName = e.Current.Name; Debug.WriteLine(itemName); _menuItems[itemName] = new AutomationWrapper(e); } } // and the toolbar buttons foreach (var button in this._acc.AutomationElement.FindAll(TreeScope.Descendants, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button))) { AutomationElement e = button as AutomationElement; if (e != null) { _menuItems[e.Current.Name] = new AutomationWrapper(e); } } if (_menuItems.Count == 0) { Sleep(500); } } } }
public static AutomationWrapper FindWindowForProcessId(int id, string windowClassName, string name) { // Hmmm, try and find window for this process then. IntPtr hwnd = GetWindow(GetDesktopWindow(), GetWindowOptions.Child); while (hwnd != IntPtr.Zero) { GetWindowThreadProcessId(hwnd, out int procid); if (procid == id) { AutomationWrapper acc = AutomationWrapper.AccessibleObjectForWindow(hwnd); if (acc != null && (windowClassName == null || acc.ClassName == windowClassName) && (name == null || acc.Name == name)) { if (IsWindowVisible(hwnd)) { return(acc); } } } hwnd = GetWindow(hwnd, GetWindowOptions.Next); } return(null); }
public Window(Window parent, IntPtr handle) { this.parent = parent; this.handle = handle; this.acc = AutomationWrapper.AccessibleObjectForWindow(handle); }
public Window LaunchIE(string args) { // when IE launches it creates a new process instead of the process we create, so we have to track that jump. // so this means watching for a new process to appear. HashSet <int> runningProcesses = new HashSet <int>(); foreach (Process e in Process.GetProcesses()) { Debug.WriteLine("Found Process " + e.Id + " : " + e.ProcessName); if (e.ProcessName == "iexplore") { try { e.Kill(); } catch { } } else { runningProcesses.Add(e.Id); } } ProcessStartInfo info = new ProcessStartInfo(); info.FileName = Environment.GetEnvironmentVariable("ProgramFiles") + "\\Internet Explorer\\iexplore.exe";; info.Arguments = args; Process p = new Process(); p.StartInfo = info; if (!p.Start()) { string msg = "Error launching " + info.FileName; MessageBox.Show("Error Creating Process", msg, MessageBoxButtons.OK, MessageBoxIcon.Error); throw new Exception(msg); } // find the new process that has a window whose ClassName is "IEFrame". Process ie = null; int retry = 5; while (retry-- > 0) { foreach (Process np in Process.GetProcesses()) { if (!runningProcesses.Contains(np.Id)) { Debug.WriteLine("Checking Process " + np.Id + " : " + np.ProcessName); AutomationWrapper wrapper = Window.FindWindowForProcessId(np.Id, "IEFrame", null); if (wrapper != null) { // found it! ie = np; p = np; break; } } } if (ie != null) { break; } Sleep(500); } if (ie != null) { Window w = new Window(p, "IEFrame", null); w.TestBase = this; return(w); } throw new Exception("Not finding the new IE process, perhaps you need to shutdown existing IE instances"); }
internal AutomationWrapper HitTest(int x, int y) { return(AutomationWrapper.AccessibleObjectAt(new Point(x, y))); }
internal void InvokeTransformButton() { AutomationWrapper s = GetXsltViewer().FindDescendant("TransformButton"); s.Invoke(); }
internal string GetXmlOutputFilename() { AutomationWrapper s = GetXsltViewer().FindDescendant("OutputFileName"); return(s.Value); }
internal void FocusFindString() { AutomationWrapper findCombo = this.w.FindDescendant("comboBoxFind"); Mouse.MouseClick(findCombo.Bounds.Center(), MouseButtons.Left); }
internal AutomationWrapper HitTest(int x, int y) { var node = AutomationWrapper.AccessibleObjectAt(new Point(x, y)); return(node); }