Пример #1
0
        public static void SendText(IntPtr wndHandle, string s, Point clientPoint)
        {
            UserBindings.ClientToScreen(wndHandle, ref clientPoint);

            var inputs = new List <UserBindings.INPUT>();

            foreach (var c in s.ToCharArray())
            {
                if (c == '\t')
                {
                    inputs.Add(CreateInput(KeyPressInputType.Down, keyCode: 0x09));
                    inputs.Add(CreateInput(KeyPressInputType.Up, keyCode: 0x09));
                }
                else if (c == '\n')
                {
                    inputs.Add(CreateInput(KeyPressInputType.Down, keyCode: 0x0D));
                    inputs.Add(CreateInput(KeyPressInputType.Up, keyCode: 0x0D));
                }
                else
                {
                    inputs.AddRange(GetCharacterInputs(c));
                }
            }
            UserBindings.SendInput((uint)inputs.Count, inputs.ToArray(), Marshal.SizeOf(typeof(UserBindings.INPUT)));
        }
Пример #2
0
        public override object Run()
        {
            if (Javascript)
            {
                try
                {
                    var element = Selenium.WebDriver.FindInput(What, Where);
                    element.SendKeys(Text);
                    return(element);
                }
                catch (Exception)
                {
                    throw new ApplicationException($"Element {What} was not found");
                }
            }
            else
            {
                var element = Selenium.WebDriver.FindInput(What, Where);

                var handle = Selenium.GetChromeHandle();

                var screenLocation = Selenium.PutElementOnScreen(element);

                UserInteropAdapter.ClickOnPoint(handle, screenLocation);
                Thread.Sleep(50);
                UserInteropAdapter.SendText(handle, Text, screenLocation);
                Thread.Sleep(50);
                UserBindings.SetForegroundWindow(UserBindings.GetConsoleWindow());

                return(element);
            }
        }
Пример #3
0
        public static void PressOnPoint(IntPtr wndHandle, Point clientPoint)
        {
            var oldPosition = Cursor.Position;

            UserBindings.ClientToScreen(wndHandle, ref clientPoint);
            Cursor.Position = new Point(clientPoint.X, clientPoint.Y);

            var inputMouseDown = new UserBindings.INPUT {
                Type = 0
            };

            inputMouseDown.Data.Mouse.Flags = 0x0002;

            var inputMouseUp = new UserBindings.INPUT {
                Type = 0
            };

            inputMouseUp.Data.Mouse.Flags = 0x0004;

            var inputs = new[] { inputMouseDown };

            UserBindings.SendInput((uint)inputs.Length, inputs, Marshal.SizeOf(typeof(UserBindings.INPUT)));

            Cursor.Position = oldPosition;
        }
Пример #4
0
        public Point PutElementOnScreen(IWebElement element)
        {
            ((IJavaScriptExecutor)WebDriver).ExecuteScript("arguments[0].scrollIntoView(true);", element);
            //((IJavaScriptExecutor)WebDriver).ExecuteScript("scrollBy(0,-200);");

            var location = GetLocation(element);

            var size = element.Size;

            var browserBox = new UserBindings.RECT();

            UserBindings.GetWindowRect(BrowserHandle, ref browserBox);

            ScrollToCenterOfScreen(location, browserBox);

            location = GetLocation(element);

            var browserBarHeight = ContentOffsetY();
            var bb = ContentOffsetX();

            location.Y += (int)Math.Abs(browserBarHeight);
            location.Y += Math.Min(size.Height / 2, 8);
            location.X += Math.Min(size.Width / 2, 8);
            return(location);
        }
Пример #5
0
        public UserBindings.RECT GetBrowserBox()
        {
            var browserBox = new UserBindings.RECT();

            UserBindings.GetWindowRect(BrowserHandle, ref browserBox);
            return(browserBox);
        }
Пример #6
0
        public override object Run()
        {
            try
            {
                var elem = Selenium.WebDriver.GetElementByVisibleText(What, Where);

                if (elem == null)
                {
                    elem = Selenium.WebDriver.GetByTagNameAndLocation(new ButtonQuery(What));
                }

                if (Javascript)
                {
                    Selenium.WebDriver.Click(elem);
                }
                else
                {
                    var screenLocation = Selenium.PutElementOnScreen(elem);
                    UserInteropAdapter.ClickOnPoint(Selenium.GetChromeHandle(), screenLocation);
                    Thread.Sleep(50);
                    UserBindings.SetForegroundWindow(UserBindings.GetConsoleWindow());
                }
            }
            catch (Exception)
            {
                throw new ApplicationException($"Element was not found");
            }
            return(null);
        }
Пример #7
0
        /// <summary>
        /// Handle single user.
        /// </summary>
        /// <param name="entry">User LDAP object.</param>
        private void HandleUser(SearchResultEntry entry)
        {
            // Create CMS object from LDAP object
            var user = new User(
                LdapHelper.GetObjectGuid(entry),
                LdapHelper.GetAttributeString(entry.Attributes["name"], true),
                LdapHelper.IsUserEnabled(entry),
                UserBindings.Select(k => new KeyValuePair <string, string>(k.Cms, LdapHelper.GetAttributeString(entry.Attributes[k.Ldap]))).ToList());

            // Find existing object in LDAP replica
            var existing = Replica.Users.FirstOrDefault(u => u.Guid == user.Guid);

            if (LdapHelper.IsDeleted(entry))
            {
                if (existing != null)
                {
                    // Remove user
                    Sender.RemoveUser(existing);
                    Replica.Users.Remove(existing);
                }
            }
            else if (existing != null)
            {
                // Check if any attribute has changed
                var userXml = Sender.GetUser(user.Guid);

                if (!string.IsNullOrEmpty(userXml))
                {
                    bool userChanged =
                        User.InternalBindings.Any(
                            b =>
                            RestHelper.GetAttributeFromReponse(userXml, b.Value) !=
                            ((b.Key == "userAccountControl" ? LdapHelper.IsUserEnabled(entry).ToString().ToLowerInvariant() : LdapHelper.GetAttributeString(entry.Attributes[b.Key], b.Key == "name")) ?? string.Empty));
                    userChanged |=
                        UserBindings.Any(
                            b =>
                            RestHelper.GetAttributeFromReponse(userXml, b.Cms) !=
                            (LdapHelper.GetAttributeString(entry.Attributes[b.Ldap]) ?? string.Empty));

                    if (userChanged)
                    {
                        // Modify user
                        Sender.ModifyUser(user);
                    }
                }
            }
            else
            {
                // Add user
                long?userId = Sender.AddUser(user);

                if (userId != null)
                {
                    user.Id = userId.Value;
                    user.DistinguishedName = entry.DistinguishedName;
                    Replica.Users.Add(user);
                }
            }
        }
Пример #8
0
        public static void PressWithControl(IntPtr wndHandle, ushort c)
        {
            var inputs = new List <UserBindings.INPUT>();

            inputs.Add(CreateInput(KeyPressInputType.Down, keyCode: 0x11));
            inputs.Add(CreateInput(KeyPressInputType.Down, keyCode: c));
            inputs.Add(CreateInput(KeyPressInputType.Up, keyCode: c));
            inputs.Add(CreateInput(KeyPressInputType.Up, keyCode: 0x11));
            UserBindings.SendInput((uint)inputs.Count, inputs.ToArray(), Marshal.SizeOf(typeof(UserBindings.INPUT)));
        }
Пример #9
0
        private void SetFormAsClickThrough()
        {
            var style = UserBindings.GetWindowLong(Handle, (int)UserBindings.GetWindowLongConst.GWL_EXSTYLE);

            UserBindings.SetWindowLong(Handle, (int)UserBindings.GetWindowLongConst.GWL_EXSTYLE, Convert.ToInt32(style
                                                                                                                 | (uint)UserBindings.WindowStyles.WS_EX_LAYERED
                                                                                                                 | (uint)UserBindings.WindowStyles.WS_EX_TRANSPARENT
                                                                                                                 | (uint)UserBindings.WindowStyles.WS_EX_TOPMOST
                                                                                                                 ));
            UserBindings.SetLayeredWindowAttributes(this.Handle, 0x0, 125, 0x3);
        }
Пример #10
0
        public static void SendText(IntPtr wndHandle, string s, Point clientPoint)
        {
            UserBindings.ClientToScreen(wndHandle, ref clientPoint);

            var inputs = new List <UserBindings.INPUT>();

            foreach (var c in s.ToCharArray())
            {
                inputs.AddRange(GetCharacterInputs(c));
            }
            UserBindings.SendInput((uint)inputs.Count, inputs.ToArray(), Marshal.SizeOf(typeof(UserBindings.INPUT)));
        }
Пример #11
0
        public void DrawStuff(IntPtr handle, int number, int clientX, int clientY, Graphics overlayGraphics, int width, int height, Color innerColor, Color outerColor)
        {
            var point = new Point(clientX, clientY);

            UserBindings.ClientToScreen(handle, ref point);
            UserInteropAdapter.ScreenToGraphics(ref point);

            overlayGraphics.FillRectangle(new SolidBrush(innerColor), point.X, point.Y, width, height);
            if (number != -1)
            {
                overlayGraphics.DrawString(number.ToString(), new Font(FontFamily.GenericSansSerif, 10),
                                           new SolidBrush(Color.FromArgb(1, 1, 1)), point.X, point.Y);
            }
            overlayGraphics.DrawRectangle(new Pen(outerColor), point.X, point.Y, width + 1, height + 1);
        }
Пример #12
0
        public override object DoRun()
        {
            var searchStrategy = new LocationHeuristictSearchStrategy(this.Selenium);
            var lookupResult   = searchStrategy.DirectLookup(TagNames, SubjectName, Locale, Direction, Order, false);

            if (Interpreter?.IsAnalysis == true)
            {
                Console.Out.WriteColoredLine(ConsoleColor.Magenta, $"Main Result: \n\t{lookupResult.MainResult}\nAll results:\n\t{string.Join("\n\t", lookupResult.AllValidResults)}");
            }

            var chromeHandle = Selenium.BrowserHandle;
            var browserBox   = new UserBindings.RECT();

            UserBindings.GetWindowRect(chromeHandle, ref browserBox);

            var e = lookupResult.AllValidResults.ElementAt(Order);

            Selenium.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);

            Selenium.ConvertFromPageToWindow(ref p);

            if (p.X < 0 || p.X > browserBox.Right || p.Y < 0 || p.Y > browserBox.Bottom)
            {
                throw new NotFoundException("Element not found");
            }
            else
            {
                if (Interpreter?.IsDebugMode == true)
                {
                    BrowserOverlay
                    .HighlightElements((Order + 1).ToString(), (Expect.ToString().ToLower().Equals(true.ToString().ToLower()) ? Color.GreenYellow : Color.Red), lookupResult.MainResult)
                    .ShowFor(750, "Highlighted element will be Clicked");
                }
                return(lookupResult.AllValidResults.ElementAt(Order).WebElement.Selected);
            }

            throw new NotFoundException("Element not found");

            throw new NotImplementedException($"Checking visibility of nth ({Order}) elements is not implemented.");
        }
        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);
                }
            }
        }
Пример #14
0
 public void Register(IInterpreter interpreter)
 {
     UserBindings.SetWindowPos(UserBindings.GetConsoleWindow(), 0, UserInteropAdapter.PrimaryScreenWidth / 2, 0, UserInteropAdapter.PrimaryScreenWidth / 2, UserInteropAdapter.PrimaryScreenHeight, 0);
 }
Пример #15
0
 private void SetFormAsClickable()
 {
     UserBindings.SetLayeredWindowAttributes(this.Handle, 0x0, 125, 0x3);
 }
Пример #16
0
 public void ConvertFromWindowToScreen(ref Point point)
 {
     UserBindings.ClientToScreen(this.BrowserHandle, ref point);
 }
Пример #17
0
 public void ConvertFromWindowToScreen(ref Rectangle rectangle)
 {
     UserBindings.ClientToScreen(this.BrowserHandle, ref rectangle);
 }
Пример #18
0
 public void ConvertFromScreenToWindow(ref Point point)
 {
     UserBindings.ScreenToClient(this.BrowserHandle, ref point);
 }
Пример #19
0
 public void BringToFront()
 {
     UserBindings.SetForegroundWindow(_handle);
     ((IJavaScriptExecutor)WebDriver).ExecuteScript("window.focus();");
 }
Пример #20
0
        public override object DoRun()
        {
            var query = new LocationHeuristictSearchStrategy(Selenium);

            var result = query.DirectLookup(SearchedTagNames, VisibleTextOfTheButton, NeighbourToLookFrom, Direction, Order, LookForOrthogonalNeighboursOnly, exactMatchOnly: true);

            if (Interpreter?.IsAnalysis == true)
            {
                Console.Out.WriteColoredLine(ConsoleColor.Magenta, _instruction?.ToAnalysisString());
                Console.Out.WriteColoredLine(ConsoleColor.Magenta, $"Main Result: \n\t{result.MainResult}\nAll results:\n\t{string.Join("\n\t", result.AllValidResults)}");
            }

            if (result.Success == false)
            {
                throw new LookupFailureException(result, $"Failed {ToString()}.\nCannot find element {(Order > 0 ? (Order + 1).ToString() : "")}({result.AllValidResults.Count()} results found)");
            }

            switch (Technique)
            {
            case Technique.Show:
                BrowserOverlay
                .HighlightElements((Order + 1).ToString(), Color.GreenYellow, result.MainResult)
                .HighlightElements((Order + 1).ToString(), Color.CadetBlue, result.AllValidResults.Except(new[] { result.AllValidResults.ElementAt(Order) }))
                .ShowUntilNextKeyword("Highlighted element will be Clicked");
                return(new OverlayAnswer(BrowserOverlay.Artifacts, "Highlighting complete."));

            case Technique.Javascript:
                Selenium.WebDriver.Click(result.MainResult.WebElement);
                break;

            case Technique.MouseAndKeyboard:
                Selenium.BringToFront();
                var screenLocation = Selenium.PutElementOnScreen(result.MainResult.WebElement);
                if (Interpreter?.IsAnalysis == true)
                {
                    BrowserOverlay
                    .HighlightElements((Order + 1).ToString(), Color.GreenYellow, result.MainResult)
                    .ShowFor(750, "Highlighted element will be Dragged");
                }
                UserInteropAdapter.PressOnPoint(Selenium.BrowserHandle, screenLocation);


                if (Interpreter.IsAnalysis)
                {
                    var oldPosition = Cursor.Position;

                    var tempPoint = new Point(screenLocation.X, screenLocation.Y);
                    UserBindings.ClientToScreen(Selenium.BrowserHandle, ref tempPoint);
                    Cursor.Position = tempPoint;
                    var steps   = 50m;
                    var xOffset = X / steps;
                    var yOffset = Y / steps;

                    for (int i = 0; i < steps; i++)
                    {
                        Cursor.Position = new Point((int)(tempPoint.X + i * xOffset), (int)(tempPoint.Y + i * yOffset));
                        Thread.Sleep(30);
                    }

                    Cursor.Position = oldPosition;
                }

                screenLocation.X += X;
                screenLocation.Y += Y;
                Thread.Sleep(20);

                UserInteropAdapter.ReleaseOnPoint(Selenium.BrowserHandle, screenLocation);
                Thread.Sleep(50);
                break;
            }

            return(new SuccessAnswer($"Performed {ToString()}"));
        }