Example #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);
        }
Example #2
0
        private bool ExecuteStep(DataRow dr, RemoteWebDriver driver)
        {
            string guimapName        = string.Empty;
            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());

            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();

                _projectPageId = Convert.ToInt32(adapterTest.GetProjectPageID(Convert.ToInt32(guiTestId)));
                //_projectId = Convert.ToInt32(adapterGuiproject.GetProjectID(_projectPageId));
                string inputTableValueDescription = string.Empty;
                if ((dr["InputDataRow"].ToString().Trim() != string.Empty) &&
                    (dr["InputDataRow"].ToString().IndexOf('-') < 0) && (dr["InputDataRow"].ToString().IndexOf(',') < 0))
                {
                    string 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 = " with DataInput=" + inputTableValue + "in DataRow=" + inputDataRow;
                    if (inputTableValue.IndexOf(Constants.RegularExpressionOutput, 0, StringComparison.Ordinal) >= 0)
                    {
                        inputTableValue = sl.GetLastCreatrdValue(inputDataColumn);
                    }
                }


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


                result = sl.ExecuteOneStep(dr, inputDataColumn, inputTableValue, driver);

                adapterTest.GetTestName(guiTestId);
                if (guiMapId != 0)
                {
                    guimapName = adapterGuimap.GetGuiMapName(guiMapId).Trim();
                }
                if (guiMapCommandId != 0)
                {
                    guiMapCommandName = adapterCommand.GetTestCommandName(guiMapCommandId).Trim();
                }
                string description;
                int    status;
                string ss = string.Empty;

                if (result)
                {
                    description = string.Format("{0}={1}", Constants.LogStepStatus, "Passed");
                    status      = Constants.Passed;
                }
                //LogResult(_runExecutionId, _batchId, _flowId, guiTestId, guiMapId,"Step Passed: " + guiMapCommandName + " => " + guimapName + inputTableValueDescription,Constants.Passed, "0", _projectId, _projectPageId);
                else
                {
                    //ss = sl.ScreenShot(driver, Directory.GetCurrentDirectory() + "\\Logs");
                    ss = sl.ScreenShot(driver, "\\\\" + Environment.MachineName + "\\Logs");
                    string     pagesource = sl.SourcePage(driver);
                    TextParser tp         = new TextParser();
                    //get iis server
                    string iisServer = tp.GetIis(pagesource);
                    description = string.Format("{0}={1}\t{2}={3}\t{4}={5}\t{6}", Constants.LogStepStatus, "Failed",
                                                "SnapShot", ss, "IISServer", iisServer, sl.LastFailureMessage);
                    status = Constants.Failed;

                    //LogResult(_runExecutionId, _batchId, _flowId, guiTestId, guiMapId,"Step Failed: " + guiMapCommandName + " => " + guimapName + inputTableValueDescription +"\n" + sl.LastFailureMessage + "\n" + ss, Constants.Failed, "0", _projectId,_projectPageId);
                }
                LogResult(_runExecutionId, _batchId, _flowId, guiTestId, guiMapId, guiMapCommandName + " " + description + inputTableValueDescription, status, "0", _projectId, _projectPageId);
            }

            catch (Exception exception)
            {
                Logger.Error(exception.Message, exception);
                result = false;
            }


            return(result);
        }