Example #1
0
 public static UITestControlCollection GetControlCollection(WinText editControl)
 {
     return editControl.FindMatchingControls();
 }
        public WinText GetCUITTextcontrol(WinWindow w, string searchBy, string searchValue, int index)
        {
            Console.WriteLine("Inside function GetCUITTextcontrol");
            WinText GetCUITTextcontrol = new WinText(w);

            try
            {
                Playback.Initialize();
                switch (searchBy.Trim().ToLower())
                {
                    case "text":
                        {
                            if (index == -1)
                            {
                                GetCUITTextcontrol.SearchProperties.Add(WinText.PropertyNames.Name, searchValue, PropertyExpressionOperator.Contains);
                                UITestControlCollection textCollection = GetCUITTextcontrol.FindMatchingControls();
                                GetCUITTextcontrol = (WinText)textCollection[0];
                            }
                            else
                            {
                                GetCUITTextcontrol.SearchProperties.Add(WinText.PropertyNames.Name, searchValue);
                                UITestControlCollection textCollection = GetCUITTextcontrol.FindMatchingControls();
                                GetCUITTextcontrol = (WinText)textCollection[index];
                            }
                            break;
                        }

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

                    default:
                        throw new Exception(_error);
                }

                Playback.Cleanup();
                Console.WriteLine("Found TextControl and exiting function GetCUITTextcontrol");
                return GetCUITTextcontrol;

            }
            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 GetCUITCHeckbox and in line: " + line);
                throw new Exception(_error + "CUITRButton:" + System.Environment.NewLine + e.Message);
            }
        }