Esempio n. 1
0
        private void RunTestsInternal(object state)
        {
            TestcaseExecutorTaskInfo taskInfo = (TestcaseExecutorTaskInfo)state;
            int threadId = Thread.CurrentThread.ManagedThreadId;

            // create a browser queue with this thread id
            CommandManager.CreateBrowserQueue(threadId);

            //notify the page that we just created a browser queue and send the thread id
            taskInfo.NotifyBrowserQueueCreated(threadId);

            BrowserCommand command = new BrowserCommand(BrowserCommand.FunctionNames.TestRunStarted);

            command.Description = "Test Run Started";
            command.Handler.RequiresElementFound = false;
            command.Handler.SetArguments(_testcases.Count);
            CommandManager.ExecuteCommand(threadId, command, 10);

            OnTestRunStarted(new EventArgs());

            foreach (Testcase testcase in taskInfo.Testcases)
            {
                testcase.TestcaseExecuting += new EventHandler <TestcaseExecutionEventArgs>(testcase_TestcaseExecuting);
                testcase.TestcaseExecuted  += new EventHandler <TestcaseExecutionEventArgs>(testcase_TestcaseExecuted);

                // [05/05/2009] clear the traces that might have been left from a previous test.
                WebTestConsole.Clear();

                try
                {
                    testcase.Execute();
                }
                catch (TimeoutException)
                {
                    // Abort the test run if we receive a TimeoutException because
                    // this likely means the browser has been closed and we don't
                    // want the server to keep sending test commands and timing out
                    // for each of them.
                    return;
                }
            }

            command             = new BrowserCommand(BrowserCommand.FunctionNames.TestRunFinished);
            command.Description = "Test Run Finished";
            command.Handler.RequiresElementFound = false;
            BrowserInfo result = CommandManager.ExecuteCommand(threadId, command, 10);

            // Provide the results of the test run to anyone interested
            string log = result != null ? result.Data : null;

            taskInfo.RequestDetails.Add("TestLog", log);

            OnTestRunFinished(new TestRunFinishedEventArgs(taskInfo.Testcases, taskInfo.RequestDetails));
        }
Esempio n. 2
0
        /// <summary>
        /// Start
        /// </summary>
        public int Start(IList <Testcase> testcases, HttpRequest request)
        {
            Setup(testcases, request);

            TestcaseExecutorTaskInfo taskInfo     = new TestcaseExecutorTaskInfo(_testcases, new BrowserQueueCreated(QueueCreated), _requestDetails);
            WaitCallback             methodTarget = new WaitCallback(RunTestsInternal);
            bool isQueued = ThreadPool.QueueUserWorkItem(methodTarget, taskInfo);

            while (_threadId == -1)
            {
                Thread.Sleep(200);
            }

            return(_threadId);
        }