Example #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);
        }
Example #2
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);
        }