Inheritance: BasePattern
Example #1
0
 void System.IDisposable.Dispose()
 {
     if (_windowPattern != null)
     {
         _windowPattern.Close();
         _windowPattern = null;
     }
     _element = null;
     _hwnd = 0;
 }
Example #2
0
 void System.IDisposable.Dispose()
 {
     if (_windowPattern != null)
     {
         _windowPattern.Close();
         _windowPattern = null;
     }
     if (_process != null)
     {
         _process.WaitForExit();
         _process = null;
     }
 }
Example #3
0
        public AppHost(string program, string args)
        {
            // Start up the program and find it
            _process = Process.Start(program, args);
            _hwnd = ActiveWaitForHwnd(_process.Id);
            if (_hwnd == IntPtr.Zero)
            {
                throw new InvalidOperationException("app never stabilized");
            }

            // Find it
            _element = AutomationElement.FromHandle(_hwnd);
            if (_element == null)
            {
                throw new InvalidOperationException();
            }

            _windowPattern = (WindowPattern)_element.GetCurrentPattern(WindowPattern.Pattern);
        }
Example #4
0
        public ExplorerHost()
        {
            // Start up Explorer and find it
            System.Diagnostics.Process.Start("cmd.exe", "/c start %SystemDrive%\\windows\\system32");

            // Wait briefly
            System.Threading.Thread.Sleep(2000 /* ms */);

            // Find it
            _element = AutomationElement.RootElement.FindFirst(TreeScope.Children,
                new PropertyCondition(AutomationElement.NameProperty, "system32"));
            if (_element == null)
            {
                throw new InvalidOperationException();
            }

            _hwnd = _element.Current.NativeWindowHandle;

            _windowPattern = (WindowPattern)_element.GetCurrentPattern(WindowPattern.Pattern);
        }
Example #5
0
			internal WindowPatternInformation (WindowPattern pattern, bool cache)
			{
				this.pattern = pattern;
				this.cache = cache;
			}
Example #6
0
 public WindowProxy(AutomationElement element)
 {
     this.Element = element;
     wp = element.Pattern<WindowPattern>();
 }
Example #7
0
 internal WindowPatternInformation(WindowPattern pattern, bool cache)
 {
     this.pattern = pattern;
     this.cache   = cache;
 }
Example #8
0
 /// <summary></summary>
 protected WindowPatternWrapper(AutomationElement element, string testSuite, TestPriorities priority, TypeOfControl typeOfControl, TypeOfPattern typeOfPattern, string dirResults, bool testEvents, IApplicationCommands commands)
     :
     base(element, testSuite, priority, typeOfControl, typeOfPattern, dirResults, testEvents, commands)
 {
     m_pattern = (WindowPattern)GetPattern(m_le, m_useCurrent, WindowPattern.Pattern);
 }
Example #9
0
        /// <summary>
        ///     The Startup handler.
        /// </summary>
        /// <param name="e">The event arguments</param>
        protected override void OnStartup(StartupEventArgs e)
        {
            // Start the WindowMove client.
            CreateWindow();

            try
            {
                // Obtain an AutomationElement from the target window handle.
                _targetWindow = StartTargetApp(_targetApplication);

                // Does the automation element exist?
                if (_targetWindow == null)
                {
                    Feedback("No target.");
                    return;
                }
                Feedback("Found target.");

                // find current location of our window
                _targetLocation = _targetWindow.Current.BoundingRectangle.Location;

                // Obtain required control patterns from our automation element
                _windowPattern = GetControlPattern(_targetWindow,
                    WindowPattern.Pattern) as WindowPattern;

                if (_windowPattern == null) return;

                // Make sure our window is usable.
                // WaitForInputIdle will return before the specified time 
                // if the window is ready.
                if (false == _windowPattern.WaitForInputIdle(10000))
                {
                    Feedback("Object not responding in a timely manner.");
                    return;
                }
                Feedback("Window ready for user interaction");

                // Register for required events
                RegisterForEvents(
                    _targetWindow, WindowPattern.Pattern, TreeScope.Element);

                // Obtain required control patterns from our automation element
                _transformPattern =
                    GetControlPattern(_targetWindow, TransformPattern.Pattern)
                        as TransformPattern;

                if (_transformPattern == null) return;

                // Is the TransformPattern object moveable?
                if (_transformPattern.Current.CanMove)
                {
                    // Enable our WindowMove fields
                    _xCoordinate.IsEnabled = true;
                    _yCoordinate.IsEnabled = true;
                    _moveTarget.IsEnabled = true;

                    // Move element
                    _transformPattern.Move(0, 0);
                }
                else
                {
                    Feedback("Wndow is not moveable.");
                }
            }
            catch (ElementNotAvailableException)
            {
                Feedback("Client window no longer available.");
            }
            catch (InvalidOperationException)
            {
                Feedback("Client window cannot be moved.");
            }
            catch (Exception exc)
            {
                Feedback(exc.ToString());
            }
        }