public static bool Finish()
        {
            // write RuntimeInstance.testingReportModel into RuntimeInstance.testReportFilePath file
            if (RuntimeInstance.currentTestingModule != null)
            {
                GUI_Utils.CheckRuntimeInstance();
                if (!RuntimeInstance.testingReportModel.ListTestModules.Contains(RuntimeInstance.currentTestingModule))
                {
                    RuntimeInstance.testingReportModel.ListTestModules.Add(RuntimeInstance.currentTestingModule);
                }
            }
            bool need2WriteLog = RuntimeInstance.testingReportModel != null &&
                                 RuntimeInstance.testingReportModel.ListTestModules != null &&
                                 RuntimeInstance.testingReportModel.ListTestModules.Count > 0;

            if (need2WriteLog)
            {
                TestReportFileLoader.WriteFile(RuntimeInstance.testReportFilePath, RuntimeInstance.testingReportModel);
            }
            if (need2WriteLog ||
                (RuntimeInstance.additionFiles != null &&
                 RuntimeInstance.additionFiles.Count > 0))
            {
                // add generated file to current testing project here
                AddReportFiles2Proj(need2WriteLog);
            }
            return(true);
        }
Example #2
0
        public static bool TextNotContains(IElement element, string value)
        {
            // export report here
            string textAttribute = element.GetText();

            if (textAttribute == null)
            {
                return(false);
            }
            string message = "Check " + element.Attributes.Name + "'s text not contains '" + value + "' is";
            string status  = ActionReport.STATUS_FAILTURE;
            string imgPath = null;
            bool   check   = !textAttribute.Contains(value);

            if (check)
            {
                message += " successful";
                status   = ActionReport.STATUS_SUCCESS;
            }
            else
            {
                message += " not successful";
                status   = ActionReport.STATUS_FAILTURE;
                imgPath  = CaptureScreen();
            }
            GUI_Utils.AddNewActionReport(new ActionReport(
                                             message, status, ActionReport.CATEGORY_VALIDATION, imgPath));
            return(check);
        }
        public bool ChooseOption(int order)
        {
            IElement buttonDropDown = GetDropDownButton(this);
            bool     re             = false;

            if (buttonDropDown == null)
            {
                re = this.Click(ClickOptions.RightElement);
            }
            else
            {
                re = buttonDropDown.Click();
            }
            //Thread.Sleep(1000);
            var listOptions = GetListOptions();

            if (listOptions == null)
            {
                GUI_Utils.AddNewActionReport(new ActionReport(
                                                 "ChooseOption " + order + " of " + this.Attributes.Name + " fail",
                                                 ActionReport.STATUS_FAILTURE,
                                                 ActionReport.CATEGORY_PROCEDURE,
                                                 Validate.CaptureScreen()));
                return(false);
            }
            re = re & ElementBase.Click(listOptions[order - 1]);
            return(re);
        }
Example #4
0
        public static bool NotExists(IElement element)
        {
            AutomationElement autoElement = GUI_Utils.SearchAutomationElement(
                new IdAndNameDesignCondition(element.Attributes.DesignedId, element.Attributes.DesignedName));

            GUI_Utils.CheckRuntimeInstance();
            string message = "Check NotExist of " + element.Attributes.Name;
            string status  = ActionReport.STATUS_FAILTURE;
            string imgPath = null;
            bool   check   = (autoElement == null || autoElement.Current.IsOffscreen);

            if (check)
            {
                message += " successfully";
                status   = ActionReport.STATUS_SUCCESS;
            }
            else
            {
                message += " not successfully";
                status   = ActionReport.STATUS_FAILTURE;
                imgPath  = CaptureScreen();
            }
            GUI_Utils.AddNewActionReport(new ActionReport(
                                             message, status, ActionReport.CATEGORY_VALIDATION, imgPath));
            return(check);
        }
Example #5
0
        public static string GetNameExp(IElement element)
        {
            string elementType = element.GetType().ToString().
                                 Replace("GUI_Testing_Automation.", "").
                                 Replace("Element", "");

            //Debug.WriteLine(elementType);

            return(element.Attributes.DesignedName != "" ?
                   (elementType + " " + GUI_Utils.NormalizeString(element.Attributes.DesignedName)) :
                   (elementType + " " + GUI_Utils.NormalizeString(element.Attributes.DesignedId)));
        }
Example #6
0
        public static string CaptureScreen()
        {
            string relativePath = @"Images\Screen_" + DateTime.Now.ToString("ddMMyy_HHmmss") + ".png";
            string path         = Path.Combine(@"..\..\Reports", relativePath);

            GUI_Utils.CreateDirectoryForFilePath(path, false);
            bool success = CaptureElement.CaptureAllScreen(path);

            if (!success)
            {
                return(null);
            }
            return(relativePath);
        }
        public static void InitNewModule(string moduleName)
        {
            string filePath = GetFilePath(moduleName, RuntimeInstance.listRunningFilesTest);

            if (filePath.EndsWith(".cs"))
            {
                filePath = filePath.Substring(0, filePath.Length - ".cs".Length);
            }
            RuntimeInstance.currentRunningFileTest = new Tuple <string, string>(moduleName, filePath);
            if (RuntimeInstance.currentTestingModule != null)
            {
                GUI_Utils.CheckRuntimeInstance();
                RuntimeInstance.testingReportModel.ListTestModules.Add(RuntimeInstance.currentTestingModule);
            }
            RuntimeInstance.currentTestingModule = null;
        }
Example #8
0
        /// <summary>
        /// store capture image to folder @path2FolderStore
        /// @fileName = @ElementType_@ElementName_@ddMMyy_HHmmss
        /// </summary>
        /// <param name="path2FolderStore"></param>
        /// <returns></returns>
        public bool Capture(string path2FolderStore)
        {
            string fileName = this.Attributes.ElementType + "_";

            fileName +=
                this.Attributes.DesignedName != "" ?
                GUI_Utils.NormalizeString(this.Attributes.DesignedName) :
                GUI_Utils.NormalizeString(this.Attributes.DesignedId);
            fileName += "_" + System.DateTime.Now.ToString("ddMMyy_HHmmss") + ".png";
            string filePath = path2FolderStore + @"\" + fileName;

            //modified by @duongtd - 09/11
            //hard code
            string encoded = CaptureElement.CaptureScreen(
                GetCurrentAutoElement().Current.BoundingRectangle, filePath);

            return(encoded != null);
        }
Example #9
0
        public static List <AutomationElement> SearchListAutomationElements(
            IElement element, List <AutomationElement> listAutoRootElement, bool updateWhenNull)
        {
            List <AutomationElement> re = new List <AutomationElement>();

            foreach (AutomationElement autoRootElement in listAutoRootElement)
            {
                re.AddRange(SearchListAutomationElements(element, autoRootElement));
            }

            //when null, update (maybe new windows)
            if (re.Count == 0)
            {
                List <AutomationElement> newWindows = GUI_Utils.UpdateElement();
                //only search with new windows
                foreach (AutomationElement newWindow in newWindows)
                {
                    re.AddRange(SearchListAutomationElements(element, newWindow));
                }
            }
            return(re);
        }
Example #10
0
        public static bool ExistsWithIdOnly(IElement element)
        {
            List <AutomationElement> autoElement = Search.SearchListAutomationElementsOnlyMatchId(
                element);
            string message = "Check ExistWidthIdOnly of " + element.Attributes.Name;
            string status  = ActionReport.STATUS_FAILTURE;
            string imgPath = null;
            bool   check   = autoElement != null && autoElement.Count > 0;

            if (check)
            {
                message += " successfully";
                status   = ActionReport.STATUS_SUCCESS;
            }
            else
            {
                message += " not successfully";
                status   = ActionReport.STATUS_FAILTURE;
                imgPath  = CaptureScreen();
            }
            GUI_Utils.AddNewActionReport(new ActionReport(
                                             message, status, ActionReport.CATEGORY_VALIDATION, imgPath));
            return(check);
        }
Example #11
0
        public static bool HeightEquals(IElement element, double value)
        {
            // export report here
            double realHeight = element.GetHeight();
            string message    = "Check " + element.Attributes.Name + "'s height equals with " + value + " is";
            string status     = ActionReport.STATUS_FAILTURE;
            string imgPath    = null;
            bool   check      = realHeight == value;

            if (check)
            {
                message += " successful";
                status   = ActionReport.STATUS_SUCCESS;
            }
            else
            {
                message += " not successful";
                status   = ActionReport.STATUS_FAILTURE;
                imgPath  = CaptureScreen();
            }
            GUI_Utils.AddNewActionReport(new ActionReport(
                                             message, status, ActionReport.CATEGORY_VALIDATION, imgPath));
            return(check);
        }
Example #12
0
        /// <summary>
        /// focus, then input normal string into this text element
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public bool InputString(string input)
        {
            AutomationElement element = GetCurrentAutoElement();

            if (element == null)
            {
                GUI_Utils.AddNewActionReport(new ActionReport(
                                                 "Input string '" + input + "' into " + this.Attributes.Name + " fail",
                                                 ActionReport.STATUS_FAILTURE,
                                                 ActionReport.CATEGORY_PROCEDURE,
                                                 Validate.CaptureScreen()));
                return(false);
            }
            //element.SetFocus();
            //ValuePattern valuePatternA = element.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern;
            //valuePatternA.SetValue(input);

            object valuePattern = null;

            // Control does not support the ValuePattern pattern
            // so use keyboard input to insert content.
            //
            // NOTE: Elements that support TextPattern
            //       do not support ValuePattern and TextPattern
            //       does not support setting the text of
            //       multi-line edit or document controls.
            //       For this reason, text input must be simulated
            //       using one of the following methods.
            //
            if (!element.TryGetCurrentPattern(
                    ValuePattern.Pattern, out valuePattern))
            {
                logger.Info("The control with an AutomationID of " +
                            element.Current.AutomationId.ToString() +
                            " does not support ValuePattern." +
                            " Using keyboard input.");

                // Set focus for input functionality and begin.
                element.SetFocus();

                // Pause before sending keyboard input.
                //Thread.Sleep(100);

                // Delete existing content in the control and insert new content.
                //SendKeys.SendWait("^{HOME}");   // Move to start of control
                //SendKeys.SendWait("^+{END}");   // Select everything
                //SendKeys.SendWait("{DEL}");     // Delete selection
                SendKeys.SendWait(input);
                Thread.Sleep(100);
                Keyboard.SendCombinedKeys(Keyboard.K_CTRL, Keyboard.K_END);
            }
            // Control supports the ValuePattern pattern so we can
            // use the SetValue method to insert content.
            else
            {
                logger.Info("The control with an AutomationID of " +
                            element.Current.AutomationId.ToString() +
                            " supports ValuePattern." +
                            " Using ValuePattern.SetValue().");

                // Set focus for input functionality and begin.
                element.SetFocus();
                string old = "";
                try
                {
                    old = ((ValuePattern)valuePattern).Current.Value;
                }
                catch (Exception) { }
                ((ValuePattern)valuePattern).SetValue(old + input);
                Keyboard.SendCombinedKeys(Keyboard.K_CTRL, Keyboard.K_END);
            }

            return(true);
        }
 /// <summary>
 /// Open application from path input
 /// </summary>
 /// <param name="pathToProgram"></param>
 /// <returns></returns>
 public static bool OpenApp(string pathToProgram)
 {
     //modify by duongtd 180226
     GUI_Utils.OpenApp(pathToProgram, TreeScope.Children, true);
     return(true);
 }
 public AutomationElementCollection Inspect(int processId)
 {
     return(GUI_Utils.DoOpenApp(processId, TreeScope.Children, true).Item1);
 }
 public AutomationElementCollection Inspect(string pathToProgram)
 {
     return(GUI_Utils.OpenApp1(pathToProgram, TreeScope.Children, true));
 }