示例#1
0
        /// <summary>
        /// Searches for a window by the given conditions and settings. If not disabled And.Assert().And.Timeout(10000) gets appended.
        /// </summary>
        /// <param name="use">Defines the conditions to be used for searching for a window.</param>
        /// <param name="is">Defines the relation of the window to another object.</param>
        /// <param name="settings">Defines the settings to be used while searching.</param>
        /// <exception cref="DW.CodedUI.WindowNotFoundException">The window could not be found. (If not disabled.)</exception>
        /// <exception cref="DW.CodedUI.WrongSetupException">Dll is missing or in the wrong version.</exception>
        /// <returns>The found window if any; otherwise an exception as long its not disabled by And.NoAssert(). If its disabled the return is null.</returns>
        public static BasicWindow Search(Use use, Is @is, And settings)
        {
            var condition          = use.GetCondition();
            var settingsConditions = settings.GetConditions();
            var instanceNumber     = settings.GetInstanceNumber();
            var timeout            = settings.GetTimeout();
            var useTimeout         = settingsConditions.Contains(AndCondition.Timeout);
            var assertResult       = settingsConditions.Contains(AndCondition.Assert);
            var checkInstance      = settingsConditions.Contains(AndCondition.Instance);
            var useInterval        = settingsConditions.Contains(AndCondition.Interval);
            var interval           = settings.GetInterval();

            if (CodedUIEnvironment.LoggerSettings.ShortLogging)
            {
                LogPool.Append("Search for a window. {0}", use.GetConditionDescription());
            }
            else
            {
                LogPool.Append("Search for a window. {0}", MessageBuilder.BuildMessage(use, useTimeout, useInterval, interval, timeout, @is));
            }

            var watch = new Stopwatch();

            watch.Start();
            while (true)
            {
                var foundInstance = 0;
                var windows       = GetAllWindows();
                foreach (var window in windows)
                {
                    var matchingWindow = Matches(window, condition, @is);
                    if (matchingWindow == null)
                    {
                        continue;
                    }

                    if (!checkInstance || ++foundInstance == instanceNumber)
                    {
                        LogPool.Append("Window '{0}' found.", matchingWindow);
                        return(matchingWindow);
                    }
                }

                if (!useTimeout || watch.Elapsed.TotalMilliseconds >= timeout)
                {
                    if (assertResult)
                    {
                        throw new WindowNotFoundException(use, useTimeout, useInterval, interval, watch.Elapsed, @is);
                    }
                    return(null);
                }

                if (useInterval)
                {
                    Thread.Sleep((int)interval);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Searches for window kinds like Window, MessageBox or system dialogs. If not disabled And.Assert().And.Timeout(10000) gets appended.
        /// </summary>
        /// <typeparam name="TWindow">The type of window to be created.</typeparam>
        /// <param name="use">Defines the conditions to be used for searching for a window.</param>
        /// <param name="is">Defines the relation of the window to another object.</param>
        /// <param name="settings">Defines the settings to be used while searching.</param>
        /// <returns>The found window if any; otherwise an exception as long its not disabled by And.NoAssert(). If its disabled the return is null.</returns>
        /// <exception cref="DW.CodedUI.WindowNotFoundException">The window could not be found. (If not disabled.)</exception>
        /// <exception cref="DW.CodedUI.WrongSetupException">Dll is missing or in the wrong version.</exception>
        /// <remarks>To change the default And settings globaly consider changing the values in the <see cref="DW.CodedUI.CodedUIEnvironment" />.</remarks>
        public static TWindow Search <TWindow>(Use use, Is @is, And settings) where TWindow : BasicWindowBase
        {
            var window = Search(use, @is, settings);

            if (window != null)
            {
                return((TWindow)Activator.CreateInstance(typeof(TWindow), window.AutomationElement));
            }
            return(null);
        }
示例#3
0
 /// <summary>
 /// Searches for a window by the given conditions and settings. If not disabled And.Assert().And.Timeout(10000) gets appended.
 /// </summary>
 /// <param name="use">Defines the conditions to be used for searching for a window.</param>
 /// <param name="settings">Defines the settings to be used while searching.</param>
 /// <returns>The found window if any; otherwise an exception as long its not disabled by And.NoAssert(). If its disabled the return is null.</returns>
 /// <exception cref="DW.CodedUI.WindowNotFoundException">The window could not be found. (If not disabled.)</exception>
 /// <exception cref="DW.CodedUI.WrongSetupException">Dll is missing or in the wrong version.</exception>
 /// <remarks>To change the default And settings globaly consider changing the values in the <see cref="DW.CodedUI.CodedUIEnvironment" />.</remarks>
 public static BasicWindow Search(Use use, And settings)
 {
     return(Search(use, new Is(), settings));
 }
示例#4
0
 /// <summary>
 /// Searches for a window by the given conditions. Default settings are And.Assert().And.Timeout(10000).
 /// </summary>
 /// <param name="use">Defines the conditions to be used for searching for a window.</param>
 /// <param name="is">Defines the relation of the window to another object.</param>
 /// <returns>The found window if any; otherwise an exception is shown.</returns>
 /// <exception cref="DW.CodedUI.WindowNotFoundException">The window could not be found.</exception>
 /// <exception cref="DW.CodedUI.WrongSetupException">Dll is missing or in the wrong version.</exception>
 public static BasicWindow Search(Use use, Is @is)
 {
     return(Search(use, @is, new CombinableAnd()));
 }
示例#5
0
 /// <summary>
 /// Searches for a window by the given conditions. Default settings are And.Assert().And.Timeout(10000).
 /// </summary>
 /// <param name="use">Defines the conditions to be used for searching for a window.</param>
 /// <returns>The found window if any; otherwise an exception is shown.</returns>
 /// <exception cref="DW.CodedUI.WindowNotFoundException">The window could not be found.</exception>
 /// <exception cref="DW.CodedUI.WrongSetupException">Dll is missing or in the wrong version.</exception>
 /// <remarks>To change the default And settings globaly consider changing the values in the <see cref="DW.CodedUI.CodedUIEnvironment" />.</remarks>
 public static BasicWindow Search(Use use)
 {
     return(Search(use, new Is(), new CombinableAnd()));
 }
示例#6
0
 /// <summary>
 /// Searches for window kinds like Window, MessageBox or system dialogs. If not disabled And.Assert().And.Timeout(10000) gets appended.
 /// </summary>
 /// <typeparam name="TWindow">The type of window to be created.</typeparam>
 /// <param name="use">Defines the conditions to be used for searching for a window.</param>
 /// <param name="settings">Defines the settings to be used while searching.</param>
 /// <returns>The found window if any; otherwise an exception as long its not disabled by And.NoAssert(). If its disabled the return is null.</returns>
 /// <exception cref="DW.CodedUI.WindowNotFoundException">The window could not be found. (If not disabled.)</exception>
 /// <exception cref="DW.CodedUI.WrongSetupException">Dll is missing or in the wrong version.</exception>
 /// <remarks>To change the default And settings globaly consider changing the values in the <see cref="DW.CodedUI.CodedUIEnvironment" />.</remarks>
 public static TWindow Search <TWindow>(Use use, And settings) where TWindow : BasicWindowBase
 {
     return(Search <TWindow>(use, new Is(), settings));
 }
示例#7
0
 /// <summary>
 /// Searches for window kinds like Window, MessageBox or system dialogs. Default settings are And.Assert().And.Timeout(10000).
 /// </summary>
 /// <typeparam name="TWindow">The type of window to be created.</typeparam>
 /// <param name="use">Defines the conditions to be used for searching for a window.</param>
 /// <param name="is">Defines the relation of the window to another object.</param>
 /// <returns>The found window if any; otherwise an exception is shown.</returns>
 /// <exception cref="DW.CodedUI.WindowNotFoundException">The window could not be found.</exception>
 /// <exception cref="DW.CodedUI.WrongSetupException">Dll is missing or in the wrong version.</exception>
 /// <remarks>To change the default And settings globaly consider changing the values in the <see cref="DW.CodedUI.CodedUIEnvironment" />.</remarks>
 public static TWindow Search <TWindow>(Use use, Is @is) where TWindow : BasicWindowBase
 {
     return(Search <TWindow>(use, @is, new CombinableAnd()));
 }
示例#8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DW.CodedUI.WindowNotFoundException" /> class.
 /// </summary>
 /// <param name="use">The conditions how the window has been searched.</param>
 /// <param name="useTimeout">A value that indicates if a timeout was used.</param>
 /// <param name="useInterval">A value that indicates if an interval was used.</param>
 /// <param name="intervalTime">The time used in the interval.</param>
 /// <param name="timeout">The elapsed search time.</param>
 /// <param name="is">The relationship to another object.</param>
 public WindowNotFoundException(Use use, bool useTimeout, bool useInterval, uint intervalTime, TimeSpan timeout, Is @is)
     : base(MessageBuilder.BuildErrorMessage(use, useTimeout, useInterval, intervalTime, timeout, @is))
 {
 }