Beispiel #1
0
        private bool SetAllScenariusStatusToRunorNot(DataTable dtScenario, int status)
        {
            var adapterBatchLogic = new BatchLogicTableAdapter();

            foreach (DataRow row in dtScenario.Rows)
            {
                adapterBatchLogic.Update(Convert.ToInt32(row["BatchID"]), Convert.ToInt32(row["ScenarioID"]),
                                         Convert.ToInt32(row["BrowserID"]), status, Convert.ToInt32(row["StepsOrder"]),
                                         Convert.ToInt32(row["BatchLogicID"]));
            }
            return(true);
        }
Beispiel #2
0
        /// <summary>
        /// Unitest will cal this one
        /// </summary>
        /// <param name="batchId"></param>
        /// <returns></returns>
        public bool ExecuteOneBatch(string batchId)
        {
            try
            {
                var jp = new JsonParser();
                //VSH: clean global configuration before ExecuteOneBatch
                Boolean res = jp.AddConfigToMemory("");

                string remote = Constants.MemoryConf["RemoteNode"];
                int    timeoutAllScenarios = Convert.ToInt32(Constants.MemoryConf["TimeoutAllScenarios"]) * 1000;
                var    sel = new Selenium();
                if (batchId == string.Empty)
                {
                    MessageBox.Show("Select Batch first", "Applenium");
                    return(false);
                }
                var sql = new Sql();
                _batchId = Convert.ToInt32(batchId);
                DataTable dtScenario = sql.GetDataTable(Constants.StrBatchScenariosToSelenium,
                                                        _batchId.ToString(CultureInfo.InvariantCulture));
                //SetAllScenariusStatusToRunorNot(dtScenario, Constants.Pending);
                var adapterBatches    = new BatchesTableAdapter();
                var adapterBatchLogic = new BatchLogicTableAdapter();
                var adapterBrowser    = new BrowsersTableAdapter();
                _batchname = adapterBatches.GetBatchName(_batchId);
                var adapterScenario = new ScenarioTableAdapter();

                _projectId = Convert.ToInt32(adapterBatches.GetProjectID(Convert.ToInt32(_batchId)));


                LogObject logObject = new LogObject();
                logObject.ExecutionID   = _runExecutionId;
                logObject.BatchID       = _batchId;
                logObject.Description   = Constants.LogBatchStatus + "=" + Constants.PROGRESS_STARTED;
                logObject.BatchName     = _batchname;
                logObject.BatchProgress = Constants.PROGRESS_STARTED;
                logObject.StatusTag     = Constants.DONE;
                logObject.ProjectID     = _projectId;

                logger.Print(logObject);

                Singleton myInstance = Singleton.Instance;
                myInstance.BatchResult = true;
                var threadFinishEvents = new List <EventWaitHandle>();
                foreach (DataRow row in dtScenario.Rows)
                {
                    if (myInstance.StopExecution)
                    {
                        myInstance.BatchResult = false;
                        break;
                    }
                    var threadFinish = new EventWaitHandle(false, EventResetMode.ManualReset);

                    string BrowserID       = row["BrowserID"].ToString();
                    string batchLogicId    = row["BatchLogicID"].ToString();
                    int    executionStatus = Convert.ToInt32(row["ExecutionStatusID"].ToString());

                    if (executionStatus == 1) //run only selected scenarios
                    {
                        threadFinishEvents.Add(threadFinish);
                        _browserName = adapterBrowser.GetBrowserName(Convert.ToInt32(BrowserID));



                        ThreadStart ts = delegate
                        {
                            //wait till hub return available browser

                            RemoteWebDriver driver = null;
                            driver = sel.SetWebDriverBrowser(null, BrowserID, false);
                            driver.Manage().Window.Maximize();



                            string scenarioId = row["ScenarioID"].ToString();

                            // adapterBatchLogic.Update(_batchId, Convert.ToInt32(scenarioId), Convert.ToInt32(browserId),Constants.Running, Convert.ToInt32(batchLogicId));

                            string scenarioname = adapterScenario.GetScenarioName(Convert.ToInt32(scenarioId));
                            if (guiInstance != null && isBatchRun == true)
                            {
                                guiInstance.UpdateProgressLabel("", "", Constants.UpdateProgress_REGULAR);
                            }

                            LogObject logObject2 = new LogObject();
                            logObject2.ExecutionID   = _runExecutionId;
                            logObject2.BatchID       = _batchId;
                            logObject2.ScenarioID    = Convert.ToInt32(scenarioId);
                            logObject2.ScnearioName  = scenarioname;
                            logObject2.Browser       = _browserName;
                            logObject2.ProjectID     = _projectId;
                            logObject2.ProjectName   = _projectName;
                            logObject2.BatchName     = _batchname;
                            logObject2.ProjectPageID = _projectPageId;
                            logObject2.StatusTag     = Constants.DONE;
                            logObject2.Browser       = _browserName;
                            logger.Print(logObject2);


                            // Do long work here
                            bool scanearioresult = ExecuteOneScenario(scenarioId, driver);

                            Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.Normal, (EventHandler)
                                                                delegate
                            {
                                if (scanearioresult == false)
                                {
                                    myInstance.BatchResult = false;
                                    //adapterBatchLogic.Update(_batchId,Convert.ToInt32(scenarioId),Convert.ToInt32(browserId),Constants.Failed,Convert.ToInt32(batchLogicId));
                                }


                                driver.Quit();
                                threadFinish.Set();
                            }, null, null);
                        };
                        try
                        {
                            ts.BeginInvoke(delegate(IAsyncResult aysncResult) { ts.EndInvoke(aysncResult); }, null);
                        }

                        catch (Exception exc)
                        {
                            MessageBox.Show("An exception has occoured when trying to execute a scenario - " + exc.TargetSite);
                        }
                        if (remote == "no")
                        {
                            WaitHandle.WaitAll(threadFinishEvents.ToArray(), Convert.ToInt32(timeoutAllScenarios));
                        }
                    }
                }

                WaitHandle.WaitAll(threadFinishEvents.ToArray(), Convert.ToInt32(timeoutAllScenarios));
                string description;
                int    status;
                string bStatus = Constants.PROGRESS_FAILED;

                if (myInstance.BatchResult)
                {
                    description = string.Format("{0}={1}", Constants.LogBatchName, "Passed");
                    status      = Constants.PASSED;
                    bStatus     = Constants.PROGRESS_PASSED;
                    //LogResult(_runExecutionId, Convert.ToInt32(_batchId), 0, 0, 0, batchname + " Batch Passed",Constants.Passed, "0", _projectId, 0);
                }

                else
                {
                    //LogResult(_runExecutionId, Convert.ToInt32(_batchId), 0, 0, 0, batchname + " Batch Failed",Constants.Failed, "0", _projectId, 0);
                    description = string.Format("{0}={1}", Constants.LogBatchStatus, "Failed");
                    status      = Constants.FAILED;
                    bStatus     = Constants.PROGRESS_FAILED;
                }

                LogObject logObject3 = new LogObject();
                logObject3.ExecutionID = _runExecutionId;
                logObject3.BatchID     = Convert.ToInt32(_batchId);
                logObject3.Description = description;
                logObject3.StatusTag   = status;
                logObject3.BatchStatus = bStatus;
                logObject3.ProjectID   = _projectId;
                logger.Print(logObject3);


                //SetAllScenariusStatusToRunorNot(dtScenario, Constants.NotRunnig);
                return(myInstance.BatchResult);
            }
            catch (Exception exception)
            {
                LogObject exceptionLog = new LogObject();
                exceptionLog.Description = exception.Message;
                exceptionLog.StatusTag   = Constants.ERROR;
                logger.Print(exceptionLog);

                return(false);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Unitest will cal this one
        /// </summary>
        /// <param name="batchId"></param>
        /// <returns></returns>
        public bool ExecuteOneBatch(string batchId)
        {
            try
            {
                var    jp     = new JsonParser();
                string remote = jp.ReadJson("RemoteNode");
                int    timeoutAllScenarios = Convert.ToInt32(jp.ReadJson("TimeoutAllScenarios")) * 1000;
                var    sel = new Selenium();
                if (batchId == string.Empty)
                {
                    MessageBox.Show("Select Batch first", "Applenium");
                    return(false);
                }
                var sql = new Sql();
                _batchId = Convert.ToInt32(batchId);
                DataTable dtScenario = sql.GetDataTable(Constants.StrBatchScenariosToSelenium,
                                                        _batchId.ToString(CultureInfo.InvariantCulture));
                //SetAllScenariusStatusToRunorNot(dtScenario, Constants.Pending);
                var    adapterBatches    = new BatchesTableAdapter();
                var    adapterBatchLogic = new BatchLogicTableAdapter();
                var    adapterBrowser    = new BrowsersTableAdapter();
                string batchname         = adapterBatches.GetBatchName(_batchId);
                var    adapterScenario   = new ScenarioTableAdapter();

                _projectId = Convert.ToInt32(adapterBatches.GetProjectID(Convert.ToInt32(_batchId)));

                LogResult(_runExecutionId, Convert.ToInt32(_batchId), 0, 0, 0, Constants.LogBatchStatus + "=Started",
                          Constants.Done,
                          "0", _projectId, 0);

                Singleton myInstance = Singleton.Instance;
                myInstance.BatchResult = true;
                var threadFinishEvents = new List <EventWaitHandle>();
                foreach (DataRow row in dtScenario.Rows)
                {
                    if (myInstance.StopExecution)
                    {
                        myInstance.BatchResult = false;
                        break;
                    }
                    var threadFinish = new EventWaitHandle(false, EventResetMode.ManualReset);

                    string browserId       = row["BrowserID"].ToString();
                    string batchLogicId    = row["BatchLogicID"].ToString();
                    int    executionStatus = Convert.ToInt32(row["ExecutionStatusID"].ToString());

                    if (executionStatus == 1) //run only selected scenarios
                    {
                        threadFinishEvents.Add(threadFinish);
                        string browserName = adapterBrowser.GetBrowserName(Convert.ToInt32(browserId));



                        ThreadStart ts = delegate
                        {
                            //wait till hub return available browser

                            RemoteWebDriver driver  = null;
                            int             elapsed = 0;
                            while ((driver == null) && (elapsed < timeoutAllScenarios))
                            {
                                //generate random number 30-60
                                Random r    = new Random();
                                int    rInt = r.Next(30000, 60000);  //for ints

                                Thread.Sleep(rInt);
                                driver   = sel.SetWebDriverBrowser(null, browserId, false);
                                elapsed += rInt;
                            }


                            string scenarioId = row["ScenarioID"].ToString();

                            // adapterBatchLogic.Update(_batchId, Convert.ToInt32(scenarioId), Convert.ToInt32(browserId),Constants.Running, Convert.ToInt32(batchLogicId));

                            string scenarioname = adapterScenario.GetScenarioName(Convert.ToInt32(scenarioId));
                            if (guiInstance != null && isBatchRun == true)
                            {
                                guiInstance.UpdateProgressLabel(scenarioname);
                            }
                            LogResult(_runExecutionId, Convert.ToInt32(_batchId), Convert.ToInt32(scenarioId), 0, 0,
                                      scenarioname + " ScenarioBrowser=" + browserName,
                                      Constants.Done,
                                      "0", _projectId, _projectPageId);

                            // Do long work here
                            bool scanearioresult = ExecuteOneScenario(scenarioId, driver);

                            Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.Normal, (EventHandler)
                                                                delegate
                            {
                                if (scanearioresult == false)
                                {
                                    myInstance.BatchResult = false;
                                    //adapterBatchLogic.Update(_batchId,Convert.ToInt32(scenarioId),Convert.ToInt32(browserId),Constants.Failed,Convert.ToInt32(batchLogicId));
                                }


                                driver.Quit();
                                threadFinish.Set();
                            }, null, null);
                        };

                        ts.BeginInvoke(delegate(IAsyncResult aysncResult) { ts.EndInvoke(aysncResult); }, null);
                        if (remote == "no")
                        {
                            WaitHandle.WaitAll(threadFinishEvents.ToArray(), Convert.ToInt32(timeoutAllScenarios));
                        }
                    }
                }

                WaitHandle.WaitAll(threadFinishEvents.ToArray(), Convert.ToInt32(timeoutAllScenarios));
                string description;
                int    status;

                if (myInstance.BatchResult)
                {
                    description = string.Format("{0}={1}", Constants.LogBatchName, "Passed");
                    status      = Constants.Passed;
                    //LogResult(_runExecutionId, Convert.ToInt32(_batchId), 0, 0, 0, batchname + " Batch Passed",Constants.Passed, "0", _projectId, 0);
                }

                else
                {
                    //LogResult(_runExecutionId, Convert.ToInt32(_batchId), 0, 0, 0, batchname + " Batch Failed",Constants.Failed, "0", _projectId, 0);
                    description = string.Format("{0}={1}", Constants.LogBatchStatus, "Failed");
                    status      = Constants.Failed;
                }
                LogResult(_runExecutionId, Convert.ToInt32(_batchId), 0, 0, 0, description, status, "0", _projectId, 0);

                //SetAllScenariusStatusToRunorNot(dtScenario, Constants.NotRunnig);
                return(myInstance.BatchResult);
            }
            catch (Exception exception)
            {
                Logger.Error(exception.Message, exception);
                return(false);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Unitest will cal this one
        /// </summary>
        /// <param name="batchId"></param>
        /// <returns></returns>
        public bool ExecuteOneBatch(string batchId)
        {
            var    jp     = new JsonParser();
            string remote = jp.ReadJson("RemoteNode");
            int    timeoutAllScenarios = Convert.ToInt32(jp.ReadJson("TimeoutAllScenarios")) * 1000;
            var    sel = new Selenium();

            if (batchId == string.Empty)
            {
                MessageBox.Show("Select Batch first", "Applenium");
                return(false);
            }
            var sql = new Sql();

            _batchId = Convert.ToInt32(batchId);
            DataTable dtScenario = sql.GetDataTable(Constants.StrBatchScenariosToSelenium,
                                                    _batchId.ToString(CultureInfo.InvariantCulture));

            SetAllScenariusStatusToRunorNot(dtScenario, Constants.Pending);
            var    adapterBatches    = new BatchesTableAdapter();
            var    adapterBatchLogic = new BatchLogicTableAdapter();
            var    adapterBrowser    = new BrowsersTableAdapter();
            string batchname         = adapterBatches.GetBatchName(_batchId);
            var    adapterScenario   = new ScenarioTableAdapter();

            _projectId = Convert.ToInt32(adapterBatches.GetProjectID(Convert.ToInt32(_batchId)));

            LogResult(_runExecutionId, Convert.ToInt32(_batchId), 0, 0, 0, batchname + " Batch Started", Constants.Done,
                      "0", _projectId, 0);

            Singleton myInstance = Singleton.Instance;

            myInstance.BatchResult = true;
            var threadFinishEvents = new List <EventWaitHandle>();

            foreach (DataRow row in dtScenario.Rows)
            {
                if (myInstance.StopExecution)
                {
                    myInstance.BatchResult = false;
                    break;
                }
                var threadFinish = new EventWaitHandle(false, EventResetMode.ManualReset);
                threadFinishEvents.Add(threadFinish);
                string browserId    = row["BrowserID"].ToString();
                string batchLogicId = row["BatchLogicID"].ToString();


                string      browserName = adapterBrowser.GetBrowserName(Convert.ToInt32(browserId));
                IWebDriver  driver      = null;
                ThreadStart ts          = delegate
                {
                    driver = sel.SetWebDriverBrowser(driver, browserId, false);
                    if (driver == null)
                    {
                        return;
                    }


                    string scenarioId = row["ScenarioID"].ToString();

                    adapterBatchLogic.Update(_batchId, Convert.ToInt32(scenarioId), Convert.ToInt32(browserId), Constants.Running, Convert.ToInt32(batchLogicId));

                    string scenarioname = adapterScenario.GetScenarioName(Convert.ToInt32(scenarioId));
                    LogResult(_runExecutionId, Convert.ToInt32(_batchId), 0, 0, 0,
                              scenarioname + " Scenario will run on " + browserName + " browser.", Constants.Done,
                              "0", _projectId, 0);


                    // Do long work here
                    bool scanearioresult = ExecuteOneScenario(scenarioId, driver);
                    Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.Normal, (EventHandler)
                                                        delegate
                    {
                        if (scanearioresult == false)
                        {
                            myInstance.BatchResult = false;
                            adapterBatchLogic.Update(_batchId, Convert.ToInt32(scenarioId),
                                                     Convert.ToInt32(browserId), Constants.Failed,
                                                     Convert.ToInt32(batchLogicId));
                        }
                        else
                        {
                            adapterBatchLogic.Update(_batchId, Convert.ToInt32(scenarioId), Convert.ToInt32(browserId), Constants.Passed, Convert.ToInt32(batchLogicId));
                        }
                        driver.Quit();
                        threadFinish.Set();
                    }, null, null);
                };

                ts.BeginInvoke(delegate(IAsyncResult aysncResult) { ts.EndInvoke(aysncResult); }, null);
                if (remote == "no")
                {
                    WaitHandle.WaitAll(threadFinishEvents.ToArray(), Convert.ToInt32(timeoutAllScenarios));
                }
            }

            WaitHandle.WaitAll(threadFinishEvents.ToArray(), Convert.ToInt32(timeoutAllScenarios));
            if (myInstance.BatchResult)
            {
                LogResult(_runExecutionId, Convert.ToInt32(_batchId), 0, 0, 0, batchname + " Batch Passed",
                          Constants.Passed, "0", _projectId, 0);
            }
            else
            {
                LogResult(_runExecutionId, Convert.ToInt32(_batchId), 0, 0, 0, batchname + " Batch Failed",
                          Constants.Failed, "0", _projectId, 0);
                //LogFailiure(_runExecutionID, 0, null, 0, null, "Description in the scenario");
            }

            SetAllScenariusStatusToRunorNot(dtScenario, Constants.NotRunnig);
            return(myInstance.BatchResult);
        }