//*************************************************************************************************************************************************************
        public static bool AddCommentsToCommentedReport(TestStack.White.Application qbApp, TestStack.White.UIItems.WindowItems.Window qbWindow, string commentedReportName, string commentedReportTitle, string xyCoordinatesFileName, int countOfCommentsToCreate)
        {
            TestStack.White.UIItems.WindowItems.Window commentedReportWindow = null;
            try
            {
                bool status = Reports.OpenSavedCommentedReport(qbApp, qbWindow, commentedReportName, commentedReportTitle);
                if (status)
                {
                    try
                    {
                        if (CheckWhetherVisualCueExists(xyCoordinatesFileName))
                        {
                            //Read from XML file
                            XmlDocument doc = new XmlDocument();
                            int counter = 0;
                            var pathWithEnv = @"%USERPROFILE%\AppData\Local\Intuit\QuickBooks\Log\15.0\Comments\" + xyCoordinatesFileName + "_VisualCue_XandY_Positions.xml";
                            var path = Environment.ExpandEnvironmentVariables(pathWithEnv).ToString();
                            doc.Load(path);
                            XmlNode root = doc.DocumentElement;
                            List<VisualCue> myVisualCueList = new List<VisualCue>();

                            foreach (XmlNode node in doc.DocumentElement)
                            {
                                //Add comments only for the first few visual cues
                                if (counter >= countOfCommentsToCreate)
                                    break;
                                else
                                {
                                    if (node.Name.Equals("VisualCue"))
                                    {
                                        VisualCue cue = new VisualCue();
                                        foreach (XmlNode childNode in node.ChildNodes)
                                        {
                                            switch (childNode.Name)
                                            {
                                                case "row":
                                                    cue.row = Int32.Parse(childNode.InnerText.Trim());
                                                    break;
                                                case "col":
                                                    cue.col = Int32.Parse(childNode.InnerText.Trim());
                                                    break;
                                                case "X1":
                                                    cue.x1 = Int32.Parse(childNode.InnerText.Trim());
                                                    break;
                                                case "Y1":
                                                    cue.y1 = Int32.Parse(childNode.InnerText.Trim());
                                                    break;
                                                case "X2":
                                                    cue.x2 = Int32.Parse(childNode.InnerText.Trim());
                                                    break;
                                                case "Y2":
                                                    cue.y2 = Int32.Parse(childNode.InnerText.Trim());
                                                    break;
                                            }
                                        }
                                        myVisualCueList.Add(cue);
                                        ++counter;
                                    }
                                }
                            }

                            TestStack.White.InputDevices.Mouse mouse = null;
                            commentedReportWindow = FrameworkLibraries.ActionLibs.WhiteAPI.Actions.GetChildWindow(qbWindow, commentedReportTitle);
                            foreach (VisualCue vc in myVisualCueList)
                            {
                                commentedReportWindow.Focus();
                                mouse = TestStack.White.InputDevices.Mouse.Instance;
                                var point = new System.Windows.Point(vc.x1, vc.y1);
                                mouse.Location = point;
                                //mouse.Click();
                                Thread.Sleep(int.Parse(Execution_Speed));
                                FrameworkLibraries.ActionLibs.WhiteAPI.Actions.ClickElementByAutomationID(commentedReportWindow, "12502");
                                Thread.Sleep(int.Parse(Execution_Speed));
                                FrameworkLibraries.ActionLibs.WhiteAPI.Actions.SetTextByAutomationID(commentedReportWindow, "CommentTextBox", "Comment from WhiteAPI");
                                FrameworkLibraries.ActionLibs.WhiteAPI.Actions.ClickElementByName(commentedReportWindow, "Save");
                                Thread.Sleep(int.Parse(Execution_Speed));
                            }
                            // Save the commented report
                            Reports.SaveCommentedReport(qbApp, qbWindow, commentedReportWindow, commentedReportName);
                            Logger.logMessage("AddCommentsToCommentedReport : -> Successfully Added add comments for the Commented report" + commentedReportName);
                            Logger.logMessage("------------------------------------------------------------------------------");
                        }
                        else
                        {
                            commentedReportWindow = FrameworkLibraries.ActionLibs.WhiteAPI.Actions.GetChildWindow(qbWindow, commentedReportTitle);
                            //Save the commented report and log that the report does not have any data to comment
                            Reports.SaveCommentedReport(qbApp, qbWindow, commentedReportWindow, commentedReportName);
                            Logger.logMessage("No visual cue to add comments for the report" + commentedReportName);
                            Logger.logMessage("------------------------------------------------------------------------------");
                        }
                    }
                    catch { }
                }
                return true;
            }
            catch (Exception e)
            {
                Logger.logMessage("AddCommentsToCommentedReport : -> Failed to add comments for the Commented report" + commentedReportName);
                Logger.logMessage(e.Message);
                Logger.logMessage("------------------------------------------------------------------------------");
                String sMessage = e.Message;
                LastException.SetLastError(sMessage);
                throw new Exception(sMessage);
            }
        }
Exemplo n.º 2
0
        //*************************************************************************************************************************************************************
        private static bool CheckCommentsCreatedByModifiedByValues(TestStack.White.Application qbApp, TestStack.White.UIItems.WindowItems.Window qbWindow, string commentedReportName, string commentedReportTitle, string xyCoordinatesFileName, int visualCueCount)
        {
            Logger.logMessage("CheckCommentsCreatedByModifiedByValues : -> Started");
            Logger.logMessage("------------------------------------------------------------------------------");
            TestStack.White.UIItems.WindowItems.Window commentedReportWindow = null;
            try
            {
                bool status = Reports.OpenSavedCommentedReport(qbApp, qbWindow, commentedReportName, commentedReportTitle);
                if (status)
                {
                    try
                    {
                        if (CheckWhetherVisualCueExists(xyCoordinatesFileName))
                        {
                            //Read from XML file
                            XmlDocument doc = new XmlDocument();
                            int counter = 0;
                            var pathWithEnv = @"%USERPROFILE%\AppData\Local\Intuit\QuickBooks\Log\15.0\Comments\" + xyCoordinatesFileName + "_VisualCue_XandY_Positions.xml";
                            var path = Environment.ExpandEnvironmentVariables(pathWithEnv).ToString();
                            doc.Load(path);
                            XmlNode root = doc.DocumentElement;
                            List<VisualCue> myVisualCueList = new List<VisualCue>();

                            foreach (XmlNode node in doc.DocumentElement)
                            {
                                //Add comments only for the first few visual cues
                                if (counter >= visualCueCount)
                                    break;
                                else
                                {
                                    if (node.Name.Equals("VisualCue"))
                                    {
                                        VisualCue cue = new VisualCue();
                                        foreach (XmlNode childNode in node.ChildNodes)
                                        {
                                            switch (childNode.Name)
                                            {
                                                case "row":
                                                    cue.row = Int32.Parse(childNode.InnerText.Trim());
                                                    break;
                                                case "col":
                                                    cue.col = Int32.Parse(childNode.InnerText.Trim());
                                                    break;
                                                case "X1":
                                                    cue.x1 = Int32.Parse(childNode.InnerText.Trim());
                                                    break;
                                                case "Y1":
                                                    cue.y1 = Int32.Parse(childNode.InnerText.Trim());
                                                    break;
                                                case "X2":
                                                    cue.x2 = Int32.Parse(childNode.InnerText.Trim());
                                                    break;
                                                case "Y2":
                                                    cue.y2 = Int32.Parse(childNode.InnerText.Trim());
                                                    break;
                                            }
                                        }
                                        myVisualCueList.Add(cue);
                                        ++counter;
                                    }
                                }
                            }

                            TestStack.White.InputDevices.Mouse mouse = null;
                            commentedReportWindow = FrameworkLibraries.ActionLibs.WhiteAPI.Actions.GetChildWindow(qbWindow, commentedReportTitle);
                            VisualCue temp = myVisualCueList.First();
                            commentedReportWindow.Focus();
                            mouse = TestStack.White.InputDevices.Mouse.Instance;
                            var point = new System.Windows.Point(temp.x1, temp.y1);
                            mouse.Location = point;
                            Thread.Sleep(int.Parse(Execution_Speed));
                            FrameworkLibraries.ActionLibs.WhiteAPI.Actions.ClickElementByAutomationID(commentedReportWindow, "12502");
                            Thread.Sleep(int.Parse(Execution_Speed));
                            FrameworkLibraries.ActionLibs.WhiteAPI.Actions.SetTextByAutomationID(commentedReportWindow, "CommentTextBox", "Comment from WhiteAPI");
                            Thread.Sleep(int.Parse(Execution_Speed));
                            FrameworkLibraries.ActionLibs.WhiteAPI.Actions.ClickElementByName(commentedReportWindow, "Save");
                            
                            var a = commentedReportWindow.Items;
                            TestStack.White.UIItems.ListView lv = (TestStack.White.UIItems.ListView)commentedReportWindow.Get(SearchCriteria.ByControlType(System.Windows.Automation.ControlType.DataGrid));
                            string id = lv.Rows[0].Cells[3].Text;
                            Assert.AreEqual("Created by Admin", id, "Invalid user identity for the comment");

                            // Edit the first comment
                            List<IUIItem> buttons = FrameworkLibraries.ActionLibs.WhiteAPI.Actions.GetAllButtons(commentedReportWindow.Items);
                            bool isEdited = false;
                            TestStack.White.UIItems.Button x = null;
                            foreach (IUIItem button in buttons)
                            {
                                if (isEdited == false && button.Id.Contains("Edit"))
                                {
                                    x = (TestStack.White.UIItems.Button)button;
                                    FrameworkLibraries.ActionLibs.WhiteAPI.Actions.ClickButtonByAutomationID(commentedReportWindow, button.Id);
                                    Thread.Sleep(int.Parse(Execution_Speed));
                                    FrameworkLibraries.ActionLibs.WhiteAPI.Actions.SetTextByAutomationID(commentedReportWindow, "CommentTextBox", "Comment-Edited");
                                    FrameworkLibraries.ActionLibs.WhiteAPI.Actions.ClickElementByName(commentedReportWindow, "Save");
                                    Thread.Sleep(int.Parse(Execution_Speed));
                                    isEdited = true;
                                    break;
                                }
                            }

                            a = commentedReportWindow.Items;
                            lv = (TestStack.White.UIItems.ListView)commentedReportWindow.Get(SearchCriteria.ByControlType(System.Windows.Automation.ControlType.DataGrid));
                            id = lv.Rows[0].Cells[3].Text;
                            Assert.AreEqual("Modified by Admin", id, "Invalid user identity for the comment");

                            Logger.logMessage("CheckCommentsCreatedByModifiedByValues : " + commentedReportName);
                            Logger.logMessage("------------------------------------------------------------------------------");
                        }
                        else
                        {
                            commentedReportWindow = FrameworkLibraries.ActionLibs.WhiteAPI.Actions.GetChildWindow(qbWindow, commentedReportTitle);
                            //Save the commented report and log that the report does not have any data to comment
                            Reports.SaveCommentedReport(qbApp, qbWindow, commentedReportWindow, commentedReportName);
                            Logger.logMessage("CheckCommentsCreatedByModifiedByValues" + commentedReportName);
                            Logger.logMessage("------------------------------------------------------------------------------");
                        }
                    }
                    catch { }
                }
                return true;
            }
            catch (Exception e)
            {
                Logger.logMessage("AddCommentsToCommentedReport : -> Failed to add comments for the Commented report" + commentedReportName);
                Logger.logMessage(e.Message);
                Logger.logMessage("------------------------------------------------------------------------------");
                String sMessage = e.Message;
                LastException.SetLastError(sMessage);
                throw new Exception(sMessage);
            }
        }