/// <summary>
        ///     Scroll to specified direction and search for treeItem
        /// </summary>
        /// <param name="button">Button to use for scrolling</param>
        /// <param name="pathPart">TreeItem to search for</param>
        /// <param name="lastFoundTreeItemChildIndex">Reference to the latest found tree item</param>
        /// <returns>
        ///     <br>TreeItem: If call worked fine</br>
        ///     <br>Null: If an error occurred</br>
        /// </returns>
        private TreeItem ScrollAndSearchTreeItem(Button button, string pathPart, int lastFoundTreeItemChildIndex)
        {
            try
            {
                bool     isSearching = true;
                TreeItem treeItem    = null;

                // While no element is found and search is going on
                while (treeItem == null && isSearching)
                {
                    Log.Info(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Scrolling...And...Searching...");
                    button.Click(DefaultValues.locDefaultLocation);
                    treeItem = NavigationElements.GetTreeItem(pathPart, lastFoundTreeItemChildIndex);
                    if (button.ScreenRectangle.Size.Height == 0)
                    {
                        isSearching = false;
                    }
                }

                return(treeItem);
            }
            catch (Exception exception)
            {
                Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), exception.Message);
                return(null);
            }
        }
        /// <summary>
        /// Tries to restore an invalid file and validates whether the modules behavior is correct and its not possible to restore.
        /// </summary>
        /// <param name="fileName">
        /// Filename of an invalid file to restore
        /// </param>
        /// <param name="defaultPath">
        /// If true, "Program Data" path is used as file location. Else a valid file location path must be provided
        /// </param>
        /// <returns>
        /// <br>True: If call worked fine</br>
        ///     <br>False: If an error occurred</br>
        /// </returns>
        public bool Run(string fileName, bool defaultPath)
        {
            bool result = true;

            if (new Navigation().Restore() == false)
            {
                Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Failed to press Restore button.");
                result = false;
            }
            else
            {
                // Use file dialog to create file with specified filename
                if (fileName == string.Empty)
                {
                    Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "File name must not be empty.");
                    result = false;
                }
                else
                {
                    if (defaultPath)
                    {
                        // set default path
                        fileName = SystemInformation.GetApplicationDataPath + @"\" + fileName;
                    }

                    if ((new LoadFile()).Run(fileName) == false)
                    {
                        Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Loading file \"" + fileName + "\" failed.");
                        result = false;
                    }
                    else
                    {
                        new Navigation().Start();
                        string         message          = new CheckSaveRestoreStatus().GetCurrentStatus().ToLower();
                        Ranorex.Button restore          = new NavigationElements().BtnRestore;
                        bool           isRestoreEnabled = false;
                        if (restore != null)
                        {
                            isRestoreEnabled = restore.Enabled;
                        }

                        if (message.Contains("please select another file") == false || isRestoreEnabled)
                        {
                            Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Tried to restore an invalid file. Module did not recognize this and would have allowed to restore the file.");
                            result = false;
                        }
                        else
                        {
                            Log.Info(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Tried to restore an invalid file. Module recognized this and refused to restore the file as expected.");
                        }
                    }
                }
            }

            return(result);
        }
Пример #3
0
        /// <summary>
        ///     Clicks button Restore
        /// </summary>
        /// <returns>
        ///     <br>True: If call worked fine</br>
        ///     <br>False: If an error occurred</br>
        /// </returns>
        public bool Restore()
        {
            Element button = new NavigationElements().BtnRestore;

            if (button != null && button.Enabled)
            {
                Mouse.MoveTo(button, 500);
                Mouse.Click();
                return(true);
            }

            Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Element is not available.");
            return(false);
        }
        /// <summary>
        ///     Search and returns a tree item behind a specified path.
        /// </summary>
        /// <param name="strPath">Item (menu / parameter) to search for.</param>
        /// <returns>
        ///     <br>TreeItem: If call worked fine</br>
        ///     <br>Null: If an error occurred</br>
        /// </returns>
        private TreeItem GetTreeItemByPath(string strPath)
        {
            string[] seperator = { "//" };
            string[] pathParts = strPath.Split(seperator, StringSplitOptions.None);

            int      counter = 0;
            int      lastFoundTreeItemChildIndex = -1;
            TreeItem lastFoundTreeItem           = null;
            TreeItem treeItem = null;

            try
            {
                for (counter = 0; counter < pathParts.Length; counter++)
                {
                    // Get treeitem if it is visible at current GUI
                    treeItem = NavigationElements.GetTreeItem(pathParts[counter], lastFoundTreeItemChildIndex);

                    if (counter == pathParts.Length - 2 && treeItem != null)
                    {
                        treeItem.Click();
                        Parameter parameter = new Application().GetParameterStateFast(pathParts[pathParts.Length - 1]);
                        if (parameter.ParameterState != ParameterState.NotRecognized)
                        {
                            return(treeItem);
                        }
                    }

                    if (treeItem == null)
                    {
                        // If scrollbar active and not null
                        if (NavigationElements.VerticalScrollbar != null && NavigationElements.VerticalScrollbar.Enabled)
                        {
                            if (NavigationElements.PageUpButton.ScreenRectangle.Size.Height == 0)
                            {
                                // If scrollbar is on top
                                // Scroll down
                                treeItem = this.ScrollAndSearchTreeItem(NavigationElements.PageDownButton, pathParts[counter], lastFoundTreeItemChildIndex);
                            }
                            else if (NavigationElements.PageDownButton.ScreenRectangle.Size.Height == 0)
                            {
                                // If scrollbar is on bottom
                                // Scroll up
                                treeItem = this.ScrollAndSearchTreeItem(NavigationElements.PageUpButton, pathParts[counter], lastFoundTreeItemChildIndex);
                            }
                            else if (NavigationElements.PageUpButton.ScreenRectangle.Size.Height <=
                                     NavigationElements.PageDownButton.ScreenRectangle.Size.Height)
                            {
                                // If scrollbar is nearly on top
                                // Scroll down first
                                treeItem = this.ScrollAndSearchTreeItem(NavigationElements.PageDownButton, pathParts[counter], lastFoundTreeItemChildIndex);

                                // Scroll up as next if treeItem noch found
                                if (treeItem == null)
                                {
                                    treeItem = this.ScrollAndSearchTreeItem(NavigationElements.PageUpButton, pathParts[counter], lastFoundTreeItemChildIndex);
                                }
                            }
                            else if (NavigationElements.PageUpButton.ScreenRectangle.Size.Height >
                                     NavigationElements.PageDownButton.ScreenRectangle.Size.Height)
                            {
                                // If scrollbar is nearly on bottom
                                // Scroll down first
                                treeItem = this.ScrollAndSearchTreeItem(NavigationElements.PageDownButton, pathParts[counter], lastFoundTreeItemChildIndex);

                                // Scroll up as next if treeItem noch found
                                if (treeItem == null)
                                {
                                    treeItem = this.ScrollAndSearchTreeItem(NavigationElements.PageUpButton, pathParts[counter], lastFoundTreeItemChildIndex);
                                }
                            }
                            else
                            {
                                Log.Error(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Impossible path at if-then-else structure.");
                            }
                        }
                        else
                        {
                            // if Scrollbar not active search for treeitem with index greater than last found
                            Log.Info(LogInfo.Namespace(MethodBase.GetCurrentMethod()), "Treeitem " + "[" + pathParts[counter] + "]" + " not found");
                        }
                    }

                    if (treeItem != null)
                    {
                        treeItem.MoveTo();
                        lastFoundTreeItemChildIndex = treeItem.Element.ChildIndex;
                        lastFoundTreeItem           = treeItem;
                    }

                    if (counter >= (pathParts.Length - 1))
                    {
                        continue;
                    }

                    if (treeItem != null)
                    {
                        treeItem.Expand();
                    }
                }

                return(lastFoundTreeItem);
            }
            catch (Exception exception)
            {
                Log.Error("Navigation.GetTreeItemByPath@" + pathParts[counter], exception.Message);
                return(null);
            }
        }
Пример #5
0
 protected Page(IWebDriver driver)
 {
     this.Driver = driver;
     NavigationElements.InitNavigationElements(driver, this);
 }