Пример #1
0
 public static UITestControlCollection GetControlCollection(WinComboBox dropDoBoxControl)
 {
     return dropDoBoxControl.FindMatchingControls();
 }
        public WinComboBox GetCUITComboBox(WinWindow w, string searchBy, string searchValue, int index)
        {
            WinComboBox GetCUITComboBox = new WinComboBox(w);
            Console.WriteLine("Inside function GetCUITComboBox");
            try
            {
                Playback.Initialize();
                switch (searchBy.Trim().ToLower())
                {
                    case "text":
                        {
                            if (index == -1)
                            {
                                GetCUITComboBox.SearchProperties[WinComboBox.PropertyNames.Name] = searchValue;
                            }
                            else
                            {
                                GetCUITComboBox.SearchProperties.Add(WinComboBox.PropertyNames.Name, searchValue);
                                UITestControlCollection comboboxCollection = GetCUITComboBox.FindMatchingControls();
                                GetCUITComboBox = (WinComboBox)comboboxCollection[index];
                            }
                            break;
                        }

                    case "automationid":
                        {
                            if (index == -1)
                            {
                                GetCUITComboBox.SearchProperties.Add(WinComboBox.PropertyNames.ControlName, searchValue);
                                UITestControlCollection comboboxCollection = GetCUITComboBox.FindMatchingControls();
                                GetCUITComboBox = (WinComboBox)comboboxCollection[0];
                            }
                            else
                            {
                                GetCUITComboBox.SearchProperties.Add(WinComboBox.PropertyNames.ControlName, searchValue);
                                UITestControlCollection comboboxCollection = GetCUITComboBox.FindMatchingControls();
                                GetCUITComboBox = (WinComboBox)comboboxCollection[index];
                            }
                            break;
                        }

                    default:
                        throw new Exception(_error);
                }
                Playback.Cleanup();
                Console.WriteLine("Found Combobox and exiting function GetCUITComboBox");
                return GetCUITComboBox;

            }
            catch (Exception e)
            {
                var st = new StackTrace(e, true);
                var testFrame = st.GetFrame(0);
                for (int i = 0; i < st.FrameCount; i++)
                {
                    testFrame = st.GetFrame(i);
                    if (testFrame.GetFileName() != null)
                    {
                        if (testFrame.GetFileName().ToString().Contains("CUITFramework.cs") == true)
                        {
                            break;
                        }
                    }

                }
                // Get the top stack frame
                var frame = testFrame;
                // Get the line number from the stack frame
                var line = frame.GetFileLineNumber();
                logTofile(_eLogPtah, "Error in GetCUITComboBox and in line: " + line);
                throw new Exception(_error + "CUITRButton:" + System.Environment.NewLine + e.Message);
            }
        }