示例#1
0
 public void CloseApp()
 {
     if (this.window != null) {
         this.window.Dispose();
         this.window = null;
     }
 }
示例#2
0
 public void CloseApp()
 {
     if (this.main != null) {
         this.main.Dispose();
         this.main = null;
     }
 }
示例#3
0
        public Window LaunchApp(string exeFileName, string args, string rootElementName)
        {
            ProcessStartInfo info = new ProcessStartInfo();
            info.FileName = exeFileName;
            info.Arguments = args;

            Process p = new Process();
            p.StartInfo = info;
            if (!p.Start()) {
                string msg = "Error launching " + exeFileName;
                MessageBox.Show("Error Creating Process", msg,
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                throw new Exception(msg);
            }
            if (p.HasExited) {
                throw new Exception(string.Format("Failed to launch '{0'}, exit code {1}", exeFileName, p.ExitCode.ToString()));
            }
            Window w = new Window(p, null, rootElementName);
            w.TestBase = this;
            return w;
        }
示例#4
0
        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");
        }
示例#5
0
 public Window(Window parent, IntPtr handle)
 {
     this.parent = parent;
     this.handle = handle;
     this.acc = AutomationWrapper.AccessibleObjectForWindow(handle);
 }
        Point GetDropSpot(Window w, Rectangle target)
        {
            AccessibleObject acc = w.AccessibleObject;
            Rectangle source = acc.Bounds;
            source.Inflate(20, 20); // add extra margin
            if (source.Contains(target)) {
                // Source window is completely occluding the target window, so we need to move it!
                Point from = new Point(source.Left + (source.Width/2), source.Top + 5);
                int amount = target.Left - source.Left + 100;
                Point end = new Point(from.X + amount, from.Y);
                // Move window to the right.
                Mouse.MouseDown(from, MouseButtons.Left);
                Mouse.MouseDragDrop(from, end, 5, MouseButtons.Left);

                source = acc.Bounds;
            }
            if (source.Left > target.Left) {
                // pick a spot along the left margin
                return new Point((target.Left + source.Left) / 2, (target.Top + target.Bottom) / 2);
            } else if (source.Right < target.Right) {
                // pick a spot along the right margin
                return new Point((target.Right + source.Right) / 2, (target.Top + target.Bottom) / 2);
            } else if (source.Top > target.Top) {
                // top margin
                return new Point((target.Right + target.Left) / 2, (source.Top + target.Top) / 2);
            } else if (source.Bottom < target.Bottom) {
                // bottom margin
                return new Point((target.Right + target.Left) / 2, (source.Bottom + target.Bottom) / 2);
            }

            // Then MOVE the window so it's not in the way!
            w.SetWindowPosition(target.Right, source.Top);
            Sleep(1000);
            source = acc.Bounds;
            return new Point((target.Left + source.Left) / 2, (target.Top + target.Bottom) / 2);
        }
 string CopyXPathFindString(Window w)
 {
     SystemAccessible s = w.FindDescendant("checkBoxXPath");
     if (s.DefaultAction == "Check") {
         s.DoDefaultAction();
     }
     SystemAccessible c = w.FindDescendant("comboBoxFind");
     return c.Value;
 }
 void ClearFindCheckBoxes(Window findDialog)
 {
     foreach (string name in new string[] { "checkBoxMatchCase", "checkBoxWholeWord", "checkBoxRegex", "checkBoxXPath" }) {
         SystemAccessible checkBox = findDialog.FindDescendant(name);
         if ((checkBox.State & AccessibleStates.Checked) != 0) {
             checkBox.DoDefaultAction();
         }
     }
 }
示例#9
0
 public Window(Window parent, IntPtr handle)
 {
     this.parent = parent;
     this.handle = handle;
     this.acc = SystemAccessible.AccessibleObjectForWindow(handle);
 }