Ejemplo n.º 1
0
        /// <summary>
        /// Facebook API Request
        /// </summary>
        /// <param name="appId"></param>
        /// <param name="appSecret"></param>
        /// <param name="installed"></param>
        /// <returns></returns>
        ///
        internal FacebookTestUserResultModel FacebookTestUserRequest(string appId, string appSecret, bool installed)
        {
            FacebookTestUserResultModel result = new FacebookTestUserResultModel();

            try
            {
                string url  = string.Format("https://graph.facebook.com/{0}/accounts/test-users", appId);
                var    data = new FacebookTestUser
                {
                    AppId     = appId,
                    AppSecret = appSecret,
                    Installed = installed
                };

                string postData = string.Format("installed={0}&access_token={1}|{2}", data.Installed, data.AppId, data.AppSecret);

                result = HttpRequestExtensions.TryPostJson <FacebookTestUserResultModel>(url, postData, 300000);
                if (result == null)
                {
                    result = HttpRequestExtensions.TryPostJson <FacebookTestUserResultModel>(url, postData, 300000);
                }
            }
            catch (Exception exception)
            {
                LogObject logException = new LogObject();
                logException.Description = exception.Message + "Failed to create Facebook user";
                logException.StatusTag   = Constants.ERROR;
                logException.Exception   = exception;
                logger.Print(logException);


                result = null;
            }
            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get Http request
        /// </summary>
        /// <param name="url"></param>
        /// <param name="timeOut"></param>
        /// <typeparam name="TResult"></typeparam>
        /// <returns></returns>
        public static TResult TryGetJson <TResult>(string url, int timeOut = 5000)
        {
            TResult result = default(TResult);

            try
            {
                //Log4NetLogger.Log(eLogLevel.Debug, string.Format("GetJson from url: {0}", url));
                var request = (HttpWebRequest)WebRequest.Create(url);
                request.Timeout = timeOut;
                using (var response = (HttpWebResponse)request.GetResponse())
                {
                    using (Stream reader = response.GetResponseStream())
                    {
                        if (reader == null)
                        {
                            return(result);
                        }
                        using (var sr = new StreamReader(reader, Encoding.UTF8))
                        {
                            string queryResult = sr.ReadToEnd();
                            //Log4NetLogger.Log(eLogLevel.Debug, string.Format("GetJson response: {0}", queryResult));
                            result = Serializer.Deserialize <TResult>(queryResult);
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                LogObject logException = new LogObject();
                logException.Description = exception.Message;
                logException.StatusTag   = Constants.ERROR;
                logException.Exception   = exception;
                logger.Print(logException);
            }
            return(result);
        }
Ejemplo n.º 3
0
        public DataTable GetDataTable(string tableName, string input)
        {
            var    dt            = new DataTable();
            string versionColumn = GetVersionColumn();

            bool isTable = true;

            try
            {
                using (var con = new SqlConnection(conString))
                {
                    string query = string.Empty;
                    switch (tableName)
                    {
                    case Constants.StrGuiMap:
                        query = _guiMap;
                        break;

                    case Constants.StrGuiMapEdit:
                        query = _guiMap;

                        break;

                    case Constants.StrPopUpNewTest:
                        query = _guiTest;
                        break;

                    case Constants.StrPopUpNewScenario:
                        query = _guiScenario;
                        break;

                    case Constants.StrPopUpNewBatch:
                        query = _guiBatch;
                        break;

                    case Constants.StrGuiTest:
                        query = _guiTest;
                        break;

                    case Constants.StrGuiTagType:
                        query = _guiTagType;
                        break;

                    case Constants.StrGuiScenario:
                        query = _guiScenario;
                        break;

                    case Constants.StrGuiBatch:
                        query = _guiBatch;
                        break;

                    case Constants.StrGuiTestSteps:
                        query = _guiTestSteps;
                        if (!string.IsNullOrEmpty(input))
                        {
                            query = query + " Where GuiTestID= '" + input + "'";
                        }
                        break;

                    case Constants.StrTestViewer:
                        query = _guiTestSteps;
                        if (!string.IsNullOrEmpty(input))
                        {
                            query = query + " where GuiTestID= '" + input + "'";
                        }
                        break;

                    case Constants.StrGuiScenarioLogic:
                        query = _guiScenarioLogic;
                        if (!string.IsNullOrEmpty(input))
                        {
                            query = query + " Where GuiScenarioID= '" + input + "'";
                        }
                        break;

                    case Constants.StrGuiBatchLogic:
                        query = _guiBatchLogic;
                        if (!string.IsNullOrEmpty(input))
                        {
                            query = query + " Where BatchID= '" + input + "'";
                        }
                        break;

                    case Constants.StrInputTable:
                    case Constants.StrInputScenarioTable:
                        query = _inputTable;
                        if (!string.IsNullOrEmpty(input))
                        {
                            string testInputTableName = GetInputDataTableName(input, true);
                            if (testInputTableName == string.Empty)
                            {
                                testInputTableName = GetTestName(input);
                            }
                            if (IsTableExists(testInputTableName, false))
                            {
                                query = "select * from QA_Autotest.Test." + testInputTableName;
                            }
                            else
                            {
                                isTable = false;
                            }
                        }
                        break;

                    case Constants.StrInputBatchTable:
                        query = _inputTable;
                        if (!string.IsNullOrEmpty(input))
                        {
                            string testInputTableName = GetInputDataTableName(input, true);
                            if (testInputTableName == string.Empty)
                            {
                                testInputTableName = GetTestName(input);
                            }
                            if (IsTableExists(testInputTableName, false))
                            {
                                query = "select * from QA_Autotest.Test." + testInputTableName;
                            }
                            else
                            {
                                isTable = false;
                            }
                        }
                        break;

                    case Constants.StrTables:
                        query = _tables;
                        break;

                    case Constants.StrColumns:
                        query = _columns + " where TABLE_NAME = '" + input + "'";
                        break;

                    case Constants.StrRowsId:

                        if (IsTableExists(input, false))
                        {
                            query = _rowsId + "QA_Autotest.Test." + input;
                        }
                        else
                        {
                            isTable = false;
                        }

                        break;

                    case Constants.StrGuiProjects:
                        query = _guiProject;
                        break;

                    case Constants.StrGuiProjectsNewTest:
                        query = _guiProject;
                        break;

                    case Constants.StrGuiProjectsNewScenario:
                        query = _guiProject;
                        break;

                    case Constants.StrGuiProjectsNewBatch:
                        query = _guiProject;
                        break;

                    case Constants.StrTestStepsToSelenium:
                        query = _testStepsToSlenium;
                        if (!string.IsNullOrEmpty(input))
                        {
                            query = query + " Where GuiTestID= '" + input + "' AND " + versionColumn + "  = 1 ORDER BY StepsOrder";
                        }
                        break;

                    case Constants.StrScenarioTestsToSelenium:
                        query = _scenarioTestsToSelenium;
                        if (!string.IsNullOrEmpty(input))
                        {
                            query = query + " Where GuiScenarioID= '" + input + "' ORDER BY StepsOrder";
                        }
                        break;

                    case Constants.StrBatchScenariosToSelenium:
                        query = _batchScenariosToSelenium;
                        if (!string.IsNullOrEmpty(input))
                        {
                            query = query + " Where BatchID= '" + input + "'";
                        }
                        break;

                    case Constants.StrLogResults:
                        query = _guiLogResults;
                        if (!string.IsNullOrEmpty(input))
                        {
                            query = query + " Where Test.TestResults.RunExecutionID= '" + input + "' ORDER BY Occured ";
                        }

                        break;

                    default:
                        //Logger.LogResult("Default case");
                        break;
                    }
                    string cmdString = query;
                    var    cmd       = new SqlCommand(cmdString, con);
                    var    sda       = new SqlDataAdapter(cmd);
                    if (isTable)
                    {
                        dt = new DataTable(tableName);
                        sda.Fill(dt);
                    }
                    else
                    {
                        dt = null;
                    }
                }
            }
            catch (Exception exception)
            {
                //Logger.LogResult(exception.Message, Constants.Debug, exception);

                LogObject log = new LogObject();
                log.Description = exception.Message;
                log.StatusTag   = Constants.DEBUG;
                log.Exception   = exception;

                logger.Print(log);
            }

            return(dt);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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);
            }
        }