Close() public method

Closes the current window
public Close ( ) : void
return void
Example #1
0
        /// <summary>
        /// Invokes a delegate that causes a new window to open, and return an object representing the new window
        /// </summary>
        /// <param name="action">The delegate that should cause a new window to open</param>
        /// <param name="windowDescription">A description that will identify the window in the log</param>
        /// <param name="timeout">The maximal time to wait for the window to open</param>
        /// <returns>The <see cref="BrowserWindow"/> object that represent the newly opened window</returns>
        /// <exception cref="ArgumentNullException"><paramref name="action"/> or <paramref name="windowDescription"/> are null</exception>
        /// <exception cref="TimeoutException">A new window wasn't opened for the specified timeout after the delegate completed</exception>
        /// <remarks>
        /// When the current <see cref="IIsolationScope"/> ends, the window is automatically closed
        /// </remarks>
        /// <example>
        /// <code>
        /// var openNewWindowButton = myBrowser.WaitForElement(By.Id("openNewWindowButtonId"), "Open new window button");
        /// var newWindow = myBrowser.OpenWindow(() => openNewButton.Click(), "New window");
        /// Assert.AreEqual("New window Title", newWindow.Title);
        /// </code>
        /// </example>
        public BrowserWindow OpenWindow([InstantHandle] Action action, string windowDescription, TimeSpan timeout)
        {
            CheckDisposed();
            if (action == null)
            {
                throw new ArgumentNullException("action");
            }
            if (windowDescription == null)
            {
                throw new ArgumentNullException("windowDescription");
            }
            Activate();
            var webDriver       = GetWebDriver();
            var existingHandles = webDriver.WindowHandles;

            action();

            var newWindowHandle = Wait.Until(() => webDriver.WindowHandles.Except(existingHandles).SingleOrDefault(),
                                             handle => handle != null,
                                             timeout, "Window '{0}' wasn't opened for 60 seconds", windowDescription);

            Logger.WriteLine("Opened window '{0}' with id={1} ({2})", windowDescription, newWindowHandle.GetHashCode(), newWindowHandle);

            var newWindow = new BrowserWindow(this, newWindowHandle, windowDescription);

            _testExecutionScopesManager.AddCleanupAction(() => newWindow.Close());

            return(newWindow);
        }
Example #2
0
        /// <summary>
        /// Invokes a delegate that causes a new window to open, and return an object representing the new window
        /// </summary>
        /// <param name="action">The delegate that should cause a new window to open</param>
        /// <param name="windowDescription">A description that will identify the window in the log</param>
        /// <returns>The <see cref="BrowserWindow"/> object that represent the newly opened window</returns>
        /// <exception cref="ArgumentNullException"><paramref name="action"/> or <paramref name="windowDescription"/> are null</exception>
        /// <exception cref="TimeoutException">A new window wasn't opened for 60 seconds after the delegate completed</exception>
        /// <remarks>
        /// When the current <see cref="IIsolationScope"/> ends, the window is automatically closed
        /// </remarks>
        /// <example>
        /// <code>
        /// var openNewWindowButton = myBrowser.WaitForElement(By.Id("openNewWindowButtonId"), "Open new window button");
        /// var newWindow = myBrowser.OpenWindow(() => openNewButton.Click(), "New window");
        /// Assert.AreEqual("New window Title", newWindow.Title);
        /// </code>
        /// </example>
        public BrowserWindow OpenWindow(Action action, string windowDescription)
        {
            CheckDisposed();
            if (action == null)
                throw new ArgumentNullException("action");
            if (windowDescription == null)
                throw new ArgumentNullException("windowDescription");

            Activate();
            var webDriver = GetWebDriver();
            var existingHandles = webDriver.WindowHandles;
            action();

            var newWindowHandle = Wait.Until(() => webDriver.WindowHandles.Except(existingHandles).SingleOrDefault(),
                handle => handle != null,
                60.Seconds(), "Window '{0}' wasn't opened for 60 seconds", windowDescription);

            Logger.WriteLine("Opened window '{0}' with id={1} ({2})", windowDescription, newWindowHandle.GetHashCode(), newWindowHandle);

            var newWindow = new BrowserWindow(this, newWindowHandle, windowDescription);
            TestBase.AddCleanupAction(() => newWindow.Close());

            return newWindow;
        }