예제 #1
0
 public static UITestControlCollection GetControlCollection(WinCheckBox checkControl)
 {
     return checkControl.FindMatchingControls();
 }
        public WinCheckBox GetCUITCHeckbox(WinWindow w, string searchBy, string searchValue, int index)
        {
            Console.WriteLine("Inside function GetCUITCHeckbox");
            WinCheckBox GetCUITCHeckbox = new WinCheckBox(w);
            try
            {
                Playback.Initialize();
                switch (searchBy.Trim().ToLower())
                {
                    case "text":
                        {
                            if (index == -1)
                            {
                                GetCUITCHeckbox.SearchProperties[WinCheckBox.PropertyNames.Name] = searchValue;
                            }
                            else
                            {
                                GetCUITCHeckbox.SearchProperties.Add(WinCheckBox.PropertyNames.Name, searchValue);
                                UITestControlCollection checkboxCollection = GetCUITCHeckbox.FindMatchingControls();
                                GetCUITCHeckbox = (WinCheckBox)checkboxCollection[index];
                            }
                            break;
                        }

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

                    default:
                        throw new Exception(_error);
                }

                Playback.Cleanup();
                Console.WriteLine("Found Checkbox and exiting function GetCUITCHeckbox");
                return GetCUITCHeckbox;

            }
            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);
            }
        }