///<summary>
 ///</summary>
 ///<param name="eventArgs"></param>
 public BrowserTestResults(RequestEventArgs eventArgs)
 {
     Id = eventArgs.Id;
     if (eventArgs.RequestLog.Body.Length > 0)
     {
         Log = Encoding.UTF8.GetString(eventArgs.RequestLog.Body);
     }
     Error      = eventArgs.RequestLog.Exception;
     StatusCode = eventArgs.RequestLog.StatusCode;
     Url        = eventArgs.RequestLog.Url;
     Success    = Url.IndexOf("success", StringComparison.InvariantCultureIgnoreCase) > -1;
 }
        ///<summary>
        ///</summary>
        ///<param name="url"></param>
        ///<param name="browser"></param>
        ///<param name="timeout"></param>
        ///<returns></returns>
        ///<exception cref="ArgumentNullException"></exception>
        ///<exception cref="InvalidOperationException"></exception>
        public RequestEventArgs RunTest(string url, WebBrowser browser, TimeSpan timeout)
        {
            if (browser == null)
            {
                throw new ArgumentNullException("browser");
            }
            if (string.IsNullOrEmpty(browser.ExecutablePath))
            {
                throw new InvalidOperationException("The specified browser could not be located.");
            }
            if (timeout.TotalMilliseconds == 0.0)
            {
                timeout = TimeSpan.FromMinutes(1.0);
            }
            var waitHandle          = new AutoResetEvent(false);
            RequestEventArgs result = null;
            Process          process;
            EventHandler <RequestEventArgs> logEventHandler = null;
            EventHandler <RequestEventArgs> handler         = logEventHandler;

            logEventHandler = delegate(object sender, RequestEventArgs e)
            {
                if (e.RequestLog.Url.ToLower().Contains(_postKey))
                {
                    Server.RequestComplete -= handler;
                    result = e;
                    waitHandle.Set();
                }
            };
            try
            {
                var startInfo = new ProcessStartInfo(browser.ExecutablePath, url)
                {
                    UseShellExecute = true,
                    WindowStyle     = ProcessWindowStyle.Minimized
                };
                Server.RequestComplete += logEventHandler;
                process = Process.Start(startInfo);
            }
            catch (Exception ex)
            {
                Server.RequestComplete -= logEventHandler;
                return(new RequestEventArgs(Guid.Empty, new LogInfo {
                    StatusCode = -1, Exception = ex.ToString()
                },
                                            new LogInfo()));
            }
            bool flag = waitHandle.WaitOne(timeout);

            try
            {
                if (!process.CloseMainWindow())
                {
                    process.Kill();
                }
            }
            catch
            {
            }
            return(flag ? result : new RequestEventArgs(Guid.Empty, new LogInfo {
                StatusCode = -2
            }, new LogInfo()));
        }