/// <summary> /// Finds the popup dialog. /// </summary> /// <param name="findBy">The find by.</param> /// <param name="timeout">The timeout.</param> /// <returns></returns> private PopupDialog findPopupDialog(Attribute findBy, int timeout) { Logger.LogAction("Busy finding PopupDialog with " + findBy.AttributeName + " '" + findBy.Value + "'"); SimpleTimer timeoutTimer = new SimpleTimer(timeout); do { Thread.Sleep(500); foreach (PopupDialog popupDialog in PopupDialogs) { if (findBy.Compare(popupDialog)) { return popupDialog; } } } while (!timeoutTimer.Elapsed); throw new PopupDialogNotFoundException(findBy.AttributeName, findBy.Value, timeout); }
private void waitUntilExistsOrNot(int timeout, bool waitUntilExists) { // Does it make sense to go into the do loop? if (waitUntilExists) { if (ElementAvailable()) { return; } else if (elementFinder == null) { throw new ItiNException("It's not possible to find the element because no elementFinder is available."); } } else { if (!ElementAvailable()) { return; } } Exception lastException; SimpleTimer timeoutTimer = new SimpleTimer(timeout); do { lastException = null; try { if (Exists == waitUntilExists) { return; } } catch (Exception e) { lastException = e; } Thread.Sleep(200); } while (!timeoutTimer.Elapsed); ThrowTimeOutException(lastException, string.Format("waiting {0} seconds for element to {1}.", timeout, waitUntilExists ? "show up" : "disappear")); }
//private void WaitForFramesToComplete(IHTMLDocument2 maindocument) //{ // HTMLDocument mainHtmlDocument = (HTMLDocument)maindocument; // int framesCount = WatiN.Core.Frame.GetFrameCountFromHTMLDocument(mainHtmlDocument); // for (int i = 0; i != framesCount; ++i) // { // IWebBrowser2 frame = WatiN.Core.Frame.GetFrameFromHTMLDocument(i, mainHtmlDocument); // if (frame != null) // { // IHTMLDocument2 document; // try // { // waitWhileIEBusy(frame); // waitWhileIEStateNotComplete(frame); // document = WaitWhileFrameDocumentNotAvailable(frame); // } // finally // { // // free frame // Marshal.ReleaseComObject(frame); // } // WaitWhileDocumentStateNotComplete(document); // WaitForFramesToComplete(document); // } // } //} /// <summary> /// This method is called to initialise the start time for /// determining a time out. It's set to the current time. /// </summary> /// <returns></returns> protected internal SimpleTimer InitTimeout() { waitForCompleteTimeout = new SimpleTimer(InfopathTester.Settings.WaitForCompleteTimeOut); return waitForCompleteTimeout; }
/// <summary> /// Waits until the given <paramref name="attribute" /> matches. /// </summary> /// <param name="attribute">The attribute.</param> /// <param name="timeout">The timeout.</param> public void WaitUntil(Attribute attribute, int timeout) { Exception lastException; ElementAttributeBag attributeBag = new ElementAttributeBag(); SimpleTimer timeoutTimer = new SimpleTimer(timeout); do { lastException = null; try { // Calling Exists will refresh the reference to the html element // so the compare is against the current html element (and not // against some cached reference. if (Exists) { attributeBag.IHTMLElement = htmlElement; if (attribute.Compare(attributeBag)) { return; } } } catch (Exception e) { lastException = e; } Thread.Sleep(200); } while (!timeoutTimer.Elapsed); ThrowTimeOutException(lastException, string.Format("waiting {0} seconds for element attribute '{1}' to change to '{2}'.", timeout, attribute.AttributeName, attribute.Value)); }