示例#1
0
        private bool ExecuteStep(DataRow dr, RemoteWebDriver driver)
        {
            AppleniumLogger logger = new AppleniumLogger();


            string guiMapCommandName = string.Empty;
            bool   result;
            int    guiTestId       = Convert.ToInt32(dr["GuiTestID"].ToString().Trim());
            string inputTableValue = string.Empty;
            int    guiMapId        = Convert.ToInt32(dr["GuiMapID"].ToString().Trim());
            int    guiMapCommandId = Convert.ToInt32(dr["GuiMapCommandID"].ToString().Trim());
            string iisServer       = string.Empty;
            string inputDataRow    = string.Empty;

            try
            {
                var sql            = new Sql();
                var sl             = new Selenium();
                var adapterGuimap  = new GuiMapTableAdapter();
                var adapterTest    = new TestTableAdapter();
                var adapterCommand = new TestCommandTableAdapter();
                //var adapter_test_failurelog = new DataSetAutoTestTableAdapters.TestFailiureLogTableAdapter();
                string inputDataColumn = string.Empty;

                var adapterGuiproject = new GuiProjectPageTableAdapter();
                _projectSectionId = Convert.ToInt32(adapterTest.GetPageSectionID(Convert.ToInt32(guiTestId)));
                _projectPageId    = Convert.ToInt32(new GuiPageSectionTableAdapter().GetGuiPageID(_projectSectionId));
                _projectId        = Convert.ToInt32(adapterGuiproject.GetProjectID(_projectPageId));
                _projectName      = new ProjectsTableAdapter().GetProjectName(_projectId);


                string inputTableValueDescription = string.Empty;
                if ((dr["InputDataRow"].ToString().Trim() != string.Empty) &&
                    (dr["InputDataRow"].ToString().IndexOf('-') < 0) && (dr["InputDataRow"].ToString().IndexOf(',') < 0))
                {
                    inputDataRow    = dr["InputDataRow"].ToString().Trim();
                    inputDataColumn = dr["InputDataColumn"].ToString().Trim();
                    string inputTableName = sql.GetInputDataTableName(guiTestId.ToString(CultureInfo.InvariantCulture),
                                                                      returnTestNameIfNotExists: true);
                    inputTableValue = sql.InputDataValue(inputTableName, inputDataRow, inputDataColumn);

                    //inputTableValueDescription = "Used DataInput Parameters: " + inputTableValue + "\nFrom DataRow: " + inputDataRow + "\n\n";
                    if (inputTableValue.IndexOf(Constants.RegularExpressionOutput, 0, StringComparison.Ordinal) >= 0)
                    {
                        inputTableValue = sl.GetLastCreatedValue(inputDataColumn);
                    }
                }


                if (inputTableValue.IndexOf(Constants.RegularExpressionRandom, 0, StringComparison.Ordinal) >= 0)
                {
                    string rnd = Guid.NewGuid().ToString().Substring(2, 13);
                    inputTableValue = inputTableValue.Replace(Constants.RegularExpressionRandom, rnd);
                }

                var jp = new JsonParser();

                //result = sl.ExecuteOneStep(dr, inputDataColumn, inputTableValue, driver);
                ResultModel resultMod = sl.ExecuteOneStep(dr, inputDataColumn, inputTableValue, driver);
                result = resultMod.Returnresult;

                adapterTest.GetTestName(guiTestId);
                if (guiMapId != 0)
                {
                    _stepname = adapterGuimap.GetGuiMapName(guiMapId).Trim();
                }
                if (guiMapCommandId != 0)
                {
                    guiMapCommandName = adapterCommand.GetTestCommandName(guiMapCommandId).Trim();
                }

                LogObject logObject = new LogObject();
                if (resultMod.Returnresult)
                {
                    logObject.StepName    = _stepname;
                    logObject.CommandName = guiMapCommandName;
                    logObject.Description = "(" + resultMod.Message + ")." + " Completed successfully.";
                    logObject.StepStatus  = "Passed";
                    logObject.StatusTag   = Constants.PASSED;
                }

                else
                {
                    string filepath   = (LogManager.GetCurrentLoggers()[0].Logger.Repository.GetAppenders()[0] as FileAppender).File;
                    string folderpath = System.IO.Directory.GetParent(filepath).ToString();

                    // ss = sl.ScreenShot(driver, "\\\\" + Environment.MachineName + "\\Logs");
                    ss = sl.ScreenShot(driver, folderpath);
                    string     pagesource = sl.SourcePage(driver);
                    TextParser tp         = new TextParser();
                    //get iis server
                    iisServer = tp.GetIis(pagesource);

                    //string info = string.Format("\n{0}={1}\n{2}={3}\n{4}={5}\n{6}", Constants.LogStepStatus, "Failed",
                    //                                                          "SnapShot", ss, "IISServer", iisServer, sl.LastFailureMessage);

                    //jp.AddKeyToMemory(Constants.Memory, "CMD " + guiMapCommandName + ": FAIL");

                    logObject.Snapshot    = ss;
                    logObject.IISserver   = iisServer;
                    logObject.StepStatus  = "Failed";
                    logObject.StatusTag   = Constants.FAILED;
                    logObject.Description = "Couldn't complete execution of step. Reason - (" + guiMapCommandName + ", step=" + _stepname + ") " + resultMod.Message;
                }


                logObject.BatchID       = _batchId;
                logObject.ScenarioID    = _flowId;
                logObject.TestID        = guiTestId;
                logObject.StepID        = guiMapId;
                logObject.Parameter1    = "Used DataInput Parameters: " + inputTableValue;
                logObject.Parameter2    = "From DataRow: " + inputDataRow;
                logObject.CommandName   = guiMapCommandName;
                logObject.BatchName     = _batchname;
                logObject.ScnearioName  = _scenarioname;
                logObject.TestName      = _testname;
                logObject.ExecutionID   = _runExecutionId;
                logObject.StepName      = _stepname;
                logObject.ProjectPageID = _projectPageId;
                logObject.ProjectID     = _projectId;
                logObject.ProjectName   = _projectName;
                logObject.Browser       = _browserName;

                logger.Print(logObject);
            }

            catch (Exception exception)
            {
                LogObject logObject = new LogObject();
                logObject.Description = exception.Message;
                logObject.CommandName = guiMapCommandName;
                logObject.StatusTag   = Constants.ERROR;
                logObject.Exception   = exception;
                logger.Print(logObject);



                //AppleniumLogger.LogResult(guiMapCommandName,exception.Message, Constants.Error, exception);
                result = false;
            }


            return(result);
        }
示例#2
0
        internal bool ExecuteOneTest(string testId, string inputDataRow, RemoteWebDriver driver, ref Dictionary <string, int> testStatus)
        {
            try
            {
                if (testId == string.Empty)
                {
                    MessageBox.Show("Select test first", "Applenium");
                    return(false);
                }
                if (testStatus.ContainsKey("TotalTests"))
                {
                    testStatus["TotalTests"] = testStatus["TotalTests"] + 1;
                }
                else
                {
                    testStatus.Add("TotalTests", 1);
                }

                var       sql                  = new Sql();
                DataTable dt                   = sql.GetDataTable(Constants.StrTestStepsToSelenium, testId);
                bool      testresult           = true;
                bool      recursivetestresult  = true;
                var       adapterGuiproject    = new GuiProjectPageTableAdapter();
                var       adapterTest          = new TestTableAdapter();
                var       adapteGuiPageSection = new GuiPageSectionTableAdapter();
                _testname = adapterTest.GetTestName(Convert.ToInt32(testId));

                if (guiInstance != null)
                {
                    guiInstance.UpdateProgressLabel(_scenarioname, _testname, Constants.UpdateProgress_REGULAR);
                }


                LogObject logObject = new LogObject();



                logObject.Description = "*-------------------------------------------------------------------------------------------------------------\n" + "\t\t\t\t\t\t\t\t\t\t" + _testname + " Test Started\n-------------------------------------------------------------------------------------------------------------\n";
                logObject.StatusTag   = Constants.INFO;
                logger.Print(logObject);



                LogObject loggg = new LogObject();
                loggg.StepName     = _stepname;
                loggg.ExecutionID  = _runExecutionId;
                loggg.TestStatus   = Constants.PROGRESS_STARTED;
                loggg.TestName     = _testname;
                loggg.Description  = Constants.LogTestName + "=" + Constants.PROGRESS_STARTED;
                loggg.ScnearioName = _scenarioname;
                loggg.ProjectName  = _projectName;
                loggg.BatchName    = _batchname;
                loggg.Parameter1   = inputDataRow;
                loggg.StatusTag    = Constants.DONE;
                loggg.Exception    = null;
                logger.Print(loggg);



                var    jp = new JsonParser();
                string skipTestOnStepFail = Constants.MemoryConf["SkipTestOnStepFail"];


                Singleton myInstance = Singleton.Instance; // Will always be the same instance...

                if (inputDataRow != null)
                {
                    if (inputDataRow.IndexOf("rand", 0, StringComparison.Ordinal) >= 0)
                    {
                        if (inputDataRow.IndexOf("-", 0, StringComparison.Ordinal) >= 0)
                        {
                            string[] rows = inputDataRow.Split('-', '(', ')');
                            //get rundom number

                            Random random    = new Random();
                            int    rownumber = random.Next(Convert.ToInt32(rows[1]), Convert.ToInt32(rows[2]));

                            testresult = ExecuteOneTest(testId, rownumber.ToString(), driver,
                                                        ref testStatus);
                            if (testresult == false)
                            {
                                recursivetestresult = false;
                            }

                            return(recursivetestresult);
                        }
                    }

                    if (inputDataRow.IndexOf("-", 0, StringComparison.Ordinal) >= 0)
                    {
                        string[] rows = inputDataRow.Split('-');
                        for (int i = Convert.ToInt32(rows[0].ToString(CultureInfo.InvariantCulture));
                             i <= Convert.ToInt32(rows[1].ToString(CultureInfo.InvariantCulture));
                             i++)
                        {
                            testresult = ExecuteOneTest(testId, i.ToString(CultureInfo.InvariantCulture), driver, ref testStatus);
                            if (testresult == false)
                            {
                                recursivetestresult = false;
                            }
                        }
                        return(recursivetestresult);
                    }

                    if (inputDataRow.IndexOf(",", 0, StringComparison.Ordinal) >= 0)
                    {
                        string[] rows = inputDataRow.Split(',');
                        foreach (string key in rows)
                        {
                            testresult = ExecuteOneTest(testId, key, driver, ref testStatus);
                            if (testresult == false)
                            {
                                recursivetestresult = false;
                            }
                        }

                        return(recursivetestresult);
                    }
                    foreach (DataRow testrow in dt.Rows)
                    {
                        testrow["InputDataRow"] = inputDataRow;
                    }
                }
                foreach (DataRow row in dt.Rows)
                {
                    if (myInstance.StopExecution)
                    {
                        testresult = false;
                        break;
                    }
                    bool stepresult = ExecuteStep(row, driver);
                    if (stepresult == false)
                    {
                        testresult = false;
                        if (skipTestOnStepFail == "yes")
                        {
                            LogObject logObject2 = new LogObject();

                            logObject2.Description = "Previous Step is Failed => TestStatus=Skiped moving to next test";
                            logObject2.StatusTag   = Constants.ERROR;
                            logObject2.ExecutionID = _runExecutionId;
                            logObject2.Exception   = null;
                            logger.Print(logObject2);

                            break;
                        }
                    }
                }
                adapterTest.GetTestName(Convert.ToInt32(testId));
                int projectPageSectionId = Convert.ToInt32(adapterTest.GetPageSectionID(Convert.ToInt32(Convert.ToInt32(testId))));
                _projectPageId = Convert.ToInt32(adapteGuiPageSection.GetGuiPageID(projectPageSectionId));
                _projectId     = Convert.ToInt32(adapterGuiproject.GetProjectID(_projectPageId));

                LogObject logObject3 = new LogObject();
                if (testresult)
                {
                    //description = string.Format("{0}={1}", Constants.LogTestStatus, "Passed");
                    //status = Constants.Passed;


                    logObject3.TestStatus = Constants.PROGRESS_PASSED;
                    logObject3.StatusTag  = Constants.PASSED;


                    if (testStatus.ContainsKey("PassedTests"))
                    {
                        testStatus["PassedTests"] = testStatus["PassedTests"] + 1;
                    }
                    else
                    {
                        testStatus.Add("PassedTests", 1);
                    }
                }

                else
                {
                    logObject3.TestStatus  = Constants.PROGRESS_FAILED;
                    logObject3.Description = _testname + " has failed";
                    logObject3.StatusTag   = Constants.FAILED;



                    if (testStatus.ContainsKey("FailedTests"))
                    {
                        testStatus["FailedTests"] = testStatus["FailedTests"] + 1;
                    }
                    else
                    {
                        testStatus.Add("FailedTests", 1);
                    }
                }

                logObject3.Parameter1    = "";
                logObject3.Parameter2    = "";
                logObject3.Snapshot      = ss;
                logObject3.BatchID       = _batchId;
                logObject3.ScenarioID    = _flowId;
                logObject3.TestID        = Convert.ToInt32(testId);
                logObject3.TestName      = _testname;
                logObject3.ScnearioName  = _scenarioname;
                logObject3.BatchName     = _batchname;
                logObject3.StepID        = -1;
                logObject3.ExecutionID   = _runExecutionId;
                logObject3.ProjectPageID = _projectPageId;
                logObject3.ProjectName   = _projectName;
                logObject3.ProjectID     = _projectId;
                logger.Print(logObject3);


                //AppleniumLogger.LogResult(_runExecutionId, _batchId, _flowId, Convert.ToInt32(testId), 0, description + " with DataRow=" + inputDataRow, status, "0", _projectId, _projectPageId);
                return(testresult);
            }
            catch (Exception exception)
            {
                LogObject logObject4 = new LogObject();
                logObject4.Description = exception.Message;
                logObject4.CommandName = string.Empty;
                logObject4.StatusTag   = Constants.EXECPTION;
                logObject4.Exception   = exception;
                logger.Print(logObject4);

                //AppleniumLogger.LogResult(string.Empty,exception.Message, Constants.Error, exception);
                return(false);
            }
        }