Ejemplo n.º 1
0
        private MouseEventHandler HandleMouseMove(ISeleniumAdapter selenium)
        {
            return(delegate(object o, MouseEventArgs args)
            {
                this.HoverX = ((MouseEventArgs)args).X;
                this.HoverY = ((MouseEventArgs)args).Y;

                var windowRect = selenium.BrowserWindowScreenRectangle;
                var topLeft = new Point(windowRect.Left, windowRect.Top);
                var bottomRight = new Point(windowRect.Right, windowRect.Bottom);

                UserInteropAdapter.ScreenToGraphics(ref topLeft);
                UserInteropAdapter.ScreenToGraphics(ref bottomRight);
                float height = Math.Abs(bottomRight.Y - topLeft.Y);
                float width = Math.Abs(bottomRight.X - topLeft.X);
                var contentTopLeft = new Point(windowRect.Left, windowRect.Top);
                contentTopLeft.X += selenium.ContentOffsetX();
                contentTopLeft.Y += selenium.ContentOffsetY();
                //

                var point = new Point(this.HoverX, this.HoverY);
                selenium.ConvertFromScreenToWindow(ref point);
                selenium.ConvertFromWindowToPage(ref point);

                var elements = selenium.WebDriver.GetElementByCoordinates(point.X, point.Y);

                var element = elements.LastOrDefault(x => x.IsClickable());

                //Console.Out.Wipe();
                //Console.Out.BeginRewritableLine();
                //Console.Out.WriteColored(ConsoleColor.Yellow, $"X {HoverX:D4} Y {HoverY:D4} ");
                //Console.Out.WriteColored(ConsoleColor.Green, $"{(element == null ? "                        " : $" -- Button {element.Text} --")}");


                //Console.Out.WriteColored(ConsoleColor.Magenta, $"width {width} height {height} ");


                if (element != null)
                {
                    var p = new Point(element.Location.X, element.Location.Y);

                    selenium.ConvertFromPageToWindow(ref p);
                    selenium.ConvertFromWindowToScreen(ref p);
                    selenium.ConvertFromScreenToGraphics(ref p);

                    ElementLocation = p;
                    ElementSize = element.Size;
                }
                else
                {
                    ElementLocation = default(Point);
                }
            });
        }
Ejemplo n.º 2
0
        private void Render(Graphics backBuffer, ISeleniumAdapter selenium)
        {
            var windowRect  = selenium.BrowserWindowScreenRectangle;
            var topLeft     = new Point(windowRect.Left, windowRect.Top);
            var bottomRight = new Point(windowRect.Right, windowRect.Bottom);

            UserInteropAdapter.ScreenToGraphics(ref topLeft);
            UserInteropAdapter.ScreenToGraphics(ref bottomRight);

            backBuffer.Clear(Color.Black);

            float height = Math.Abs(bottomRight.Y - topLeft.Y);
            float width  = Math.Abs(bottomRight.X - topLeft.X);

            var contentTopLeft = new Point(windowRect.Left, windowRect.Top);

            contentTopLeft.X += selenium.ContentOffsetX();
            contentTopLeft.Y += selenium.ContentOffsetY();
            if (!ClickThrough)
            {
                backBuffer.FillRectangle(new SolidBrush(BackgroundColor), contentTopLeft.X + 8, contentTopLeft.Y, width - selenium.ContentOffsetX() - 16, height - selenium.ContentOffsetY() - 18);
            }

            backBuffer.FillRectangle(new SolidBrush(HeaderColor), topLeft.X + 8, topLeft.Y + 22, width - 16, 24);
            backBuffer.DrawRectangle(new Pen(HeaderColor, 10), topLeft.X + 8, topLeft.Y, width - 16, height - 8);

            backBuffer.DrawString(Title, new Font(FontFamily.GenericSansSerif, 14), new SolidBrush(Color.FromArgb(255, 10, 10, 10)), topLeft.X + 340, topLeft.Y + 22);

            if (ElementLocation != default(Point))
            {
                backBuffer.DrawRectangle(new Pen(Color.FromArgb(255, 0, 50, 150), 4),
                                         ElementLocation.X - 2, ElementLocation.Y - 2, ElementSize.Width + 4, ElementSize.Height + 4);
                backBuffer.FillRectangle(new SolidBrush(Color.FromArgb(255, 100, 255, 255)),
                                         ElementLocation.X - 2, ElementLocation.Y - 2, ElementSize.Width + 4, ElementSize.Height + 4);
            }

            foreach (var artifact in Artifacts)
            {
                var rectangle = new Rectangle(artifact.Rectangle.X, artifact.Rectangle.Y, artifact.Rectangle.Width, artifact.Rectangle.Height);

                _seleniumAdapter.ConvertFromPageToWindow(ref rectangle);
                _seleniumAdapter.ConvertFromWindowToScreen(ref rectangle);
                _seleniumAdapter.ConvertFromScreenToGraphics(ref rectangle);

                backBuffer.DrawRectangle(new Pen(artifact.LineColor, 6),
                                         rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
                backBuffer.FillRectangle(new SolidBrush(artifact.BackgroundColor),
                                         rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);

                backBuffer.DrawString(artifact.Text, new Font(FontFamily.GenericSansSerif, 12), new SolidBrush(Color.FromArgb(255, 10, 10, 10)), rectangle.X, rectangle.Y);
            }
        }
Ejemplo n.º 3
0
        public static void HighlightElements(Action action, ISeleniumAdapter seleniumAdapter, IEnumerable <IBufferedElement> elements, Color innerColor, Color outerColor, int selectionIndex, Color selectionColor, int xOffset = 0, int yOffset = 0)
        {
            using (var overlay = new Overlay())
            {
                if (selectionIndex != -1 && elements.Count() > selectionIndex)
                {
                    seleniumAdapter.PutElementOnScreen(elements.ElementAt(selectionIndex).WebElement);
                }
                var handle = seleniumAdapter.BrowserHandle;
                overlay.Init();
                int i = 0;
                foreach (var element in elements)
                {
                    i++;

                    var p = new Point(element.Rectangle.Left, element.Rectangle.Top);
                    seleniumAdapter.ConvertFromPageToWindow(ref p);

                    overlay.DrawStuff(handle, i, p.X, p.Y,
                                      overlay.Graphics, element.Rectangle.Width, element.Rectangle.Height,
                                      i == (1 + selectionIndex) ? selectionColor : innerColor,
                                      outerColor);

                    if (xOffset != 0 || yOffset != 0)
                    {
                        overlay.Graphics.DrawLine(Pens.Red,
                                                  p.X + element.Rectangle.Width / 2,
                                                  p.Y + element.Rectangle.Height / 2,
                                                  p.X + element.Rectangle.Width / 2 + xOffset,
                                                  p.Y + element.Rectangle.Height / 2 + yOffset);
                    }
                }

                Console.Out.WriteColoredLine(ConsoleColor.White,
                                             $"{elements.Count()} elements highlighted on screen. Press enter to continue (highlighting will disappear).");


                action.Invoke();
            }
        }
        private IEnumerable <IBufferedElement> OnScreen(IEnumerable <IBufferedElement> bufferedElements)
        {
            var chromeHandle = _seleniumAdapter.BrowserHandle;
            var browserBox   = new UserBindings.RECT();

            UserBindings.GetWindowRect(chromeHandle, ref browserBox);
            foreach (var e in bufferedElements)
            {
                _seleniumAdapter.PutElementOnScreen(e.WebElement);

                var refreshedPosition = e.WebElement.AsBufferedElement().Rectangle;

                var centerX = refreshedPosition.X + refreshedPosition.Width / 2;
                var centerY = refreshedPosition.Y + refreshedPosition.Height / 2;

                var p = new Point(centerX, centerY);
                _seleniumAdapter.ConvertFromPageToWindow(ref p);

                if (p.X >= 0 && p.X <= browserBox.Right && p.Y >= 0 && p.Y <= browserBox.Bottom)
                {
                    yield return(e);
                }
            }
        }