public void ShouldSetInnerExcpetionWithLastException()
        {
            // GIVEN
            var timeOut = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(1))
            {
                ExceptionMessage = () => "throwing exceptions"
            };

            // WHEN
            try
            {
                timeOut.Try(() =>
                {
                    var zero = 0;
                    return(1 / zero == 0);
                });
            }
            catch (Exception e)
            {
                // THEN
                Assert.That(e.InnerException, Is.Not.Null, "Expected an innerexception");
                Assert.That(e.InnerException.GetType(), Is.EqualTo(typeof(DivideByZeroException)), "Expected DivideByZeroException");
                return;
            }

            Assert.Fail("Expected TimeOutException");
        }
Beispiel #2
0
        internal static Process CreateProcess(string arguments, bool waitForMainWindow)
        {
            var ffProcess = new Process {
                StartInfo = { FileName = PathToExe, Arguments = arguments }
            };

            ffProcess.Start();
            ffProcess.WaitForInputIdle(5000);
            ffProcess.Refresh();

            if (waitForMainWindow)
            {
                var action = new TryFuncUntilTimeOut(Settings.WaitForCompleteTimeOut)
                {
                    SleepTime = 200
                };
                var result = action.Try(() =>
                {
                    ffProcess.Refresh();
                    if (!ffProcess.HasExited && ffProcess.MainWindowHandle != IntPtr.Zero)
                    {
                        Logger.LogAction("Waited for FireFox, main window handle found.");
                        return(true);
                    }
                    return(false);
                });

                if (!result)
                {
                    Debug.WriteLine("Timer elapsed waiting for FireFox to start.");
                }
            }

            return(ffProcess);
        }
Beispiel #3
0
Datei: IE.cs Projekt: minskowl/MY
        private static IE CreateIEPartiallyInitializedInNewProcess()
        {
            var m_Proc = CreateIExploreInNewProcess();

            var action = new TryFuncUntilTimeOut(Settings.AttachToIETimeOut)
            {
                SleepTime = 500
            };
            var ie = action.Try(() =>
            {
                m_Proc.Refresh();
                var mainWindowHandle = m_Proc.MainWindowHandle;

                return(mainWindowHandle != IntPtr.Zero
                    ? FindIEPartiallyInitialized(new AttributeConstraint("hwnd", mainWindowHandle.ToString()))
                    : null);
            });

            if (ie != null)
            {
                return(ie);
            }

            throw new IENotFoundException("Timeout while waiting to attach to newly created instance of IE.", Settings.AttachToIETimeOut);
        }
        public void ShouldCreateTimeOutException()
        {
            // GIVEN
            var timeoutsec = 1;
            var timeOut = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(timeoutsec))
                              {
                                  ExceptionMessage = () => string.Format("returning false for {0} seconds", timeoutsec)
                              };

            // WHEN
            try
            {
                timeOut.Try(() => false);
            }
            catch(Exception e)
            {
                // THEN
                Assert.That(e is Exceptions.TimeoutException, "Unexpected exception type: " + e.GetType());
                Assert.That(e.Message, Is.EqualTo("Timeout while returning false for 1 seconds"), "Unexpected exception message");
                Assert.That(e.InnerException, Is. Null, "Expected no InnerException");
                return;
            }

            Assert.Fail("Expected TimeOutException");
        }
        public void ShouldCreateTimeOutException()
        {
            // GIVEN
            var timeoutsec = 1;
            var timeOut    = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(timeoutsec))
            {
                ExceptionMessage = () => string.Format("returning false for {0} seconds", timeoutsec)
            };

            // WHEN
            try
            {
                timeOut.Try(() => false);
            }
            catch (Exception e)
            {
                // THEN
                Assert.That(e is Exceptions.TimeoutException, "Unexpected exception type: " + e.GetType());
                Assert.That(e.Message, Is.EqualTo("Timeout while returning false for 1 seconds"), "Unexpected exception message");
                Assert.That(e.InnerException, Is.Null, "Expected no InnerException");
                return;
            }

            Assert.Fail("Expected TimeOutException");
        }
Beispiel #6
0
        /// <inheritdoc />
        public void WaitUntilReady()
        {
            WaitUntilElementAvailable();

            if (ElementTag.IsMatch(ElementFactory.GetElementTags <Image>(), this))
            {
                return;
            }

            // Wait as long as the readystate of an element is BETWEEN
            // Uninitialized and Complete. If it's uninitialized,
            // it's quite probable that it will never reach Complete.
            // Like for elements that could not load an image or icon
            // or some other bits not part of the HTML page.
            var tryFuncUntilTimeOut = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(Settings.WaitForCompleteTimeOut));
            var ihtmlElement2       = AsHtmlElement2;
            var success             = tryFuncUntilTimeOut.Try(() =>
            {
                var readyState = ihtmlElement2.readyStateValue;
                return(readyState == 0 || readyState == 4);
            });

            if (success)
            {
                return;
            }

            throw new WatiNException(String.Format("Element didn't reach readystate = complete within {0} seconds: {1}", Settings.WaitForCompleteTimeOut, AsHtmlElement.outerText));
        }
        public bool WaitUntilHandled(int timeoutAfterSeconds)
        {
            var tryActionUntilTimeOut = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(timeoutAfterSeconds));
            tryActionUntilTimeOut.Try(() => HasHandledDialog);

            return HasHandledDialog;
        }
Beispiel #8
0
        protected void WaitUntil(DoFunc<bool> waitWhile, BuildTimeOutExceptionMessage exceptionMessage)
        {
            if (_waitForCompleteTimer == null) throw new WatiNException("_waitForCompleteTimer not initialized");

            var timeOut = new TryFuncUntilTimeOut(_waitForCompleteTimer) {ExceptionMessage = exceptionMessage};
            timeOut.Try(waitWhile);
        }
        private static IEBrowser CreateIEPartiallyInitializedInNewProcess()
        {
            var m_Proc = CreateIExploreInNewProcess();
            var helper = new AttachToIeHelper();

            var action = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(Settings.AttachToBrowserTimeOut))
            {
                SleepTime = TimeSpan.FromMilliseconds(500)
            };

            var ie = action.Try(() =>
            {
                m_Proc.Refresh();
                var mainWindowHandle = m_Proc.MainWindowHandle;

                return(mainWindowHandle != IntPtr.Zero
                    ? helper.FindIEPartiallyInitialized(new AttributeConstraint("hwnd", mainWindowHandle.ToString()))
                    : null);
            });

            if (ie != null)
            {
                return(ie._ieBrowser);
            }

            throw new BrowserNotFoundException("IE", "Timeout while waiting to attach to newly created instance of IE.", Settings.AttachToBrowserTimeOut);
        }
Beispiel #10
0
        public void GoToUrlNoWait()
        {
            ExecuteTest(browser =>
            {
                // GIVEN
                Assert.That(browser.Url, Is.EqualTo(AboutBlank), "Pre-condition");

                var url = MainURI.AbsoluteUri;

                // WHEN
                browser.GoToNoWait(url);

                // THEN
                // This might fail in FireFox, although the check is essentail,
                // a constant failing test is even worse, so skip it for FireFox
                if (browser.GetType().IsInstanceOfType(typeof(IE)))
                {
                    Assert.That(browser.Url, Is.EqualTo(AboutBlank), "Right after GoToNoWait");
                }

                TryFuncUntilTimeOut.Try(TimeSpan.FromSeconds(3), () => browser.Uri == MainURI);
                browser.WaitForComplete();

                Assert.AreEqual(MainURI, new Uri(browser.Url), "Final check");
            });
        }
        public bool WaitUntilHandled(int timeoutAfterSeconds)
        {
            var tryActionUntilTimeOut = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(timeoutAfterSeconds));

            tryActionUntilTimeOut.Try(() => HasHandledDialog);

            return(HasHandledDialog);
        }
        public IE TryFindIe(Constraint findBy, SimpleTimer timer)
        {
            var action = new TryFuncUntilTimeOut(timer)
            {
                SleepTime = TimeSpan.FromMilliseconds(500)
            };

            return action.Try(() => FindIEPartiallyInitialized(findBy));
        }
Beispiel #13
0
        public virtual void WaitUntilClosed(int timeout)
        {
            var tryActionUntilTimeOut = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(timeout))
            {
                ExceptionMessage = () => string.Format("waiting {0} seconds for HtmlDialog to close.", timeout)
            };

            tryActionUntilTimeOut.Try(() => !Exists);
        }
        private IE TryFindIe(Constraint findBy, SimpleTimer timer)
        {
            var action = new TryFuncUntilTimeOut(timer)
            {
                SleepTime = TimeSpan.FromMilliseconds(500)
            };

            return(action.Try(() => FindIEPartiallyInitialized(findBy)));
        }
Beispiel #15
0
		public void WaitUntilExists(int waitDurationInSeconds)
		{
            var tryActionUntilTimeOut = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(waitDurationInSeconds));
            tryActionUntilTimeOut.Try(() => Exists());
            
			if (!Exists())
			{
				throw new WatiNException(string.Format("Dialog not available within {0} seconds.", waitDurationInSeconds));
			}
		}
        /// <summary>
        /// Waits until the text is inside the HTML Body element contains the given <paramref name="text" />.
        /// </summary>
        /// <param name="text">The text.</param>
        /// <param name="timeOut">The number of seconds to wait</param>
        /// <returns>
        ///     <see name="TimeoutException"/> if the specified text is not found within the time out period.
        /// </returns>
        public virtual void WaitUntilContainsText(string text, int timeOut)
        {
            var tryActionUntilTimeOut = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(timeOut))
            {
                SleepTime        = TimeSpan.FromMilliseconds(50),
                ExceptionMessage = () => string.Format("waiting {0} seconds for document to contain text '{1}'.", timeOut, text)
            };

            tryActionUntilTimeOut.Try(() => ContainsText(text));
        }
Beispiel #17
0
        /// <summary>
        /// Waits until the text is inside the HTML Body element contains the given <paramref name="text" />.
        /// </summary>
        /// <param name="text">The text.</param>
        /// <param name="timeOut">The number of seconds to wait</param>
        /// <returns>
        ///     <see name="TimeoutException"/> if the specified text is not found within the time out period.
        /// </returns>
        public virtual void WaitUntilContainsText(string text, int timeOut)
        {
            var tryActionUntilTimeOut = new TryFuncUntilTimeOut(timeOut)
            {
                SleepTime        = 50,
                ExceptionMessage = () => string.Format("waiting {0} seconds for document to contain text '{1}'.", Settings.WaitUntilExistsTimeOut, text)
            };

            tryActionUntilTimeOut.Try(() => ContainsText(text));
        }
Beispiel #18
0
        /// <summary>
        /// Waits until the <paramref name="regex" /> matches some text inside the HTML Body element.
        /// </summary>
        /// <param name="regex">The regular expression to match with.</param>
        /// <param name="timeOut">The number of seconds to wait</param>
        /// <returns>
        ///     <see name="TimeoutException"/> if the specified text is not found within the time out period.
        /// </returns>
        public virtual void WaitUntilContainsText(Regex regex, int timeOut)
        {
            var tryActionUntilTimeOut = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(timeOut))
            {
                SleepTime        = TimeSpan.FromMilliseconds(50),
                ExceptionMessage = () => string.Format("waiting {0} seconds for document to contain regex '{1}'.", Settings.WaitUntilExistsTimeOut, regex)
            };

            tryActionUntilTimeOut.Try(() => ContainsText(regex));
        }
        public void TryShouldReturnFalseIfDidTimeOut()
        {
            // GIVEN
            var timeOut = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(1));
            
            // WHEN
            var result = timeOut.Try(() => false );

            // THEN
            Assert.That(result, Is.False);
        }
        public void SleepTimeShouldDefaultToSettingsSleepTime()
        {
            // GIVEN
            Settings.SleepTime = 123;

            // WHEN
            var timeOut = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(1));

            // THEN
            Assert.That(timeOut.SleepTime.TotalMilliseconds, Is.EqualTo(123), "Unexpected default timeout");
        }
        public void SleepTimeShouldDefaultToSettingsSleepTime()
        {
            // GIVEN
            Settings.SleepTime = 123;

            // WHEN
            var timeOut = new TryFuncUntilTimeOut(1);

            // THEN
            Assert.That(timeOut.SleepTime, Is.EqualTo(123), "Unexpected default timeout");
        }
Beispiel #22
0
        /// <summary>
        /// Wait until the save/open/run dialog opens.
        /// This exists because some web servers are slower to start a file than others.
        /// </summary>
        /// <param name="waitDurationInSeconds">duration in seconds to wait</param>
        public void WaitUntilFileDownloadDialogIsHandled(int waitDurationInSeconds)
        {
            var tryActionUntilTimeOut = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(waitDurationInSeconds));

            tryActionUntilTimeOut.Try(() => HasHandledFileDownloadDialog);

            if (!HasHandledFileDownloadDialog)
            {
                throw new WatiNException(string.Format("Has not shown dialog after {0} seconds.", waitDurationInSeconds));
            }
        }
        public void ShouldTimeOutifActionDidNotReturnSucces()
        {
            // GIVEN
            var timeOut = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(1));

            // WHEN
            timeOut.Try(() => false);

            // THEN
            Assert.That(timeOut.DidTimeOut, Is.True, "Expected timout");
        }
        public void TryShouldReturnFalseIfDidTimeOut()
        {
            // GIVEN
            var timeOut = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(1));

            // WHEN
            var result = timeOut.Try(() => false);

            // THEN
            Assert.That(result, Is.False);
        }
        public void TryShouldReturnTrueIfNoTimeOut()
        {
            // GIVEN
            var timeOut = new TryFuncUntilTimeOut(1);

            // WHEN
            var result = timeOut.Try(() => true);

            // THEN
            Assert.That(result, Is.True);
        }
        public void WaitUntilExists(int waitDurationInSeconds)
        {
            var tryActionUntilTimeOut = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(waitDurationInSeconds));

            tryActionUntilTimeOut.Try <bool>(Exists);

            if (!Exists())
            {
                throw new WatiNException(string.Format("Dialog not available within {0} seconds.", waitDurationInSeconds));
            }
        }
        public void ShouldCallTheAction()
        {
            // GIVEN
            var actionCalled = false;
            var timeOut = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(2));

            // WHEN
            timeOut.Try(() => { actionCalled = true; return true; });

            // THEN
            Assert.That(actionCalled, Is.True, "action not called");
        }
Beispiel #28
0
        /// <summary>
        /// Wait until the download progress window does not exist any more
        /// </summary>
        /// <param name="waitDurationInSeconds">duration in seconds to wait</param>
        public void WaitUntilDownloadCompleted(int waitDurationInSeconds)
        {
            var tryActionUntilTimeOut = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(waitDurationInSeconds));

            tryActionUntilTimeOut.Try(() => !ExistsOrNull(DownloadProgressDialog));

            if (ExistsOrNull(DownloadProgressDialog))
            {
                throw new WatiNException(string.Format("Still downloading after {0} seconds.", waitDurationInSeconds));
            }

            Logger.LogAction("Download complete at {0}", DateTime.Now.ToLongTimeString());
        }
        public void ShouldCallTheAction()
        {
            // GIVEN
            var actionCalled = false;
            var timeOut      = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(2));

            // WHEN
            timeOut.Try(() => { actionCalled = true; return(true); });


            // THEN
            Assert.That(actionCalled, Is.True, "action not called");
        }
Beispiel #30
0
        private static void WaitUntilVisibleOrTimeOut(Window window)
        {
            // Wait untill window is visible so all properties
            // of the window class (like Style and StyleInHex)
            // will return valid values.
            var tryActionUntilTimeOut = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(Settings.WaitForCompleteTimeOut));
            var success = tryActionUntilTimeOut.Try(() => window.Visible);

            if (!success)
            {
                Logger.LogAction((LogFunction log) => { log("Dialog with title '{0}' not visible after {1} seconds.", window.Title, Settings.WaitForCompleteTimeOut); });
            }
        }
        public Browser Find(Constraint findBy, int timeout, bool waitForComplete)
        {
            Logger.LogAction("Busy finding FireFox matching constraint {0}", findBy);

            var action = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(timeout)) { SleepTime = TimeSpan.FromMilliseconds(500) };
            var fireFox = action.Try(() => FindFireFox(findBy));

            if (fireFox != null)
            {
                if (waitForComplete) fireFox.WaitForComplete();
                return fireFox;
            }

            throw new BrowserNotFoundException("FireFox", findBy.ToString(), timeout);
        }
Beispiel #32
0
Datei: IE.cs Projekt: minskowl/MY
        private HtmlDialog FindHtmlDialog(Constraint findBy, int timeout)
        {
            Logger.LogAction("Busy finding HTMLDialog matching criteria: " + findBy);

            var action = new TryFuncUntilTimeOut(timeout)
            {
                SleepTime = 500
            };
            var result = action.Try(() => HtmlDialogs.First(findBy));

            if (result == null)
            {
                throw new HtmlDialogNotFoundException(findBy.ToString(), timeout);
            }

            return(result);
        }
Beispiel #33
0
        private void WaitUntilElementAvailable()
        {
            var tryActionUntilTimeOut = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(Settings.WaitForCompleteTimeOut));
            var ihtmlElement          = AsHtmlElement;
            var success = tryActionUntilTimeOut.Try(() =>
            {
                var tagName = ihtmlElement.tagName;
                return(true);
            });

            if (success)
            {
                return;
            }

            throw new WatiNException(String.Format("Element wasn't available within {0} seconds.", Settings.WaitForCompleteTimeOut));
        }
        public void ShouldNotAllowNullAsAction()
        {
            // Given
            var timeout = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(30));

            // When
            try
            {
                timeout.Try <object>(null);
            }
            catch (Exception e)
            {
                Assert.That(e is ArgumentNullException, Is.True, "Action should be required");
                Assert.That(e.Message, Text.Contains("func"), "Expected for argument 'func'");
                return;
            }
            Assert.Fail("Expected an ArgumentNullException");
        }
 public void ShouldNotAllowNullAsAction()
 {
     // Given
     var timeout = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(30));
     
     // When
     try
     {
         timeout.Try<object>(null);
     }
     catch (Exception e)
     {
         Assert.That(e is ArgumentNullException, Is.True, "Action should be required");
         Assert.That(e.Message, Text.Contains("func"), "Expected for argument 'func'");
         return;
     }
     Assert.Fail("Expected an ArgumentNullException");
 }
Beispiel #36
0
        private HtmlDialog FindHtmlDialog(Constraint findBy, int timeout)
        {
            Logger.LogAction((LogFunction log) => { log("Busy finding HTMLDialog matching criteria: {0}", findBy); });

            var action = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(timeout))
            {
                SleepTime = TimeSpan.FromMilliseconds(500)
            };

            var result = action.Try(() => HtmlDialogs.First(findBy));

            if (result == null)
            {
                throw new HtmlDialogNotFoundException(findBy.ToString(), timeout);
            }

            return(result);
        }
Beispiel #37
0
        public void GoToUrlNoWait()
        {
            ExecuteTest(browser =>
            {
                Assert.That(browser.Url, Is.EqualTo(AboutBlank));

                var url = MainURI.AbsoluteUri;

                browser.GoToNoWait(url);

                Assert.That(browser.Url, Is.EqualTo(AboutBlank));

                TryFuncUntilTimeOut.Try(TimeSpan.FromSeconds(3), () => browser.Uri == MainURI);
                browser.WaitForComplete();

                Assert.AreEqual(MainURI, new Uri(browser.Url));
            });
        }
Beispiel #38
0
        private void AttachToExisting(Constraint findBy, int timeout, bool waitForComplete)
        {
            var action = new TryFuncUntilTimeOut(timeout)
            {
                SleepTime = 500
            };
            bool found = action.Try(() => FindFireFox(findBy));

            if (found)
            {
                if (waitForComplete)
                {
                    WaitForComplete();
                }
                return;
            }

            throw new FireFoxNotFoundException(findBy.ToString(), timeout);
        }
Beispiel #39
0
	    private static void WaitUntilVisibleOrTimeOut(Window window)
		{
			// Wait untill window is visible so all properties
			// of the window class (like Style and StyleInHex)
			// will return valid values.
		    var tryActionUntilTimeOut = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(Settings.WaitForCompleteTimeOut));
            var success = tryActionUntilTimeOut.Try(() => window.Visible);

            if (!success)
            {
                Logger.LogAction("Dialog with title '{0}' not visible after {1} seconds.", window.Title, Settings.WaitForCompleteTimeOut);
            }
		}
        public void SleepTimeShouldDefaultToSettingsSleepTime()
        {
            // GIVEN
            Settings.SleepTime = 123;

            // WHEN
            var timeOut = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(1));

            // THEN
            Assert.That(timeOut.SleepTime.TotalMilliseconds, Is.EqualTo(123), "Unexpected default timeout");
        }
        public void ShouldSetInnerExcpetionWithLastException()
        {
            // GIVEN
            var timeOut = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(1))
                              {
                                  ExceptionMessage = () => "throwing exceptions"
                              };
            
            // WHEN
            try
            {
                timeOut.Try(() =>
                    {
                        var zero = 0;
                        return 1 / zero == 0;
                    });
            }
            catch(Exception e)
            {
                // THEN
                Assert.That(e.InnerException, Is.Not.Null, "Expected an innerexception");
                Assert.That(e.InnerException.GetType(), Is.EqualTo(typeof(DivideByZeroException)), "Expected DivideByZeroException");
                return;
            }

            Assert.Fail("Expected TimeOutException");
        }
		private HtmlDialog FindHtmlDialog(Constraint findBy, int timeout)
		{
			Logger.LogAction("Busy finding HTMLDialog matching criteria: {0}", findBy);

            var action = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(timeout))
            {
                SleepTime = TimeSpan.FromMilliseconds(500)
            };

            var result = action.Try(() => HtmlDialogs.First(findBy));
            
            if (result == null)
            {
                throw new HtmlDialogNotFoundException(findBy.ToString(), timeout);
            }
            
            return result;
		}
		private static IEBrowser CreateIEPartiallyInitializedInNewProcess()
		{
			var m_Proc = CreateIExploreInNewProcess();
		    var helper = new AttachToIeHelper();

		    var action = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(Settings.AttachToBrowserTimeOut))
            {
                SleepTime = TimeSpan.FromMilliseconds(500)
            };

            var ie = action.Try(() =>
            {
                m_Proc.Refresh();
                var mainWindowHandle = m_Proc.MainWindowHandle;

                return mainWindowHandle != IntPtr.Zero
                    ? helper.FindIEPartiallyInitialized(new AttributeConstraint("hwnd", mainWindowHandle.ToString()))
                    : null;
            });

            if (ie != null) return ie._ieBrowser; 

			throw new BrowserNotFoundException("IE", "Timeout while waiting to attach to newly created instance of IE.", Settings.AttachToBrowserTimeOut);
		}
Beispiel #44
0
        public virtual void WaitUntilClosed(int timeout)
	    {
            var tryActionUntilTimeOut = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(timeout))
            {
                ExceptionMessage = () => string.Format("waiting {0} seconds for HtmlDialog to close.", timeout)
            };

            tryActionUntilTimeOut.Try(() => !Exists);
        }
        private bool HandledDownloadProgressDialog(Window window)
        {
            if (IsDownloadProgressDialog(window))
            {
                DownloadProgressDialog = window;

                var openOrRun= new WinButton(4377, new Hwnd(window.Hwnd));

                if (openOrRun.Enabled)
                {
                    var close = new WinButton(2, new Hwnd(window.Hwnd));
                    close.Click();

                    var actionUntilTimeOut = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(5));
                    actionUntilTimeOut.Try(() => window.Exists());

                    // TODO: What to do if the window doesn't close after timeout?
                }

                return true;
            }
            return false;
        }
Beispiel #46
0
        internal static void CreateProcess(string arguments, bool waitForMainWindow)
        {
            var ffProcess = new Process {StartInfo = {FileName = PathToExe, Arguments = arguments}};
            
            ffProcess.Start();
            ffProcess.WaitForInputIdle(5000);
            ffProcess.Refresh();

            if (!waitForMainWindow) return;
            
            var action = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(Settings.WaitForCompleteTimeOut))
                             {
                                 SleepTime = TimeSpan.FromMilliseconds(200)
                             };

            var result = action.Try(() =>
                            {
                                ffProcess.Refresh();
                                if (!ffProcess.HasExited && ffProcess.MainWindowHandle != IntPtr.Zero)
                                {
                                    Logger.LogAction("Waited for FireFox, main window handle found.");
                                    return true;
                                }
                                return false;
                            });

            if (!result)
            {
                Debug.WriteLine("Timer elapsed waiting for FireFox to start.");
            }
        }
        public void CloseFireFoxProcess()
        {
            //if (Process == null) return;
            
            //Process.WaitForExit(5000);
            
            //if (Process == null || Process.HasExited) return;

            System.Diagnostics.Process firefoxProcess = FireFox.CurrentProcess;
            if (firefoxProcess == null)
            {
                return;
            }

            firefoxProcess.WaitForExit(5000);

            firefoxProcess = FireFox.CurrentProcess;
            if (firefoxProcess == null)
            {
                return;
            }
            else if (firefoxProcess.HasExited)
            {
                TryFuncUntilTimeOut waiter = new TryFuncUntilTimeOut(TimeSpan.FromMilliseconds(5000));
                bool procIsNull = waiter.Try<bool>(() => { firefoxProcess = FireFox.CurrentProcess; return firefoxProcess == null; });
                if (procIsNull)
                {
                    if (!waiter.DidTimeOut && firefoxProcess == null)
                    {
                        return;
                    }
                }
            }

            Logger.LogDebug("Killing FireFox process");
            UtilityClass.TryActionIgnoreException(() => Process.Kill());
        }
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources
        /// </summary>
        /// <param name="disposing">
        /// <c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.
        /// </param>
        public void Dispose(bool disposing)
        {
            // Check to see if Dispose has already been called.
            if (!_disposed)
            {
                // If disposing equals true, dispose all managed 
                // and unmanaged resources.
                if (disposing)
                {
                    // Dispose managed resources.
                    if (_telnetSocket != null && _telnetSocket.Connected && (Process == null || !Process.HasExited))
                    {
                        try
                        {
                            WriteAndRead("{0}.home();", PromptName);
                            var windowCount = WriteAndReadAsInt("{0}.getWindows().length", PromptName);
                            Logger.LogDebug(string.Format("Closing window. {0} total windows found", windowCount));
                            SendCommand(string.Format("{0}.close();", WindowVariableName));
                            if (windowCount == 1)
                            {
                                Logger.LogDebug("No further windows remain open.");
                                CloseConnection();
                                CloseFireFoxProcess();
                            }
                            else
                            {
                                TryFuncUntilTimeOut waiter = new TryFuncUntilTimeOut(TimeSpan.FromMilliseconds(2000));
                                bool windowClosed = waiter.Try<bool>(() => { return WriteAndReadAsInt("{0}.getWindows().length", PromptName) == windowCount - 1; });
                            }
                        }
                        catch (IOException ex)
                        {
                            Logger.LogDebug("Error communicating with mozrepl server to initiate shut down, message: {0}", ex.Message);
                        }
                    }
                }
            }

            _disposed = true;
            Connected = false;
        }
        /// <summary>
        /// Wait until the download progress window does not exist any more
        /// </summary>
        /// <param name="waitDurationInSeconds">duration in seconds to wait</param>
        public void WaitUntilDownloadCompleted(int waitDurationInSeconds)
        {
            var tryActionUntilTimeOut = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(waitDurationInSeconds));
            tryActionUntilTimeOut.Try(() => !ExistsOrNull(DownloadProgressDialog));

            if (ExistsOrNull(DownloadProgressDialog))
            {
                throw new WatiNException(string.Format("Still downloading after {0} seconds.", waitDurationInSeconds));
            }

            Logger.LogAction("Download complete at {0}", DateTime.Now.ToLongTimeString());
        }
        /// <summary>
        /// Wait until the save/open/run dialog opens.
        /// This exists because some web servers are slower to start a file than others.
        /// </summary>
        /// <param name="waitDurationInSeconds">duration in seconds to wait</param>
        public void WaitUntilFileDownloadDialogIsHandled(int waitDurationInSeconds)
        {
            var tryActionUntilTimeOut = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(waitDurationInSeconds));
            tryActionUntilTimeOut.Try(() => HasHandledFileDownloadDialog);

            if (!HasHandledFileDownloadDialog)
            {
                throw new WatiNException(string.Format("Has not shown dialog after {0} seconds.", waitDurationInSeconds));
            }
        }
        public void ShouldTimeOutifActionDidNotReturnSucces()
        {
            // GIVEN
            var timeOut = new TryFuncUntilTimeOut(TimeSpan.FromSeconds(1));
            
            // WHEN
            timeOut.Try(() => false );

            // THEN
            Assert.That(timeOut.DidTimeOut, Is.True, "Expected timout");
        }
Beispiel #52
0
        protected virtual void WaitUntil(DoFunc<bool> waitWhile, BuildTimeOutExceptionMessage exceptionMessage)
        {
            if (Timer == null)
                throw new WatiNException("_waitForCompleteTimer not initialized");

            var timeOut = new TryFuncUntilTimeOut(Timer) {ExceptionMessage = exceptionMessage};
            timeOut.Try(waitWhile);
        }