示例#1
0
 public static UITestControlCollection GetControlCollection(WinRadioButton radioControl)
 {
     return radioControl.FindMatchingControls();
 }
        public WinRadioButton GetCUITRadioButton(WinWindow w, string searchBy, string searchValue, int index)
        {
            Console.WriteLine("Inside function GetCUITRadioButton");
            WinRadioButton GetCUITRadioButton = new WinRadioButton(w);
            try
            {
                Playback.Initialize();
                switch (searchBy.Trim().ToLower())
                {
                    case "text":
                        {
                            if (index == -1)
                            {
                                GetCUITRadioButton.SearchProperties[WinRadioButton.PropertyNames.Name] = searchValue;

                            }
                            else
                            {
                                GetCUITRadioButton.SearchProperties.Add(WinRadioButton.PropertyNames.Name, searchValue);
                                UITestControlCollection radioButtonCollection = GetCUITRadioButton.FindMatchingControls();
                                GetCUITRadioButton = (WinRadioButton)radioButtonCollection[index];
                            }
                            break;
                        }

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

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

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