예제 #1
0
        public void testmethods()
        {
            ApplicationUnderTest note = ApplicationUnderTest.Launch("C:\\Windows\\System32\\notepad.exe");
            UITestControl        num  = new UITestControl();

            num.TechnologyName = "MSAA";
            num.SearchProperties[UITestControl.PropertyNames.Name] = "Untitled - Notepad";
            UITestControl           but     = new WinButton(num);
            UITestControlCollection control = but.FindMatchingControls();
            var controlbutton = control.GetNamesOfControls();

            foreach (var c in controlbutton)
            {
                Keyboard.SendKeys(c + "\n");
            }


            // var Ocr = new AutoOcr();
            //var Result = Ocr.Read(@"C:\Users\shravya.shastri\Desktop\qrcode.png");
            // Console.WriteLine(Result.Text);
            // string n = Result.ToString();
            // method.launch();
            // Keyboard.SendKeys(n);
            // method.filemethod();
            // method.savemethod();
            // method.scenarios();
            //mouse.rightclickmethod();
        }
        /// <summary>
        /// Get all buttons in UI with the given button 'Name' property
        /// </summary>
        /// <param name="window">Parent window of the control</param>
        /// <param name="buttonName">Display Name of Control</param>
        /// <returns>List of WinButtons</returns>
        public static List <WinButton> GetButtonsByName(this WinWindow window, string buttonName)
        {
            WinButton btn = new WinButton(window);

            btn.TechnologyName = "MSAA";
            btn.SearchProperties[WinButton.PropertyNames.Name] = buttonName;
            var buttons = btn.FindMatchingControls();
            List <WinButton> buttonArray = new List <WinButton>();

            foreach (var button in buttons)
            {
                if (button.Name.Contains(buttonName))
                {
                    buttonArray.Add((WinButton)button);
                }
            }
            return(buttonArray);
        }
 public static void ClickWinButton(string wintitle, string tabname)
 {
     WinWindow wnd2 = new WinWindow();
     wnd2.SearchProperties.Add(WinWindow.PropertyNames.Name, wintitle, PropertyExpressionOperator.Contains);
     wnd2.SearchProperties.Add(WinWindow.PropertyNames.ClassName, "WindowsForms10.Window", PropertyExpressionOperator.Contains);
     wnd2.SetFocus();
     wnd2.Maximized = true;
     Console.WriteLine("got focus of window"+ wnd2.Name);
     Console.WriteLine("Button Name " + tabname);
     WinButton wbtn = new WinButton(wnd2);
     UITestControlCollection allbtns = wbtn.FindMatchingControls();
     Console.WriteLine("buttons count insiode widnows was " + allbtns.Count);
     foreach (UITestControl indbutton in allbtns)
     {
         Console.WriteLine("Found button " + indbutton.Name);
     }
     wbtn.SearchProperties.Add(WinButton.PropertyNames.Name, tabname, PropertyExpressionOperator.Contains);
     Mouse.Click(wbtn);
 }
예제 #4
0
        public void PrintingMatchingControlsName()
        {
            ApplicationUnderTest.Launch(@"C:\Windows\System32\calc.exe");

            //For WinWindow
            WinWindow calWindow = new WinWindow();

            calWindow.SearchProperties[WinWindow.PropertyNames.Name]      = "Calculator";
            calWindow.SearchProperties[WinWindow.PropertyNames.ClassName] = "CalcFrame";

            WinButton button = new WinButton(calWindow);

            UITestControlCollection buttonColl = button.FindMatchingControls();
            var Controls = buttonColl.Select(bu => bu.Name);

            foreach (var item in Controls)
            {
                Console.WriteLine(item);
            }
        }
예제 #5
0
        public static void ClickWinButton(string wintitle, string tabname)
        {
            WinWindow wnd2 = new WinWindow();

            wnd2.SearchProperties.Add(WinWindow.PropertyNames.Name, wintitle, PropertyExpressionOperator.Contains);
            wnd2.SearchProperties.Add(WinWindow.PropertyNames.ClassName, "WindowsForms10.Window", PropertyExpressionOperator.Contains);
            wnd2.SetFocus();
            wnd2.Maximized = true;
            Console.WriteLine("got focus of window" + wnd2.Name);
            Console.WriteLine("Button Name " + tabname);
            WinButton wbtn = new WinButton(wnd2);
            UITestControlCollection allbtns = wbtn.FindMatchingControls();

            Console.WriteLine("buttons count insiode widnows was " + allbtns.Count);
            foreach (UITestControl indbutton in allbtns)
            {
                Console.WriteLine("Found button " + indbutton.Name);
            }
            wbtn.SearchProperties.Add(WinButton.PropertyNames.Name, tabname, PropertyExpressionOperator.Contains);
            Mouse.Click(wbtn);
        }
예제 #6
0
 public static UITestControlCollection GetControlCollection(WinButton btnControl)
 {
     return btnControl.FindMatchingControls();
 }
        //this function is called inside CUITWindow() and its overloaded method
        public WinButton GetCUITButton(WinWindow w, string searchBy, string searchValue, int index)
        {
            Console.WriteLine("Inside function GetCUITButton:");
            WinButton GetCUITButton = new WinButton(w);

            try
            {
                Playback.Initialize();
                switch (searchBy.Trim().ToLower())
                {
                    case "text":
                        {
                            if (index == -1)
                            {

                                GetCUITButton.SearchProperties[WinButton.PropertyNames.Name] = searchValue;
                            }
                            else
                            {

                                GetCUITButton.SearchProperties.Add(WinButton.PropertyNames.Name, searchValue);
                                UITestControlCollection buttonCollection = GetCUITButton.FindMatchingControls();
                                GetCUITButton = (WinButton)buttonCollection[index];

                            }
                            break;
                        }
                    case "regulartext":
                        {
                            if (index == -1)
                            {

                                GetCUITButton.SearchProperties.Add(WinButton.PropertyNames.Name, searchValue, PropertyExpressionOperator.Contains);
                                UITestControlCollection buttonCollection = GetCUITButton.FindMatchingControls();
                                GetCUITButton = (WinButton)buttonCollection[0];
                            }
                            else
                            {

                                GetCUITButton.SearchProperties.Add(WinButton.PropertyNames.Name, searchValue);
                                UITestControlCollection buttonCollection = GetCUITButton.FindMatchingControls();
                                GetCUITButton = (WinButton)buttonCollection[index];

                            }
                            break;
                        }

                    case "automationid":
                        {
                            if (index == -1)
                            {
                                GetCUITButton.SearchProperties.Add(WinButton.PropertyNames.ControlName, searchValue);
                                UITestControlCollection buttonCollection = GetCUITButton.FindMatchingControls();
                                GetCUITButton = (WinButton)buttonCollection[0];
                            }
                            else
                            {

                                GetCUITButton.SearchProperties.Add(WinButton.PropertyNames.ControlName, searchValue);
                                UITestControlCollection buttonCollection = GetCUITButton.FindMatchingControls();
                                GetCUITButton = (WinButton)buttonCollection[index];
                            }
                            break;
                        }

                    default:
                        throw new Exception(_error);

                }
                Playback.Cleanup();
                Console.WriteLine("Found Button and exiting function GetCUITButton");
                return GetCUITButton;

            }
            catch (Exception e)
            {
                // Get stack trace for the exception with source file information
                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 GetCUITButton and in line: " + line);
                throw new Exception(_error + "CUITRButton:" + System.Environment.NewLine + e.Message + " in line " + line);
            }
        }