Example #1
0
        /// <inheritdoc />
        public void ReleaseBrowser(BrowserAbstract browser)
        {
            // This method is not expected to leak any predictable WebDriver exceptions.
            if (browser == null)
            {
                return;
            }

            FiddlerProxy.ClearHeaders(browser.ProcessId);

            try
            {
                // cleanup the previous state
                browser.DeleteAllCookies();

                // Selenium issue: must navigate away from page after cleaning up cookies otherwise some cookies will persist.
                browser.NavigateTo(browser.DefaultPage);
            }
            // ReSharper disable once EmptyGeneralCatchClause
            catch
            {
                // suppress any exceptions while removing cookies.
                // If there is a problem, the browser will be marked as Faulted and handled in the next block.
            }

            if (this.browserPools.ContainsKey(browser.BrowserType) &&
                !this.browserPools[browser.BrowserType].PoolContains(browser))
            {
                // put the browser back in rotation
                this.browserPools[browser.BrowserType].ReleaseBrowser(browser);
            }
        }
Example #2
0
 /// <summary>
 /// Removes a browser instance from the pool.
 /// </summary>
 /// <param name="browser">
 ///     The browser to remove.
 /// </param>
 public void RemoveInstance(BrowserAbstract browser)
 {
     if (browser != null)
     {
         this.instances.Remove(browser);
         this.timers.Remove(browser);
     }
 }
Example #3
0
        /// <summary>
        /// Returns a previously acquired browser to the pool.
        /// </summary>
        /// <param name="browser">
        ///     The browser to release.
        /// </param>
        public void ReleaseBrowser(BrowserAbstract browser)
        {
            if (this.instances.Contains(browser))
            {
                this.pool.Add(browser);

                this.timers[browser].Stop();

                this.timers[browser].Reset();
            }
        }
Example #4
0
        /// <summary>
        /// Adds a browser instance to the pool.
        /// </summary>
        /// <param name="browser">
        ///     The browser to add.
        /// </param>
        public void AddInstance(BrowserAbstract browser)
        {
            if (browser.BrowserType == this.BrowserType)
            {
                if (!this.timers.ContainsKey(browser))
                {
                    this.timers.Add(new KeyValuePair <BrowserAbstract, Stopwatch>(browser, new Stopwatch()));
                }

                this.instances.Add(browser);
                this.pool.Add(browser);
            }
        }
Example #5
0
        /// <inheritdoc />
        public BrowserAbstract AcquireBrowser(BrowserType browserType)
        {
            BrowserAbstract browser = null;

            if (this.browserPools.ContainsKey(browserType))
            {
                var pool = this.browserPools[browserType];
                browser = pool.WaitForABrowser();

                if (browser == null)
                {
                    Logger.WriteDebug(
                        "Unable to acquire browser {0}", browserType);
                }
            }

            return(browser);
        }
Example #6
0
        /// <inheritdoc />
        public void CreateBrowserInstances()
        {
            // wait a short while for the semaphore, if we can't get it then assume someone else is maintaining the pool
            if (this.syncLock.Wait(100))
            {
                try
                {
                    foreach (var pool in this.browserPools.Values)
                    {
                        for (int i = pool.InstanceCount; i < pool.MaxInstances; i++)
                        {
                            try
                            {
                                BrowserAbstract browser = this.factory.Create(pool.BrowserType);

                                Logger.WriteInfo(
                                    "Registering browser: {0} (PID {1} parent PID {2})",
                                    browser.GetType().Name,
                                    browser.ProcessId,
                                    browser.ParentProcessId);

                                pool.AddInstance(browser);
                            }
                            catch (Exception exception)
                            {
                                Logger.WriteWarning(
                                    exception,
                                    "Unexpected failure while creating a browser of type {0}",
                                    pool.BrowserType);
                            }
                        }
                    }
                }
                finally
                {
                    this.syncLock.Release();
                }
            }
        }
Example #7
0
 /// <summary>
 /// Returns a value indicating whether the specified browser is available in the pool.
 /// </summary>
 /// <param name="browser">
 ///     The browser to verify.
 /// </param>
 /// <returns>
 /// True if the browser is available in the pool, otherwise false.
 /// </returns>
 public bool PoolContains(BrowserAbstract browser)
 {
     return(this.pool.Contains(browser));
 }