/* * Created by Ranorex * User: rodriqu_dd * Date: 01/11/2021 * Time: 09:11 * * To change this template use Tools > Options > Coding > Edit standard headers. */ using System; using System.Collections.Generic; using System.Text; using System.Text.RegularExpressions; using System.Drawing; using System.Threading; using System.Linq; using WinForms = System.Windows.Forms; using Ranorex; using Ranorex.Core; using Ranorex.Core.Repository; using Ranorex.Core.Testing; namespace Ranorex_Automation_Helpers.UserCodeCollections { /// /// Creates a Ranorex user code collection. A collection is used to publish user code methods to the user code library. /// [UserCodeCollection] public static class PropertiesPanelHelpers { // You can use the "Insert New User Code Method" functionality from the context menu, // to add a new method with the attribute [UserCodeMethod]. /// /// This static method returns a Row object given the path in the properties panel. /// [UserCodeMethod] public static Ranorex.Adapter GetRowInPropertiesPanelGivenPath(string pathItem, Adapter argumentAdapter) { Mouse.DefaultMoveTime = 0; Keyboard.DefaultKeyPressTime = 0; Delay.SpeedFactor = 0.0; int minimumIndex = 0; var stepsPathItem = pathItem.Split('>').ToList(); var stepRow = argumentAdapter.As().Children.ToList()[1]; for (int i=0; i < stepsPathItem.Count; i++) { // Find the item corresponding to the step var step = stepsPathItem[i]; var completeList = argumentAdapter.As
().Children.ToList(); var searchList = completeList.GetRange(minimumIndex, completeList.Count-minimumIndex); var indexStepRow = searchList.FindIndex(row => row.GetAttributeValue("AccessibleName").Contains(step)); stepRow = searchList[indexStepRow]; stepRow.Focus(); var cell = stepRow.As(); if (cell != null) { cell.Select(); } if (i != stepsPathItem.Count - 1 && stepRow.Element.GetAttributeValueText("AccessibleState").Contains("Collapsed")) { stepRow.PressKeys("{Right}"); } minimumIndex += 1 + indexStepRow; Delay.Duration(Duration.Parse("500"), false); } return stepRow; } /// /// This method sets a new value to a parameter in a field in properties panel given its path. /// [UserCodeMethod] public static void SetValue(this Ranorex.Adapter row, string newValue, string parameterType) { switch (parameterType) { case "Text": SetTextParameterInPropertiesPanel(row, newValue); break; case "Double": SetDoubleParameterInPropertiesPanel(row, newValue); break; case "DropDown": //RepoItemInfo listItemInfo = new RepoItemInfo(myRepository.DropDownMenuInRowPropertiesPanel.List, "genericItemInDropDownList", "listitem[@accessiblename~" + newValueForParameter + "]", 30000, null); //SetDynamicDropDownParameterInPropertiesPanel(row, newValueForParameter, listItemInfo); break; default: Report.Log(ReportLevel.Error, "Type of parameter " + parameterType + " not implemented!"); break; } } private static void SetDoubleParameterInPropertiesPanel(Ranorex.Adapter row, string newValue) { row.Element.SetAttributeValue("AccessibleValue", newValue.ToCurrentCulture()); } private static void SetTextParameterInPropertiesPanel(Ranorex.Adapter row, string newValue) { row.Element.SetAttributeValue("AccessibleValue", newValue); } private static void SetDynamicDropDownParameterInPropertiesPanel(Ranorex.Adapter row, string newValueForParameter, RepoItemInfo listItemInfo) { row.Click(); row.Click(".98;.5"); listItemInfo.FindAdapter().Focus(); listItemInfo.FindAdapter().Click(); } } }