Exemplo n.º 1
0
        public void SetUp()
        {
            using var app = Application.AttachOrLaunch("Gu.Wpf.Geometry.Demo.exe", WindowName);
            var window = app.MainWindow;

            window.FindButton("None").Invoke();
        }
Exemplo n.º 2
0
        public void MouseWheelBottomLeft()
        {
            using (var app = Application.AttachOrLaunch("Gu.Wpf.Geometry.Demo.exe", WindowName))
            {
                var window        = app.MainWindow;
                var renderSize    = window.FindTextBlock("Size");
                var contentMatrix = window.FindTextBlock("ContentMatrix");
                Mouse.Position = window.FindGroupBox("Zoombox").Bounds.BottomLeft + new Vector(1, -1);
                Assert.AreEqual("Identity", contentMatrix.Text);

                Mouse.Scroll(1);
                Assert.AreEqual("386, 249", renderSize.Text);
                Assert.AreEqual("1.05,0,0,1.05,0,-12.45", contentMatrix.Text);

                Mouse.Scroll(1);
                Assert.AreEqual("386, 249", renderSize.Text);
                Assert.AreEqual("1.1025,0,0,1.1025,0,-25.5225", contentMatrix.Text);

                Mouse.Scroll(-1);
                Assert.AreEqual("386, 249", renderSize.Text);
                Assert.AreEqual("1.05,0,0,1.05,0,-12.45", contentMatrix.Text);

                Mouse.Scroll(-1);
                Assert.AreEqual("386, 249", renderSize.Text);
                Assert.AreEqual("1,0,0,1,0,2.8421709430404E-14", contentMatrix.Text);
            }
        }
Exemplo n.º 3
0
        public void MouseWheelCenter()
        {
            using (var app = Application.AttachOrLaunch("Gu.Wpf.Geometry.Demo.exe", WindowName))
            {
                var window        = app.MainWindow;
                var renderSize    = window.FindTextBlock("Size");
                var contentMatrix = window.FindTextBlock("ContentMatrix");
                Mouse.Position = window.FindGroupBox("Zoombox").Bounds.Center();
                Assert.AreEqual("Identity", contentMatrix.Text);

                Mouse.Scroll(1);
                Assert.AreEqual("386, 249", renderSize.Text);
                Assert.AreEqual("1.05,0,0,1.05,-9.65000000000001,-6.20000000000002", contentMatrix.Text);

                Mouse.Scroll(1);
                Assert.AreEqual("386, 249", renderSize.Text);
                Assert.AreEqual("1.1025,0,0,1.1025,-19.7825,-12.71", contentMatrix.Text);

                Mouse.Scroll(-1);
                Assert.AreEqual("386, 249", renderSize.Text);
                Assert.AreEqual("1.05,0,0,1.05,-9.65,-6.20000000000003", contentMatrix.Text);

                Mouse.Scroll(-1);
                Assert.AreEqual("386, 249", renderSize.Text);
                Assert.AreEqual("1,0,0,1,1.59872115546023E-14,-1.68753899743024E-14", contentMatrix.Text);
            }
        }
Exemplo n.º 4
0
        public void MouseWheelTopLeftExplicitWheelZoomFactor()
        {
            using (var app = Application.Launch("Gu.Wpf.Geometry.Demo.exe", WindowName))
            {
                var window = app.MainWindow;
                window.FindTextBox("WheelZoomFactor").Text = "1.1";
                window.FindButton("None").Click();
                var renderSize    = window.FindTextBlock("Size");
                var contentMatrix = window.FindTextBlock("ContentMatrix");
                Mouse.Position = window.FindGroupBox("Zoombox").Bounds.TopLeft + new Vector(1, 1);
                Assert.AreEqual("Identity", contentMatrix.Text);

                Mouse.Scroll(1);
                Assert.AreEqual("386, 249", renderSize.Text);
                Assert.AreEqual("1.1,0,0,1.1,0,0", contentMatrix.Text);

                Mouse.Scroll(1);
                Assert.AreEqual("386, 249", renderSize.Text);
                Assert.AreEqual("1.21,0,0,1.21,0,0", contentMatrix.Text);

                Mouse.Scroll(-1);
                Assert.AreEqual("386, 249", renderSize.Text);
                Assert.AreEqual("1.1,0,0,1.1,0,0", contentMatrix.Text);

                Mouse.Scroll(-1);
                Assert.AreEqual("386, 249", renderSize.Text);
                Assert.AreEqual("Identity", contentMatrix.Text);
            }
        }
Exemplo n.º 5
0
        public void PanFromUniform()
        {
            using (var app = Application.AttachOrLaunch("Gu.Wpf.Geometry.Demo.exe", WindowName))
            {
                var window        = app.MainWindow;
                var renderSize    = window.FindTextBlock("Size");
                var contentMatrix = window.FindTextBlock("ContentMatrix");
                var zoomBox       = window.FindGroupBox("Zoombox");
                window.FindButton("Uniform").Invoke();
                window.WaitUntilResponsive();
                Assert.AreEqual("386, 249", renderSize.Text);
                Assert.AreEqual("0.6225,0,0,0.6225,99.625,-1.4210854715202E-14", contentMatrix.Text);

                Mouse.DragHorizontally(MouseButton.Left, zoomBox.Bounds.Center(), 50);
                window.WaitUntilResponsive();
                Assert.AreEqual("386, 249", renderSize.Text);
                Assert.AreEqual("0.6225,0,0,0.6225,149.625,-1.4210854715202E-14", contentMatrix.Text);

                Mouse.DragHorizontally(MouseButton.Left, zoomBox.Bounds.Center(), -50);
                window.WaitUntilResponsive();
                Assert.AreEqual("386, 249", renderSize.Text);
                Assert.AreEqual("0.6225,0,0,0.6225,99.625,-1.4210854715202E-14", contentMatrix.Text);

                Mouse.DragVertically(MouseButton.Left, zoomBox.Bounds.Center(), 50);
                window.WaitUntilResponsive();
                Assert.AreEqual("386, 249", renderSize.Text);
                Assert.AreEqual("0.6225,0,0,0.6225,99.625,50", contentMatrix.Text);

                Mouse.DragVertically(MouseButton.Left, zoomBox.Bounds.Center(), -50);
                window.WaitUntilResponsive();
                Assert.AreEqual("386, 249", renderSize.Text);
                Assert.AreEqual("0.6225,0,0,0.6225,99.625,-1.4210854715202E-14", contentMatrix.Text);
            }
        }
Exemplo n.º 6
0
        public void MouseWheelTopRight()
        {
            using (var app = Application.AttachOrLaunch("Gu.Wpf.Geometry.Demo.exe", WindowName))
            {
                var window        = app.MainWindow;
                var renderSize    = window.FindTextBlock("Size");
                var contentMatrix = window.FindTextBlock("ContentMatrix");
                Mouse.Position = window.FindGroupBox("Zoombox").Bounds.TopRight + new Vector(-1, 1);
                Assert.AreEqual("Identity", contentMatrix.Text);

                Mouse.Scroll(1);
                Assert.AreEqual("386, 249", renderSize.Text);
                Assert.AreEqual("1.05,0,0,1.05,-19.3,0", contentMatrix.Text);

                Mouse.Scroll(1);
                Assert.AreEqual("386, 249", renderSize.Text);
                Assert.AreEqual("1.1025,0,0,1.1025,-39.565,0", contentMatrix.Text);

                Mouse.Scroll(-1);
                Assert.AreEqual("386, 249", renderSize.Text);
                Assert.AreEqual("1.05,0,0,1.05,-19.3,0", contentMatrix.Text);

                Mouse.Scroll(-1);
                Assert.AreEqual("386, 249", renderSize.Text);
                Assert.AreEqual("1,0,0,1,3.19744231092045E-14,0", contentMatrix.Text);
            }
        }
Exemplo n.º 7
0
        public void MouseWheelBottomRight()
        {
            using (var app = Application.AttachOrLaunch(Application.FindExe("Gu.Wpf.Geometry.Demo.exe"), "ZoomWindow"))
            {
                var window        = app.MainWindow;
                var renderSize    = window.FindTextBlock("Size");
                var contentMatrix = window.FindTextBlock("ContentMatrix");
                var image         = window.FindFirstDescendant(ControlType.Image);
                Assert.AreEqual("Identity", contentMatrix.Text);

                var topLeft = image.Bounds.TopLeft();
                var size    = Size.Parse(renderSize.Text);
                Mouse.Click(MouseButton.Left, new Point(topLeft.X + size.Width - 1, topLeft.Y + size.Height - 1));
                Mouse.Scroll(1);
                app.WaitWhileBusy();
                app.WaitWhileBusy();
                var matrix = Matrix.Parse(contentMatrix.Text);
                Assert.AreEqual(1.05, matrix.M11, 1E-3);
                Assert.AreEqual(1.05, matrix.M22, 1E-3);
                var expectedOffsetX = -0.05 * size.Width;
                Assert.AreEqual(expectedOffsetX, matrix.OffsetX, 1E-1);
                var expectedOffsetY = -0.05 * size.Height;
                Assert.AreEqual(expectedOffsetY, matrix.OffsetY, 1E-1);
            }
        }
Exemplo n.º 8
0
        public void PanFromUniform()
        {
            using var app = Application.AttachOrLaunch("Gu.Wpf.Geometry.Demo.exe", WindowName);
            var window        = app.MainWindow;
            var renderSize    = window.FindTextBlock("Size");
            var contentMatrix = window.FindTextBlock("ContentMatrix");
            var zoomBox       = window.FindGroupBox("Zoombox");

            window.FindButton("Uniform").Invoke();
            Assert.AreEqual("386, 248", renderSize.Text);
            Assert.AreEqual("0.62,0,0,0.62,100,0", contentMatrix.Text);

            Mouse.DragHorizontally(MouseButton.Left, zoomBox.Bounds.Center(), 50);
            Assert.AreEqual("386, 248", renderSize.Text);
            Assert.AreEqual("0.62,0,0,0.62,150,0", contentMatrix.Text);

            Mouse.DragHorizontally(MouseButton.Left, zoomBox.Bounds.Center(), -50);
            Assert.AreEqual("386, 248", renderSize.Text);
            Assert.AreEqual("0.62,0,0,0.62,100,0", contentMatrix.Text);

            Mouse.DragVertically(MouseButton.Left, zoomBox.Bounds.Center(), 50);
            Assert.AreEqual("386, 248", renderSize.Text);
            Assert.AreEqual("0.62,0,0,0.62,100,50", contentMatrix.Text);

            Mouse.DragVertically(MouseButton.Left, zoomBox.Bounds.Center(), -50);
            Assert.AreEqual("386, 248", renderSize.Text);
            Assert.AreEqual("0.62,0,0,0.62,100,0", contentMatrix.Text);
        }
Exemplo n.º 9
0
        public static void ChangeScopeVisibility(Visibility notVisible)
        {
            using var app = Application.AttachOrLaunch(ExeFileName, WindowName);
            var window             = app.MainWindow;
            var scope              = window.FindGroupBox("Scope");
            var node               = window.FindGroupBox("Node");
            var visibilityComboBox = window.FindComboBox("ScopeVisibilityComboBox");

            Assert.AreEqual("HasError: False", scope.FindTextBlock("HasErrorTextBlock").Text);
            CollectionAssert.IsEmpty(scope.GetErrors());

            Assert.AreEqual("Children: 0", node.FindTextBlock("ChildCountTextBlock").Text);
            Assert.AreEqual("HasError: False", node.FindTextBlock("HasErrorTextBlock").Text);
            CollectionAssert.IsEmpty(node.GetErrors());
            Assert.AreEqual("Gu.Wpf.ValidationScope.ValidNode", node.FindTextBlock("NodeTypeTextBlock").Text);

            window.FindTextBox("TextBox").Text = "a";
            var expectedErrors = new[] { "Value 'a' could not be converted." };

            Assert.AreEqual("HasError: True", scope.FindTextBlock("HasErrorTextBlock").Text);
            CollectionAssert.AreEqual(expectedErrors, scope.GetErrors());

            Assert.AreEqual("Children: 1", node.FindTextBlock("ChildCountTextBlock").Text);
            Assert.AreEqual("HasError: True", node.FindTextBlock("HasErrorTextBlock").Text);
            CollectionAssert.AreEqual(expectedErrors, node.GetErrors());
            Assert.AreEqual("Gu.Wpf.ValidationScope.ScopeNode", node.FindTextBlock("NodeTypeTextBlock").Text);

            visibilityComboBox.Select(notVisible.ToString());
            Assert.AreEqual("HasError: False", scope.FindTextBlock("HasErrorTextBlock").Text);
            CollectionAssert.IsEmpty(scope.GetErrors());

            Assert.AreEqual("Children: 0", node.FindTextBlock("ChildCountTextBlock").Text);
            Assert.AreEqual("HasError: False", node.FindTextBlock("HasErrorTextBlock").Text);
            CollectionAssert.IsEmpty(node.GetErrors());
            Assert.AreEqual("Gu.Wpf.ValidationScope.ValidNode", node.FindTextBlock("NodeTypeTextBlock").Text);

            visibilityComboBox.Select("Visible");
            Assert.AreEqual("HasError: True", scope.FindTextBlock("HasErrorTextBlock").Text);
            CollectionAssert.AreEqual(expectedErrors, scope.GetErrors());

            Assert.AreEqual("Children: 1", node.FindTextBlock("ChildCountTextBlock").Text);
            Assert.AreEqual("HasError: True", node.FindTextBlock("HasErrorTextBlock").Text);
            CollectionAssert.AreEqual(expectedErrors, node.GetErrors());
            Assert.AreEqual("Gu.Wpf.ValidationScope.ScopeNode", node.FindTextBlock("NodeTypeTextBlock").Text);

            window.FindTextBox("TextBox").Text = "1";
            Assert.AreEqual("HasError: False", scope.FindTextBlock("HasErrorTextBlock").Text);
            CollectionAssert.IsEmpty(scope.GetErrors());

            Assert.AreEqual("Children: 0", node.FindTextBlock("ChildCountTextBlock").Text);
            Assert.AreEqual("HasError: False", node.FindTextBlock("HasErrorTextBlock").Text);
            CollectionAssert.IsEmpty(node.GetErrors());
            Assert.AreEqual("Gu.Wpf.ValidationScope.ValidNode", node.FindTextBlock("NodeTypeTextBlock").Text);
        }
        public void spy()
        {
            var curtime = DateTime.Now;

            try
            {
                log.Info("BEGIN SPY FROM HIGHLIGHT FORM");
                Process targetProcess = WindowInteraction.GetProcess(ProcessName);
                //WindowInteraction.FocusWindow(targetProcess);
                App         = Gu.Wpf.UiAutomation.Application.Attach(targetProcess.Id);
                MainWindow  = App.MainWindow;
                ElementList = MainWindow.FindAll(TreeScope.Descendants, new PropertyCondition(AutomationElement.FrameworkIdProperty, "WPF"));
                dataGridView1.Rows.Clear();
                dataGridView1.AllowUserToAddRows = true;

                SpyObjectList = new SpyObject[ElementList.Count];
                int SpyObjectIndex = 0;

                //comboBox1.Enabled = false;

                for (int i = 0; i < ElementList.Count; i++)
                {
                    SpyObjectList[SpyObjectIndex]       = new SpyObject();
                    SpyObjectList[SpyObjectIndex].index = SpyObjectIndex;
                    if (ElementList[i].AutomationId == "" && SpyObjectIndex - 1 > 0 && ElementList[i - 1].Name != "" && ElementList[i].Name == "")
                    {
                        SpyObjectList[SpyObjectIndex].automationId = (ElementList[i - 1].Name + "_" + ElementList[i].ClassName).Replace(" ", "_").Replace(":", "");
                    }
                    else
                    {
                        SpyObjectList[SpyObjectIndex].automationId = ElementList[i].AutomationId;
                    }
                    SpyObjectList[SpyObjectIndex].name = ElementList[i].Name;
                    SpyObjectList[SpyObjectIndex].type = ElementList[i].ClassName;
                    DataGridViewRow row = (DataGridViewRow)dataGridView1.Rows[i].Clone();
                    row.Cells[0].Value = SpyObjectList[SpyObjectIndex].index;
                    row.Cells[1].Value = SpyObjectList[SpyObjectIndex].automationId;
                    row.Cells[2].Value = SpyObjectList[SpyObjectIndex].name;
                    row.Cells[3].Value = SpyObjectList[SpyObjectIndex].type;
                    dataGridView1.Rows.Add(row);
                    SpyObjectIndex++;
                }
                log.Info("SPY DONE OF HIGHLIGHT");



                dataGridView1.AllowUserToAddRows = false;
            }
            catch (Exception ex)
            {
                log.Error("ERROR CODE: " + ex.HResult + "  -----  " + "detail: " + ex.Message);
            }
        }
Exemplo n.º 11
0
 public static void SetUp()
 {
     if (Application.TryAttach(ExeFileName, WindowName, out var app))
     {
         using (app)
         {
             var window = app.MainWindow;
             window.FindTextBox("TextBox").Text = "0";
             Keyboard.Type(Key.TAB);
         }
     }
 }
Exemplo n.º 12
0
        public void GetAUTProc()
        {
            IntPtr hWnd = flexProc[0].MainWindowHandle;
            if (hWnd != IntPtr.Zero)
            {
                SetForegroundWindow(hWnd);
                ShowWindow(hWnd, SW_MAXIMIZE);
            }

            App = Gu.Wpf.UiAutomation.Application.Attach(flexProc[0].Id);
            MainWindow = App.MainWindow;
            Element = SearchbyFramework("WPF");
            Console.WriteLine("AUT's ProcessId: " + MainWindow.ProcessId);
        }
Exemplo n.º 13
0
        public void SetsToUniformInCodeBehind()
        {
            using var app = Application.Launch("Gu.Wpf.Geometry.Demo.exe", "ZoomboxContentChanged");
            var window = app.MainWindow;

            Wait.For(TimeSpan.FromMilliseconds(200));
            window.FindButton("Uniform").Invoke();
            var zoomBox      = window.FindGroupBox("Zoom");
            var imageSources = window.FindComboBox("ImageSources");

            using var expected         = zoomBox.Capture();
            imageSources.SelectedIndex = 1;
            window.FindButton("UniformToFill").Invoke();
            imageSources.SelectedIndex = 0;
            ImageAssert.AreEqual(expected, zoomBox);
        }
        public void highlight(int objectID)
        {
            var curtime = DateTime.Now;

            try
            {
                log.Info("BEGIN HIGHLIGHT");
                Process targetProcess = WindowInteraction.GetProcess(ProcessName);

                App           = Gu.Wpf.UiAutomation.Application.Attach(targetProcess.Id);
                MainWindow    = App.MainWindow;
                ElementList   = MainWindow.FindAll(TreeScope.Descendants, new PropertyCondition(AutomationElement.FrameworkIdProperty, "WPF"));
                SpyObjectList = new SpyObject[ElementList.Count];
                int SpyObjectIndex = 0;
                for (int i = 0; i < ElementList.Count; i++)
                {
                    SpyObjectList[SpyObjectIndex]       = new SpyObject();
                    SpyObjectList[SpyObjectIndex].index = SpyObjectIndex;
                    if (ElementList[i].AutomationId == "" && SpyObjectIndex - 1 > 0 && ElementList[i - 1].Name != "" && ElementList[i].Name == "")
                    {
                        SpyObjectList[SpyObjectIndex].automationId = (ElementList[i - 1].Name + "_" + ElementList[i].ClassName).Replace(" ", "_").Replace(":", "");
                    }
                    else
                    {
                        SpyObjectList[SpyObjectIndex].automationId = ElementList[i].AutomationId;
                    }
                    SpyObjectList[SpyObjectIndex].name = ElementList[i].Name;
                    SpyObjectList[SpyObjectIndex].type = ElementList[i].ClassName;


                    if (SpyObjectList[SpyObjectIndex].index == objectID)
                    {
                        ElementList[SpyObjectList[SpyObjectIndex].index].DrawHighlight(true, Color.Red, TimeSpan.FromSeconds(2));
                    }

                    SpyObjectIndex++;
                }
                log.Info("DONE HIGHLIGHT");
            }
            catch (Exception ex)
            {
                log.Error("ERROR CODE: " + ex.HResult + "  -----  " + "detail: " + ex.Message);
            }
        }
Exemplo n.º 15
0
 public void ZoomUniformToFill()
 {
     using (var app = Application.AttachOrLaunch(Application.FindExe("Gu.Wpf.Geometry.Demo.exe"), "ZoomWindow"))
     {
         var window        = app.MainWindow;
         var renderSize    = window.FindTextBlock("Size");
         var contentMatrix = window.FindTextBlock("ContentMatrix");
         window.FindButton("UniformToFill").Click();
         var size          = Size.Parse(renderSize.Text);
         var expectedScale = Math.Max(size.Width / 300, size.Height / 400);
         var matrix        = Matrix.Parse(contentMatrix.Text);
         Assert.AreEqual(expectedScale, matrix.M11, 1E-3);
         Assert.AreEqual(expectedScale, matrix.M22, 1E-3);
         var expectedOffsetX = size.Width < 300 ? (size.Width - (expectedScale * 300)) / 2 : 0;
         Assert.AreEqual(expectedOffsetX, matrix.OffsetX, 1E-3);
         var expectedOffsetY = size.Height < 400 ? (size.Height - (expectedScale * 400)) / 2 : 0;
         Assert.AreEqual(expectedOffsetY, matrix.OffsetY, 1E-3);
     }
 }
Exemplo n.º 16
0
        public void Decrease()
        {
            using var app = Application.AttachOrLaunch("Gu.Wpf.Geometry.Demo.exe", WindowName);
            var window        = app.MainWindow;
            var renderSize    = window.FindTextBlock("Size");
            var contentMatrix = window.FindTextBlock("ContentMatrix");

            window.FindButton("Uniform").Invoke();
            var zoomButton = window.FindButton("Decrease");

            Assert.AreEqual(true, zoomButton.IsEnabled);
            zoomButton.Click();
            Assert.AreEqual("386, 248", renderSize.Text);
            Assert.AreEqual("0.31,0,0,0.31,146.5,62", contentMatrix.Text);

            Assert.AreEqual(true, zoomButton.IsEnabled);
            zoomButton.Click();
            Assert.AreEqual("386, 248", renderSize.Text);
            Assert.AreEqual("0.155,0,0,0.155,169.75,93", contentMatrix.Text);
        }
Exemplo n.º 17
0
        public void Increase()
        {
            using var app = Application.AttachOrLaunch("Gu.Wpf.Geometry.Demo.exe", WindowName);
            var window        = app.MainWindow;
            var renderSize    = window.FindTextBlock("Size");
            var contentMatrix = window.FindTextBlock("ContentMatrix");

            window.FindButton("Uniform").Invoke();
            var zoomButton = window.FindButton("Increase");

            Assert.AreEqual(true, zoomButton.IsEnabled);
            zoomButton.Click();
            Assert.AreEqual("386, 248", renderSize.Text);
            Assert.AreEqual("1.24,0,0,1.24,7,-124", contentMatrix.Text);

            Assert.AreEqual(true, zoomButton.IsEnabled);
            zoomButton.Click();
            Assert.AreEqual("386, 248", renderSize.Text);
            Assert.AreEqual("2.48,0,0,2.48,-179,-372", contentMatrix.Text);
        }
Exemplo n.º 18
0
        public void ZoomUniformToFill()
        {
            using var app = Application.AttachOrLaunch("Gu.Wpf.Geometry.Demo.exe", WindowName);
            var window        = app.MainWindow;
            var renderSize    = window.FindTextBlock("Size");
            var contentMatrix = window.FindTextBlock("ContentMatrix");
            var zoomButton    = window.FindButton("UniformToFill");

            Assert.AreEqual(true, zoomButton.IsEnabled);
            zoomButton.Click();
            Assert.AreEqual("386, 248", renderSize.Text);
            Assert.AreEqual("1.28667,0,0,1.28667,0,-133.33333", contentMatrix.Text);

            window.FindButton("None").Click();
            Assert.AreEqual("386, 248", renderSize.Text);
            Assert.AreEqual("Identity", contentMatrix.Text);

            Assert.AreEqual(true, zoomButton.IsEnabled);
            zoomButton.Click();
            Assert.AreEqual("386, 248", renderSize.Text);
            Assert.AreEqual("1.28667,0,0,1.28667,0,-133.33333", contentMatrix.Text);
        }
Exemplo n.º 19
0
        public void MouseWheelTopLeft()
        {
            using (var app = Application.AttachOrLaunch(Application.FindExe("Gu.Wpf.Geometry.Demo.exe"), "ZoomWindow"))
            {
                var window = app.MainWindow;
                window.FindButton("None").Invoke();
                var contentMatrix = window.FindTextBlock("ContentMatrix");
                var image         = window.FindFirstDescendant(ControlType.Image);
                var topLeft       = image.Bounds.TopLeft();
                Mouse.Position = topLeft;
                Assert.AreEqual("Identity", contentMatrix.Text);

                Mouse.Scroll(1);
                app.WaitWhileBusy();
                app.WaitWhileBusy();
                var matrix = Matrix.Parse(contentMatrix.Text);
                Assert.AreEqual(1.05, matrix.M11, 1E-3);
                Assert.AreEqual(1.05, matrix.M22, 1E-3);
                Assert.AreEqual(0, matrix.OffsetX, 1E-2);
                Assert.AreEqual(0, matrix.OffsetY, 1E-2);
            }
        }
Exemplo n.º 20
0
        public void ZoomUniform()
        {
            using (var app = Application.AttachOrLaunch("Gu.Wpf.Geometry.Demo.exe", WindowName))
            {
                var window        = app.MainWindow;
                var renderSize    = window.FindTextBlock("Size");
                var contentMatrix = window.FindTextBlock("ContentMatrix");

                var zoomButton = window.FindButton("Uniform");
                Assert.AreEqual(true, zoomButton.IsEnabled);
                zoomButton.Click();
                Assert.AreEqual("386, 249", renderSize.Text);
                Assert.AreEqual("0.6225,0,0,0.6225,99.625,-1.4210854715202E-14", contentMatrix.Text);

                window.FindButton("None").Click();
                Assert.AreEqual("386, 249", renderSize.Text);
                Assert.AreEqual("Identity", contentMatrix.Text);

                Assert.AreEqual(true, zoomButton.IsEnabled);
                zoomButton.Click();
                Assert.AreEqual("386, 249", renderSize.Text);
                Assert.AreEqual("0.6225,0,0,0.6225,99.625,-1.4210854715202E-14", contentMatrix.Text);
            }
        }
        public static void DoCapture(string Proc)
        {
            var curtime = DateTime.Now;

            var path      = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            var imagePath = path + @"\Botsina\SpyObjects\";

            System.IO.FileInfo file = new System.IO.FileInfo(imagePath);

            if (file.Directory.Exists)
            {
                DirectoryInfo dir = new DirectoryInfo(imagePath);

                foreach (FileInfo fi in dir.GetFiles())
                {
                    fi.Delete();
                }
            }
            else
            {
                file.Directory.Create();
            }

            try
            {
                //this.Hide();

                log.Info("BEGIN CAPTURE TO FILE");

                file.Directory.Create();

                Process targetProcess = WindowInteraction.GetProcess(Proc);

                App           = Gu.Wpf.UiAutomation.Application.Attach(targetProcess.Id);
                MainWindow    = App.MainWindow;
                ElementList   = MainWindow.FindAll(TreeScope.Descendants, new PropertyCondition(AutomationElement.FrameworkIdProperty, "WPF"));
                SpyObjectList = new SpyObject[ElementList.Count];
                int SpyObjectIndex = 0;

                SendKeys.Send("{PRTSC}");

                Image img = Clipboard.GetImage();

                for (int i = 0; i < ElementList.Count; i++)
                {
                    SpyObjectList[SpyObjectIndex]       = new SpyObject();
                    SpyObjectList[SpyObjectIndex].index = SpyObjectIndex;
                    if (ElementList[i].AutomationId == "" && SpyObjectIndex - 1 > 0 && ElementList[i - 1].Name != "" && ElementList[i].Name == "")
                    {
                        SpyObjectList[SpyObjectIndex].automationId = (ElementList[i - 1].Name + "_" + ElementList[i].ClassName).Replace(" ", "_").Replace(":", "");
                    }
                    else
                    {
                        SpyObjectList[SpyObjectIndex].automationId = ElementList[i].AutomationId;
                    }
                    SpyObjectList[SpyObjectIndex].name = ElementList[i].Name;
                    SpyObjectList[SpyObjectIndex].type = ElementList[i].ClassName;

                    if ((SpyObjectList[SpyObjectIndex].type == "ComboBox" ||
                         SpyObjectList[SpyObjectIndex].type == "ComboBoxEdit" ||
                         SpyObjectList[SpyObjectIndex].type == "DataGrid" ||
                         SpyObjectList[SpyObjectIndex].type == "TextBox" ||
                         SpyObjectList[SpyObjectIndex].type == "Button" ||
                         SpyObjectList[SpyObjectIndex].type == "RadioButton" ||
                         SpyObjectList[SpyObjectIndex].type == "AutoCompleteCombobox")

                        && SpyObjectList[SpyObjectIndex].automationId.Contains("PART") != true)
                    {
                        if (ElementList[SpyObjectIndex].Bounds.IsEmpty == false && ElementList[SpyObjectIndex].IsOffscreen == false)
                        {
                            ElementList[SpyObjectIndex].CaptureToFile(imagePath + SpyObjectIndex + ".png");
                            log.Info(ElementList[SpyObjectIndex].ClassName);
                        }
                    }

                    SpyObjectIndex++;
                }
                img.Save(imagePath + "thisScreen" + ".png");
                log.Info("DONE CAPTURE TO FILE");

                //this.Show();
            }
            catch (Exception ex)
            {
                log.Error("ERROR CODE: " + ex.HResult + "  -----  " + "detail: " + ex.Message);
                //this.Show();
            }
        }
Exemplo n.º 22
0
 public void OneTimeTearDown()
 {
     Application.KillLaunched(Application.FindExe("Gu.Wpf.Geometry.Demo.exe"));
 }
Exemplo n.º 23
0
 public static void OneTimeTearDown() => Application.KillLaunched(ExeFileName);
Exemplo n.º 24
0
 public virtual void OneTimeSetUp()
 {
     this.application?.Dispose();
     this.application = Application.Launch(Application.FindExe("Gu.Wpf.Media.Demo.exe"), this.WindowName);
 }
        public static void ClearValue(string Proc)
        {
            var curtime = DateTime.Now;

            ExceptionCode excode = new ExceptionCode();

            try
            {
                log.Info("BEGIN CLEAR VALUE");
                Process targetProcess = WindowInteraction.GetProcess(Proc);
                App        = Application.Attach(targetProcess.Id);
                MainWindow = App.MainWindow;
                WindowInteraction.FocusWindow(targetProcess);

                ElementListWPF = GrabAUT.SearchbyFramework("WPF");

                //ElementListWin32 = DoSpy.SearchbyFramework("Win32");

                //if (ElementListWin32[0].AsMessageBox().)
                //{
                //    ElementListWin32[0].AsMessageBox().Close();
                //}

                int id = 0;

                foreach (UiElement UIE in ElementListWPF)
                {
                    if (UIE.ControlType.ProgrammaticName == "ControlType.Edit")
                    {
                        if (!UIE.AsTextBox().IsReadOnly)
                        {
                            UIE.AsTextBox().Enter("");
                            //(UIE.AutomationElement.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern).SetValue("");
                            log.Info(id + " CLEARED");
                        }
                    }
                    else if (UIE.ClassName == "CheckBox")
                    {
                        if (UIE.AsCheckBox().IsChecked == true)
                        {
                            UIE.AsCheckBox().Click();
                            log.Info(id + " UNCHECKED");
                        }
                    }

                    id++;
                }
                theMessage = curtime + " - CLEAR SCREEN COMPLETED";
            }
            catch (Exception ex)
            {
                if (ex.HResult == excode.INVALID_SCRIPT)
                {
                    log.Error("CANNOT USE THE CURRENT SCRIPT ON THIS SCREEN");
                    theMessage = curtime + " - CANNOT USE THE CURRENT SCRIPT ON THIS SCREEN";
                }
                else
                {
                    log.Error(ex.Message);
                }
            }
        }
Exemplo n.º 26
0
        // SPY FUNCTION
        public void Spy()
        {
            IntPtr hWnd = flexProc[0].MainWindowHandle;
            if (hWnd != IntPtr.Zero)
            {
                SetForegroundWindow(hWnd);
                ShowWindow(hWnd, SW_MAXIMIZE);
            }
            App = Gu.Wpf.UiAutomation.Application.Attach(flexProc[0].Id);
            MainWindow = App.MainWindow;

            Element = MainWindow.FindAll(TreeScope.Descendants, new PropertyCondition(AutomationElement.FrameworkIdProperty, "WPF"));
            try
            {

                //Clear SpyIMG files
                deletefiles();

                var curtime = DateTime.Now;
                var day = curtime.Day;
                var month = curtime.Month;
                var year = curtime.Year;

                var sec = curtime.Second;
                var hour = curtime.Hour;
                var minute = curtime.Minute;
                var longTimeString = DateTime.Now.ToOADate();


                var reformat = day + "-" + month + "-" + year + "__" + hour + "-" + minute + "-" + sec + "-";


                using (System.IO.StreamWriter file =
                new System.IO.StreamWriter(@"C:\Users\" + SR.username + @"\Documents\GUWPF\" + reformat + "SpyResult.json"))
                {
                    this.WindowState = FormWindowState.Minimized;
                    Thread.Sleep(500);
                    SR.currenttime = longTimeString.ToString();

                    id = 0;
                    foreach (UiElement UIE in Element)
                    {
                        if (!UIE.Bounds.IsEmpty)
                        {
                            SR.index = id;
                            SR.autoDI = UIE.AutomationId;
                            SR.classname = UIE.ClassName;
                            SR.name = UIE.Name;
                            SR.directory = @"C:\Users\" + SR.username + @"\Documents\GUWPF\SpyIMG\" + SR.index + " - " + SR.classname + ".png";
                            //SR.currenttime = curtime.ToString();


                            if (UIE.AutomationId == "")
                                SR.autoDI = "No AutomationID";
                            if (UIE.Name == "")
                                SR.name = "No Name";

                            UIE.CaptureToFile(@"C:\Users\" + SR.username + @"\Documents\GUWPF\SpyIMG\" + SR.index + " - " + SR.classname + ".png");
                            id++;



                            listBox1.Items.Add("ID: " + SR.index + " - " + SR.autoDI + " - " + SR.classname + " - " + SR.name);
                            string ObjectUI = JsonConvert.SerializeObject(SR, Newtonsoft.Json.Formatting.Indented);

                            if (SR.index == 0)
                            {
                                file.WriteLine("[");
                                file.WriteLine(ObjectUI + ",");
                            }
                            else if (SR.index == Element.Count - 1)
                            {
                                file.WriteLine(ObjectUI);
                                file.WriteLine("]");
                            }

                            else file.WriteLine(ObjectUI + ",");

                        }

                    }
                    file.WriteLine("]");
                    this.WindowState = FormWindowState.Normal;
                }
            }
            catch (Exception err)
            {
                listBox1.Items.Add(id + " - " + SR.classname + " - " + err.Message);
            }

        }