コード例 #1
0
ファイル: Program.cs プロジェクト: sham165/krypton
        /// <summary>
        /// Key Press -> Send specified Key to window.
        /// </summary>
        /// <param name="popUpName">string : Name of popup to recover.</param>
        /// <param name="key"> string : Key to send.</param>
        private static void KeyPress(string popUpName, string key)
        {
            try
            {
                _objAutoit.WinActivate(popUpName, string.Empty); //Activate window.

                switch (key.ToLower())                           //Send Specified Key.
                {
                case "tab":
                    _objAutoit.Send("{TAB}");
                    break;

                case "space":
                    _objAutoit.Send("{SPACE}");
                    break;

                case "enter":
                    _objAutoit.Send("{ENTER}");
                    break;

                default:
                    _objAutoit.Send(key, 1);
                    break;
                }
            }
            catch (Exception e)
            {
                KryptonException.Writeexception(e.InnerException);
            }
        }
コード例 #2
0
ファイル: IE.cs プロジェクト: Danielfenghk/open2testselenium
 /// <summary>
 /// Handle Certificate Navigation block in IE.
 /// </summary>
 public static void handleIECertificateError(ref IWebDriver driver)
 {
     try
     {
         if (driver.Title.Contains("Certificate Error: Navigation Blocked"))
         {
             driver.Navigate().GoToUrl("javascript:document.getElementById('overridelink').click()");
         }
     }
     catch (Exception e)
     {
         KryptonException.Writeexception(e);
     }
 }
コード例 #3
0
ファイル: Program.cs プロジェクト: sham165/krypton
        /// <summary>
        /// btnClick : Click on any object in specified window.
        /// </summary>
        /// <param name="popUpName">string : name of popup to recover.</param>
        /// <param name="btnTitle"></param>
        private static void BtnClick(string popUpName, string btnTitle = "")
        {
            try
            {
                _objAutoit.WinActivate(popUpName);

                //Click on control, close dialog if unsuccessful
                if (!(btnTitle.Equals("") || btnTitle.Equals(string.Empty)))
                {
                    if (_objAutoit.ControlClick(popUpName, "", "[TEXT:" + btnTitle + "]") == 0)
                    {
                    }
                }
            }
            catch (Exception e)
            {
                KryptonException.Writeexception(e.InnerException);
            }
        }
コード例 #4
0
        private string GetMachineNameFromIPAddress(string ipAdress)
        {
            string machineName = string.Empty;

            try
            {
                ServiceAgent service = new ServiceAgent(ipAdress);
                machineName = service.GetMachineName();
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(machineName);
                machineName = xmlDoc.InnerText;
            }
            catch (Exception ex)
            {
                KryptonException.Writeexception(ex);
                Console.WriteLine("Unable to find the machine....");
            }
            return(machineName);
        }
コード例 #5
0
        /// <summary>
        /// common steps for creating html report and upload
        /// </summary>
        internal static void CreateHtmlReportSteps(List <string> inputTestIds = null)
        {
            //Creating HTML Report
            try
            {
                LogFile.AllXmlFilesLocation = string.Join(";", FilePath);

                // Using new format of report.
                bool isSummaryRequired  = Utility.GetParameter("SummaryReportRequired").ToLower().Equals("true");
                bool htmlReportRequired = !Utility.GetParameter("HtmlReportRequired").ToLower().Equals("false");
                LogFile.CreateHtmlReport(string.Empty, false, true, Property.IsSauceLabExecution);
                HtmlReport.CreateHtmlReport(string.Empty, false, true, Property.IsSauceLabExecution, isSummaryRequired, false, false, htmlReportRequired);
                GetReportSummary();
                Property.FinalXmlPath = FilePath[FilePath.Length - 1];
            }
            catch (Exception exception)
            {
                TestSuiteResult = 1;
                KryptonException.ReportException(exception.Data + "\n Message " + exception.Message + "\n StackTrace" + exception.StackTrace + "\n Line Number" +
                                                 exception.StackTrace.Substring(exception.StackTrace.LastIndexOf(' ')));
            }

            Console.WriteLine(ConsoleMessages.MSG_DASHED);
            Console.WriteLine(ConsoleMessages.MSG_UPLOADING_LOG);

            Manager.UploadTestExecutionResults();
            try
            {
                if (Utility.GetParameter("EmailNotification").Equals("true", StringComparison.OrdinalIgnoreCase))
                {
                    Utility.EmailNotification("end", false); //Email Notification after completion of the process
                }
            }
            catch (Exception)
            {
                Console.WriteLine(Utility.GetCommonMsgVariable("KRYPTONERRCODE0053"));
                throw;
            }
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: sham165/krypton
        /// <summary>
        ///   Get Dataset from the file specified.
        /// </summary>
        /// <param name="filePath">string : Filepath.</param>
        /// <returns>Dataset : dataset for the file.</returns>
        ///
        private static DataSet GetDataSet(string filePath)
        {
            DataSet dataset       = new DataSet();
            string  tmpFileName   = string.Empty;
            string  fileExtension = Path.GetExtension(filePath);

            try
            {
                tmpFileName = GetTemporaryFile(fileExtension, filePath);
                if (fileExtension != null && fileExtension.ToLower().Equals(".csv"))
                {
                    if (!File.Exists(tmpFileName))
                    {
                        Console.WriteLine(ConsoleMessages.FOD + filePath);
                    }
                    using (GenericParsing.GenericParserAdapter gp = new GenericParsing.GenericParserAdapter(tmpFileName, Encoding.UTF7))
                    {
                        gp.FirstRowHasHeader = true;
                        gp.ColumnDelimiter   = ',';
                        dataset = gp.GetDataSet();
                    }
                }
                else
                {
                    dataset = GetExcelDataSet(filePath);
                }
            }
            catch (Exception ex)
            {
                KryptonException.Writeexception(ex);
            }
            finally
            {
                File.Delete(tmpFileName);
            }
            return(dataset);
        }
コード例 #7
0
        internal void UpdateJobDeatils()
        {
            StreamReader reader = null;

            try
            {
                HttpWebRequest request = WebRequest.Create("https://" + username + ":" + accessKey + "@saucelabs.com/rest/v1/" + username + "/jobs/" + Utility.GetVariable("SessionID")) as HttpWebRequest;
                request.Method      = "Put";
                request.Credentials = new NetworkCredential(username, accessKey);
                request.ContentType = "application/json";
                //Setting the status.
                string ByteString = "{\"passed\": true} ";
                if (Property.JobExecutionStatus.Equals(ExecutionStatus.Fail))
                {
                    ByteString = "{\"passed\": false}";
                }
                byte[] byteRequestBody = Encoding.UTF8.GetBytes(ByteString);
                Stream requestStream   = request.GetRequestStream();
                requestStream.Write(byteRequestBody, 0, byteRequestBody.Length);
                requestStream.Close();
                HttpWebResponse response = request.GetResponse() as HttpWebResponse;
                reader = new StreamReader(response.GetResponseStream());
                string contents = reader.ReadLine();
            }
            catch (Exception ex)
            {
                KryptonException.Writeexception(ex);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: sham165/krypton
        /// <summary>
        /// Execution starts here
        /// </summary>
        /// <param name="args"> Two agruments would be passed 1. Recovery file path 2. Sheet name for popup file. 3. Invoking Parent Process ID </param>
        static void Main(string[] args)
        {
            try
            {
                string filePath = args[0].ToString();
                Console.WriteLine("FilePath" + filePath);
                _applicationPath = Application.ExecutablePath;
                int    applicationFilePath = _applicationPath.LastIndexOf("\\", StringComparison.Ordinal);
                string workingDirectory    = string.Empty;
                if (applicationFilePath >= 0)
                {
                    workingDirectory = _applicationPath.Substring(0, applicationFilePath + 1);
                }
                DataSet dataset = GetDataSet(filePath);
                try
                {
                    //Generate Autoit object.
                    _objAutoit = new AutoItX3Lib.AutoItX3();
                    //Setting AutoIt Title match to Exact match.
                    _objAutoit.AutoItSetOption("WinTitleMatchMode", 4);
                    _parentProcessId = args[2];
                }
                catch (Exception e)
                {
                    KryptonException.Writeexception(e);
                }

                //Starting Infinite loop.
                //loop should run as long as parent process is running
                while (_isParentProcessRunning)
                {
                    //Getting all windows beforehand.
                    dynamic windowsList  = _objAutoit.WinList("[REGEXPTITLE:^.*$]");
                    int     winListCount = (int)windowsList[0, 0]; // List[0,0] give the count of windows.

                    var windowTitleList = new List <string>();
                    //Populating non empty titles to windowTitleList.
                    for (int j = 1; j <= winListCount; j++)
                    {
                        string title = (string)windowsList[0, j];
                        if (!string.IsNullOrEmpty(title))
                        {
                            windowTitleList.Add(title);
                        }
                    }
                    if (dataset.Tables.Count > 0)
                    {
                        for (int i = 0; i < dataset.Tables[0].Rows.Count; i++)
                        {
                            //First thing first, check if parent process is running
                            //If parent process (Krypton.exe) is not running, exits from here
                            try
                            {
                                Process.GetProcessById(int.Parse(_parentProcessId));
                            }
                            catch (Exception e)
                            {
                                //Exception will occur only when parent process is not running
                                _isParentProcessRunning = false;
                                return;
                            }

                            //Get IE popup Title.
                            string popupName = dataset.Tables[0].Rows[i]["PopUpTitle"].ToString().Trim();
                            //Get IE popup Title.
                            string buttonName = dataset.Tables[0].Rows[i]["ButtonName"].ToString().Trim();
                            //Get the action need to be done.
                            string action = dataset.Tables[0].Rows[i]["Action"].ToString().Trim();

                            //Populate data if provided.
                            var data = dataset.Tables[0].Rows[i]["Data"].ToString().Trim();
                            if (windowTitleList.Contains(popupName))
                            {
                                //Switching control based on action given.
                                switch (action.ToLower())
                                {
                                case "click":
                                    BtnClick(popupName, buttonName);
                                    break;

                                case "keypress":
                                    KeyPress(popupName, data);
                                    break;

                                case "close":
                                    _objAutoit.WinClose(popupName);
                                    break;

                                case "run":
                                case "execute":
                                    if (!File.Exists(_applicationPath + data))
                                    {
                                        data = data + ".exe";
                                    }
                                    //Create process information and assign data
                                    using (Process specialScriptProcess = new Process())
                                    {
                                        specialScriptProcess.StartInfo.CreateNoWindow   = false;
                                        specialScriptProcess.StartInfo.WindowStyle      = ProcessWindowStyle.Hidden;
                                        specialScriptProcess.StartInfo.UseShellExecute  = false;
                                        specialScriptProcess.StartInfo.FileName         = data;
                                        specialScriptProcess.StartInfo.WorkingDirectory = workingDirectory;
                                        specialScriptProcess.StartInfo.ErrorDialog      = false;
                                        // Start the process
                                        specialScriptProcess.Start();
                                        specialScriptProcess.WaitForExit(10000);
                                    }
                                    break;
                                }
                            }
                            System.Threading.Thread.Sleep(10);
                        }
                        System.Threading.Thread.Sleep(2000);
                    }
                }
            }
            catch (System.Runtime.InteropServices.COMException)
            {
                Console.WriteLine(ConsoleMessages.REGISTER_AUTOIT);
            }
            catch (IndexOutOfRangeException)
            {
                Console.WriteLine(ConsoleMessages.INVALID_ARGUMNETS);
            }
            catch (Exception e)
            {
                Console.WriteLine(ConsoleMessages.PARALLEL_rECOVERY + e.Message + e.StackTrace);
            }
        }
コード例 #9
0
        /// <summary>
        /// This is the method to write common exception to xml log and display in console
        /// </summary>
        /// <param name="exception">Exception</param>
        /// <param name="stepNo">Step Number</param>
        /// <param name="stepDescription">Description</param>
        /// <returns></returns>
        public static void WriteExceptionLog(KryptonException exception, int stepNo, string stepDescription)
        {
            Console.WriteLine(exception.Message);
            try
            {
                Property.InitializeStepLog();
            }
            catch (Exception ex)
            {
                KryptonException.ReportException(ex.Message + "Initializesteplog()");
            }
            Property.StepNumber      = stepNo.ToString();
            Property.StepDescription = stepDescription;
            Property.Status          = ExecutionStatus.Fail;
            Property.Remarks         = exception.Message;
            Property.ExecutionDate   = DateTime.Now.ToString(Utility.GetParameter("DateFormat"));
            Property.ExecutionTime   = DateTime.Now.ToString(Utility.GetParameter("TimeFormat"));
            try
            {
                XmlLog.WriteExecutionLog();
                XmlLog.SaveXmlLog();
            }
            catch (Exception e)
            {
                KryptonException.ReportException(e.Message + "--->" + e.StackTrace + "--->" + e.Source);
            }

            if (Utility.GetParameter("closebrowseroncompletion").ToLower().Trim().Equals("true"))
            {
                if (TestStepAction != null)
                {
                    TestStepAction.Do("closeallbrowsers");
                }
            }

            try
            {
                if (stepDescription.IndexOf("Execute Test Case", StringComparison.OrdinalIgnoreCase) < 0)
                {
                    //Execution end date and time set
                    DateTime dtNow = DateTime.Now;
                    Property.ExecutionEndDateTime = dtNow.ToString(Property.Date_Time);

                    CreateHtmlReportSteps();

                    if (Utility.GetParameter("closebrowseroncompletion").ToLower().Trim().Equals("true"))
                    {
                        if (TestStepAction != null && !Utility.GetParameter("RunRemoteExecution").Equals("true", StringComparison.OrdinalIgnoreCase))
                        {
                            TestStepAction.Do("shutdowndriver"); //shutdown driver
                        }
                    }
                }
            }
            catch (Exception ex) {
                TestEngine.Logwriter.WriteLog("Data" + ex.Data + "Stacktrace" + ex.StackTrace + "Message" + ex.Message);
            }
            //Wait for user input at the end of the execution is handled by configuration file
            if (!string.Equals(Utility.GetParameter("EndExecutionWaitRequired"), "false", StringComparison.OrdinalIgnoreCase) &&
                stepDescription.IndexOf("Execute Test Case", StringComparison.OrdinalIgnoreCase) < 0)
            {
                Console.WriteLine(ConsoleMessages.MSG_DASHED);
                Console.WriteLine(ConsoleMessages.MSG_TERMINATE_WITH_EXCEPTION);
                while (true)
                {
                    ConsoleKeyInfo inf = Console.ReadKey(true); // Key output not shown
                    if (inf.Key == ConsoleKey.Enter)
                    {
                        break;
                    }

                    Console.WriteLine("Please press [Enter]" + inf.Key);
                }
            }
            TestSuiteResult = 1;
        }