Beispiel #1
0
        public void GetGuiMap()
        {
            var guiMapAdapter = new GuiMapTableAdapter();
            var guimapname    = guiMapAdapter.GetGuiMapName(1).Trim();

            Assert.AreEqual("OB_SignIn", guimapname);
        }
Beispiel #2
0
        private void SilenceCreateNewElement(int pageSectionID, string ElementName)
        {
            Boolean flag          = true;
            var     sql           = new Sql();
            var     dataset       = new DataSetAutoTest();
            var     adapterGuimap = new GuiMapTableAdapter();

            if (pageSectionID > 0)
            {
                adapterGuimap.Fill(dataset.GuiMap);
                DataTableReader dtElementReader = dataset.GuiMap.CreateDataReader();

                while (dtElementReader.Read())
                {
                    //GuiMapID 0
                    var col1 = dtElementReader.GetValue(1).ToString().Trim();                  //GuiMapObjectName
                    var col2 = dtElementReader.GetValue(2).ToString().Trim();                  //TagTypeID === 2
                    var col3 = dtElementReader.GetValue(3).ToString().Trim();                  //TagTypeValue
                    var col4 = Convert.ToInt32(dtElementReader.GetValue(4).ToString().Trim()); //GuiProjectID == PageSection

                    if (col4 == pageSectionID && col3 == ElementName)
                    {
                        flag = false;
                        break;
                    }
                }
                if (flag)
                {
                    string guiMapObjectName = _pprefix + ElementName;
                    adapterGuimap.Insert(guiMapObjectName, 2, ElementName, pageSectionID);
                    string GuiMapId = adapterGuimap.GetLastGuiMapId().ToString();
                    sql.UpdateVersion("GuiMap", "GuiMapID", GuiMapId, this._VersionName, 1);
                }
            }
        }
Beispiel #3
0
        private void sleep(int guiMapId)
        {
            var guimapadapter = new GuiMapTableAdapter();
            int sleeptime     = Convert.ToInt32(guimapadapter.GetTagTypeValue(guiMapId));

            Thread.Sleep(sleeptime * 1000);
        }
Beispiel #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);
        }
Beispiel #5
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);
        }
Beispiel #6
0
        internal int LogResult(int runExecutionId, int batchId, int scenarioId, int testId, int stepId,
                               string description, int status, string outOfFlow, int projectId, int projectPageId)
        {
            try
            {
                int      result;
                string   batchName       = string.Empty;
                string   scenarioName    = string.Empty;
                string   testName        = string.Empty;
                string   stepName        = string.Empty;
                string   projectName     = string.Empty;
                string   projectPageName = string.Empty;
                DateTime occurred        = DateTime.Now.ToUniversalTime();
                using (var adapterLogresult = new TestResultsTableAdapter())
                {
                    result = adapterLogresult.Insert(runExecutionId, batchId, scenarioId, testId, stepId, description,
                                                     status, outOfFlow, projectId, projectPageId, occurred);
                }

                using (var adapterBatch = new BatchesTableAdapter())
                {
                    if (batchId != 0)
                    {
                        batchName = adapterBatch.GetBatchName(batchId);
                    }
                    else
                    {
                        batchName = Constants.LogNothing;
                    }
                }

                using (var adapterScenario = new ScenarioTableAdapter())
                {
                    if (scenarioId != 0)
                    {
                        scenarioName = adapterScenario.GetScenarioName(scenarioId);
                    }
                    else
                    {
                        scenarioName = Constants.LogNothing;
                    }
                }

                using (var adapterTest = new TestTableAdapter())
                {
                    if (testId != 0)
                    {
                        testName = adapterTest.GetTestName(testId);
                    }
                    else
                    {
                        testName = Constants.LogNothing;
                    }
                }

                using (var adapterGuiMap = new GuiMapTableAdapter())
                {
                    if (stepId != 0)
                    {
                        stepName = adapterGuiMap.GetGuiMapName(stepId).Trim();
                    }
                    else
                    {
                        stepName = Constants.LogNothing;
                    }
                }

                using (var adapterProject = new ProjectsTableAdapter())
                {
                    if (projectId != 0)
                    {
                        projectName = adapterProject.GetProjectName(projectId);
                    }
                    else
                    {
                        projectName = Constants.LogNothing;
                    }
                }

                using (var adapterProjectPage = new GuiProjectPageTableAdapter())
                {
                    if (projectPageId != 0)
                    {
                        projectPageName = adapterProjectPage.GetProjectPageName(projectPageId);
                    }
                    else
                    {
                        projectPageName = Constants.LogNothing;
                    }
                }


                string logString = String.Format("{0}={1}\t{2}={3}\t{4}={5}\t{6}={7}\t{8}={9}\t{10}=( {11} )\t{12}={13}\t{14}={15}",
                                                 Constants.LogExecutionId, runExecutionId,
                                                 Constants.LogBatchName, batchName,
                                                 Constants.LogScenarioName, scenarioName,
                                                 Constants.LogTestName, testName,
                                                 Constants.LogStepName, stepName,
                                                 Constants.LogDescription, description,
                                                 Constants.LogProjectName, projectName,
                                                 Constants.LogProjectPageName, projectPageName);
                if (status == Constants.Passed)
                {
                    Logger.Passed(logString);
                }
                if (status == Constants.Done)
                {
                    Logger.Done(logString);
                }
                if (status == Constants.Failed)
                {
                    Logger.Failed(logString);
                }

                return(result);
            }
            catch (Exception exception)
            {
                Logger.Error(exception.Message, exception);
                return(0);
            }
        }
Beispiel #7
0
        internal List <OpenBookPositionData> GetOpenBookPositionData(RemoteWebDriver driver, int tableRowweguiMapId)
        {
            try
            {
                var          sl                       = new Selenium();
                TestFlowInfo tfi                      = new TestFlowInfo(true, "OpenBookValidator");
                var          dataAccess               = new DataAccessor(true, ref tfi);
                var          guimapadapter            = new GuiMapTableAdapter();
                string       userNameElementValue     = guimapadapter.GetTagTypeValue(Constants.ObOpenTradesUserName);
                string       userName                 = driver.FindElement((By)sl.GetWebElement(1, userNameElementValue, string.Empty)).Text;
                string       userTableRowElementValue = guimapadapter.GetTagTypeValue(tableRowweguiMapId);
                ReadOnlyCollection <IWebElement> rows =
                    driver.FindElements((By)sl.GetWebElement(1, userTableRowElementValue, string.Empty));
                var openbookpositiondata = new List <OpenBookPositionData>();
                foreach (IWebElement row in rows)
                {
                    StockStatus?stockStatus = StockStatus.Position;
                    string      parentUserNameElementValue =
                        guimapadapter.GetTagTypeValue(Constants.ObOpenTardesParentNameGuiMapId);
                    string parentUserName =
                        row.FindElement((By)sl.GetWebElement(1, parentUserNameElementValue, string.Empty)).Text;
                    string initRateStringElementValue =
                        guimapadapter.GetTagTypeValue(Constants.ObOpenTardesInitRateStringGuimapid);
                    string initRateString =
                        row.FindElement((By)sl.GetWebElement(1, initRateStringElementValue, string.Empty)).Text;
                    decimal initRate;

                    if (initRateString != string.Empty)
                    {
                        String trimmedRate = sl.GetCleanRate(initRateString);
                        initRate = Convert.ToDecimal(trimmedRate);
                    }
                    else
                    {
                        initRate = 0;
                    }
                    string instrumentDisplayNameElementValue =
                        guimapadapter.GetTagTypeValue(Constants.ObOpenTradedInstrumentDisplayName);
                    string instrumentDisplayName =
                        row.FindElement((By)sl.GetWebElement(1, instrumentDisplayNameElementValue, string.Empty))
                        .Text.Replace("/", "");
                    string isBuyStringElementValue = guimapadapter.GetTagTypeValue(Constants.ObOpenTradesIsBuyString);
                    string isBuyString             =
                        row.FindElement((By)sl.GetWebElement(1, isBuyStringElementValue, string.Empty)).Text;
                    bool isBuy;
                    if (String.Compare(isBuyString, "BUY", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        isBuy = true;
                    }
                    else
                    {
                        isBuy = false;
                    }
                    string isOverWeekendNameElementValue =
                        guimapadapter.GetTagTypeValue(Constants.ObOpenTradesIsOverWeekendNonStocks);
                    bool isOverWeekend = sl.CheckIfElementFind(row,
                                                               (By)sl.GetWebElement(1, isOverWeekendNameElementValue, string.Empty),
                                                               driver);
                    if (isOverWeekend == false)
                    {
                        //non stocks
                        isOverWeekendNameElementValue =
                            guimapadapter.GetTagTypeValue(Constants.ObOpenTradesIsOverWeekendStocks);
                        isOverWeekend = sl.CheckIfElementFind(row, (By)sl.GetWebElement(1, isOverWeekendNameElementValue, string.Empty), driver);
                    }

                    decimal limitRate;
                    string  limitRateElementValue = guimapadapter.GetTagTypeValue(Constants.ObOpenTradesLimitRate);
                    if (sl.CheckIfElementFind(row, (By)sl.GetWebElement(1, limitRateElementValue, string.Empty), driver))
                    {
                        string limitRateString =
                            row.FindElement((By)sl.GetWebElement(1, limitRateElementValue, string.Empty)).Text;
                        Char[] limitRatearr =
                            limitRateString.ToCharArray().Where(c => Char.IsDigit(c) || Char.IsPunctuation(c)).ToArray();
                        limitRate = Convert.ToDecimal(new string(limitRatearr));

                        stockStatus = new StockStatus(); //non stock
                    }
                    else
                    {
                        limitRate = 999999.9m;
                    }
                    decimal stopRate;
                    string  stopRateElementValue = guimapadapter.GetTagTypeValue(Constants.ObOpenTradeStopRate);
                    if (sl.CheckIfElementFind(row, (By)sl.GetWebElement(1, stopRateElementValue, string.Empty),
                                              driver))
                    {
                        string stopRateString =
                            row.FindElement((By)sl.GetWebElement(1, stopRateElementValue, string.Empty)).Text;
                        Char[] stopRatearr =
                            stopRateString.ToCharArray().Where(c => Char.IsDigit(c) || Char.IsPunctuation(c)).ToArray();
                        stopRate = Convert.ToDecimal(new string(stopRatearr));
                    }
                    else
                    {
                        stopRate = 0;
                    }


                    string instrumentElementValue = guimapadapter.GetTagTypeValue(Constants.ObOpenTradesInstrument);
                    int    positionId             =
                        Convert.ToInt32(
                            row.FindElement((By)sl.GetWebElement(1, instrumentElementValue, string.Empty))
                            .GetAttribute("positionid"));

                    string infoRowPendingElementValue =
                        guimapadapter.GetTagTypeValue(Constants.ObOpenTaredsInfoRowPending);
                    bool isInfoRowPending = sl.CheckIfElementFind(row,
                                                                  (By)
                                                                  sl.GetWebElement(1, infoRowPendingElementValue, string.Empty),
                                                                  driver);
                    if (isInfoRowPending)
                    {
                        stockStatus = StockStatus.Order;
                    }

                    try
                    {
                        openbookpositiondata.Add(new OpenBookPositionData(userName, parentUserName, initRate, instrumentDisplayName, isBuy, isOverWeekend, limitRate, stopRate, positionId, stockStatus));
                    }
                    catch (Exception e)
                    {
                        Logger.Error("Can't Add + " + instrumentDisplayName + " to openbook position data" + e.Message);
                    }
                }
                return(openbookpositiondata);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Beispiel #8
0
        /// <summary>
        ///     Execute one step generaly called from execution manger (gets vlaue from data table )
        /// </summary>
        public bool ExecuteOneStep(DataRow dr, string inputDataColumn, string inputTableValue, IWebDriver driver)
        {
            int    guiMapCommandId    = -1;
            string guiMapTagTypeValue = string.Empty;
            var    jp         = new JsonParser();
            By     webelement = By.XPath("null");

            bool result = true;
            int  waitElementDisplayed    = Convert.ToInt32(jp.ReadJson("WaitElementDisplayed"));
            int  waitElementExists       = Convert.ToInt32(jp.ReadJson("WaitElementExists"));
            int  expandedWaitFindElement = Convert.ToInt32(jp.ReadJson("ExpandedWaitFindElement"));
            int  delayBetweenCommands    = Convert.ToInt32(jp.ReadJson("DelayBetweenCommands"));

            if (inputTableValue.IndexOf(Constants.RegularExpressionTestingEnvironment, 0, StringComparison.Ordinal) >= 0)
            {
                inputTableValue = inputTableValue.Replace(Constants.RegularExpressionTestingEnvironment, jp.ReadJson("TestingEnvironment"));
            }

            try
            {
                int guiMapId;
                using (var adapterGuimap = new GuiMapTableAdapter())
                {
                    guiMapId        = Convert.ToInt32(dr["GuiMapID"].ToString().Trim());
                    guiMapCommandId = Convert.ToInt32(dr["GuiMapCommandID"].ToString().Trim());
                    int guiMapTagTypeId = Convert.ToInt32(adapterGuimap.GetTagTypeID(guiMapId));
                    if (guiMapId != 0)
                    {
                        guiMapTagTypeValue = adapterGuimap.GetTagTypeValue(guiMapId).Trim();
                        webelement         = (By)GetWebElement(guiMapTagTypeId, guiMapTagTypeValue, inputTableValue);
                    }
                }
                if (webelement != null)
                {
                    Thread.Sleep(delayBetweenCommands);

                    switch (guiMapCommandId)
                    {
                    case 1:     //"click":
                        // clickTheLinkAndFocusOnANewWindow(_driver,webelement);
                        driver.FindElement(webelement).Click();
                        Logger.Done(webelement + " clicked");
                        break;

                    case 2:     //"sendkey":
                        driver.FindElement(webelement).Clear();
                        driver.FindElement(webelement).SendKeys(inputTableValue);
                        Logger.Done(webelement + " Sentkey with " + inputTableValue);

                        break;

                    case 3:     //navigate
                        driver.Navigate().GoToUrl(inputTableValue);
                        Logger.Done("navigated to " + inputTableValue);
                        break;

                    case 4:     //findelementt
                        driver.FindElement(webelement);
                        Logger.Done(webelement + " Found");

                        break;

                    case 6:     //"check":
                        driver.FindElement(webelement).Click();
                        break;

                    case 7:     //"mouseover":
                        var builder = new Actions(driver);

                        builder.MoveToElement(driver.FindElement(webelement)).Build().Perform();

                        Thread.Sleep(1000);
                        Logger.Done(webelement + " Mouse Overed");

                        break;

                    case 8:     //"waituntill-findelement":
                        result = Waituntilfindelement(webelement, waitElementExists, driver);
                        Logger.Done(webelement.ToString().Trim() + " waited");
                        break;

                    case 9:     //"compare text
                        if (String.CompareOrdinal(driver.FindElement(webelement).Text, inputTableValue) != 0)
                        {
                            result = false;
                            LocalLogFailure(
                                "The Expected text is wrong actual: " + driver.FindElement(webelement).Text +
                                " vs expected :" + inputTableValue, null, Constants.Failed);
                        }

                        Logger.Done(webelement + " compared text to " + inputTableValue);
                        break;

                    case 10:     //select drop down by Index
                        // select the drop down list////System.Windows.MessageBox
                        IWebElement dropdown = driver.FindElement(webelement);
                        //create select element object
                        var selectElement = new SelectElement(dropdown);
                        //select by index
                        selectElement.SelectByIndex(Convert.ToInt32(inputTableValue));

                        ExecuteJavaScript(
                            "$('" + guiMapTagTypeValue + "').val('" + inputTableValue + "').change()", driver);

                        Logger.Done(webelement + " dropeddown with index   " + inputTableValue);
                        break;

                    case 11:     //wait untill  displayed

                        WaituntilelementDisplayed(webelement, waitElementDisplayed, driver, false);
                        break;

                    case 12:     //verify is exists

                        IWait <IWebDriver> wait = new WebDriverWait(driver, TimeSpan.FromSeconds(waitElementExists));
                        //IWebElement a = ExpectedConditions.ElementExists(webelement);
                        wait.Until(ExpectedConditions.ElementExists(webelement));

                        break;

                    case 13:     //select drop down
                        // select the drop down list////System.Windows.MessageBox
                        dropdown = driver.FindElement(webelement);
                        if (dropdown.Displayed)
                        {
                            //create select element object
                            selectElement = new SelectElement(dropdown);
                            selectElement.SelectByText(inputTableValue);
                            // select by text
                            //selectElement.SelecyByText("HighSchool");
                        }
                        ExecuteJavaScript(
                            "$('" + guiMapTagTypeValue + " option:selected').val('" + inputTableValue +
                            "').change()", driver);
                        Logger.Done(webelement + " dropeddown with text   " + inputTableValue);
                        break;

                    case 14:     //select drop down
                        // select the drop down list////System.Windows.MessageBox
                        dropdown = driver.FindElement(webelement);
                        if (dropdown.Displayed)
                        {
                            //create select element object
                            selectElement = new SelectElement(dropdown);
                            //select by Value
                            selectElement.SelectByValue(inputTableValue);
                        }
                        ExecuteJavaScript(
                            "$('" + guiMapTagTypeValue + "').val('" + inputTableValue + "').change()", driver);
                        Logger.Done(webelement + " dropeddown with value   " + inputTableValue);
                        break;

                    case 15:     //SetlocalStorage Run JavaScript(any java script)
                        // select the drop down list////System.Windows.MessageBox

                        ExecuteJavaScript(inputTableValue, driver);
                        Logger.Done("Java script executed with   " + inputTableValue);
                        break;

                    case 16:     //wait untill  find element long time expanded
                        WaituntilelementDisplayed(webelement, expandedWaitFindElement, driver, false);
                        break;

                    case 17:     //Count number of elements and Compare
                        int elementcount = driver.FindElements(webelement).Count();
                        if (elementcount != Convert.ToInt32(inputTableValue))
                        {
                            result = false;
                            LocalLogFailure(
                                "The Expected count is wrong:" + inputTableValue + " vs actual: " + elementcount,
                                null, Constants.Failed);
                        }

                        Logger.Done("number of elements " + webelement + "is " + elementcount + "compared to:   " +
                                    inputTableValue);
                        break;

                    case 18:     //scrolldown
                        ExecuteJavaScript("window.scroll(0,document.body.scrollHeight)", driver);
                        Logger.Done("Scrolled Down");

                        break;

                    case 19:     //scrollup
                        ExecuteJavaScript("window.scroll(0,0)", driver);
                        Logger.Done("Scrolled Up");
                        break;

                    case 20:     //switchtowindow
                        SwitchTowindow(driver, inputTableValue);
                        break;

                    case 21:     //validateOpenTrades

                        break;

                    case 22:     //case close current window
                        driver.Close();
                        break;

                    case 23:     //close  window by name
                        string currentwindowhandle = driver.CurrentWindowHandle;
                        SwitchTowindow(driver, inputTableValue);
                        driver.Close();
                        //back to current window
                        driver.SwitchTo().Window(currentwindowhandle);
                        break;

                    case 24:     //clear cookeis

                        driver.Manage().Cookies.DeleteAllCookies();
                        // driver.Navigate().Refresh();

                        break;

                    case 25:     //wait untill  find element with refresh
                        WaituntilelementDisplayed(webelement, waitElementDisplayed, driver, true);
                        break;

                    case 26:     //create new user

                        break;

                    case 27:     //create commenter badge

                        break;

                    case 28:    //refresh page
                        driver.Navigate().Refresh();
                        break;

                    case 29:    //runexe
                        string  automaticHedgerPath = jp.ReadJson("ExePath");
                        Process newProcess          = Process.Start(automaticHedgerPath);
                        Thread.Sleep(10000);
                        if (newProcess != null)
                        {
                            newProcess.Kill();
                        }

                        break;

                    case 30:    //sleep
                        sleep(guiMapId);
                        break;


                    case 31:    //ComapreDB to... savedText or value
                        // connect string + query split
                        var      guimapadapter        = new GuiMapTableAdapter();
                        string   ConString_Query      = guimapadapter.GetTagTypeValue(guiMapId);
                        string[] ConString_QuerySplit = ConString_Query.Split('!');

                        var    sql      = new Sql();
                        string DBResult = sql.GetDBSingleValue(ConString_QuerySplit[0], ConString_QuerySplit[1]);
                        if (String.CompareOrdinal(DBResult, inputTableValue) != 0)
                        {
                            result = false;
                            LocalLogFailure(
                                "The Expected text is wrong actual: " + DBResult +
                                " vs expected :" + inputTableValue, null, Constants.Failed);
                        }

                        Logger.Done(ConString_QuerySplit[1] + " compared text to " + inputTableValue);
                        break;

                    case 32:    //SaveElementText
                        SetLastCreatedValue(inputDataColumn, driver.FindElement(webelement).Text);

                        break;

                    case 33:    //Accept Alert
                        driver.SwitchTo().Alert().Accept();


                        break;

                    case 34:    //Accept Dissmiss
                        driver.SwitchTo().Alert().Dismiss();

                        break;

                    case 35:    //SaveElementText to memmory
                        SetLastCreatedValue("memmory", driver.FindElement(webelement).Text);

                        break;

                    case 36:    //ComapreDB to... savedText or value in memmory
                        // connect string + query split
                        var    guimapadapter36   = new GuiMapTableAdapter();
                        string ConString_Query36 = guimapadapter36.GetTagTypeValue(guiMapId);
                        ConString_Query36 = GetDBElement(ConString_Query36, inputTableValue);
                        string[] ConString_QuerySplit36 = ConString_Query36.Split('!');

                        var    sql36      = new Sql();
                        string DBResult36 = sql36.GetDBSingleValue(ConString_QuerySplit36[0], ConString_QuerySplit36[1]);
                        if (String.CompareOrdinal(DBResult36, GetLastCreatrdValue("memmory")) != 0)
                        {
                            result = false;
                            LocalLogFailure(
                                "The Expected text is wrong actual: " + DBResult36 +
                                " vs expected :" + GetLastCreatrdValue("memmory"), null, Constants.Failed);
                        }

                        Logger.Done(ConString_QuerySplit36[1] + " compared text to " + inputTableValue);
                        break;

                    default:
                        LocalLogFailure("Can't run this command:" + guiMapTagTypeValue.Trim(), null,
                                        Constants.Failed);
                        break;
                    }
                }
                else
                {
                    result = false;
                    LocalLogFailure(guiMapCommandId + ": web element was not found : " + guiMapTagTypeValue.Trim(), null,
                                    Constants.Failed);
                }
            }


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


            if (result)
            {
                Logger.Passed(guiMapCommandId + ": TestStep : " + guiMapTagTypeValue.Trim());
            }
            else
            {
                Logger.Failed(guiMapCommandId + ": TestStep : " + guiMapTagTypeValue.Trim());
            }
            return(result);
        }
Beispiel #9
0
        private bool ExecuteStep(DataRow dr, IWebDriver 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 data input: " + inputTableValue + "in row : " + 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, 16);
                    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();
                }


                if (result)
                {
                    LogResult(_runExecutionId, _batchId, _flowId, guiTestId, guiMapId,
                              "Step Passed: " + guiMapCommandName + " => " + guimapName + inputTableValueDescription,
                              Constants.Passed, "0", _projectId, _projectPageId);
                }
                else
                {
                    string ss = sl.ScreenShot(driver, Directory.GetCurrentDirectory() + "\\Logs");
                    LogResult(_runExecutionId, _batchId, _flowId, guiTestId, guiMapId,
                              "Step Failed: " + guiMapCommandName + " => " + guimapName + inputTableValueDescription +
                              "\n" + sl.LastFailureMessage + "\n" + ss, Constants.Failed, "0", _projectId,
                              _projectPageId);
                }
            }

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


            return(result);
        }