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); } }
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); }
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); } }); }
public override object DoRun() { var chromeHandle = Selenium.BrowserHandle; var clientPoint = new Point(200, 200); //UserInteropAdapter.ClickOnPoint(chromeHandle, clientPoint); Selenium.BringToFront(); Thread.Sleep(150); UserInteropAdapter.SendText(chromeHandle, $"PRGORILOCAL\\{UserName}\t{Password}\n", clientPoint); return(null); }
private void DrawStuff(int number, int clientX, int clientY, Graphics overlayGraphics) { var point = new Point(clientX, clientY); var handle = Selenium.GetChromeHandle(); ClientToScreen(handle, ref point); UserInteropAdapter.ScreenToGraphics(ref point); overlayGraphics.FillRectangle(new SolidBrush(Color.FromArgb(255, 0, 255, 255)), point.X, point.Y, 20, 20); overlayGraphics.DrawString(number.ToString(), new Font(FontFamily.GenericSansSerif, 10), new SolidBrush(Color.DarkMagenta), point.X, point.Y); overlayGraphics.DrawRectangle(new Pen(Color.FromArgb(255, 255, 0, 255)), point.X, point.Y, 21, 21); }
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); } }
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); }
public override object DoRun() { List <IAnswer> answers = new List <IAnswer>(); var remainingSteps = Interpreter2.Plan.Count() - Interpreter.Iterator.Index; int count = Math.Min(remainingSteps, Count); for (int i = 0; i < count; i++) { ConsoleView.Render(ConsoleColor.DarkGray, $"Starting step {Interpreter.Iterator.Index + 1})\t{Interpreter.Iterator.Current}"); var answer = Interpreter2.Please(string.Empty); answers.Add(answer); //ConsoleView.Render(ConsoleColor.DarkGray, $"Finished step {Interpreter.Iterator.Index })\t{Interpreter.Iterator.Previous}\n{Interpreter.Iterator.Previous.Status}"); ConsoleView.Render(Interpreter.Please("status")); if (UserInteropAdapter.IsKeyDown(Keys.Escape)) { Interpreter.IsDebugMode = true; return("Escape pressed. Interrupting..."); } } if (answers.Any(x => x is INegativeAnswer)) { var baseAnswer = new ExceptionAnswer($"Ran {count} step{(count == 1 ? "" : "s")}."); baseAnswer.Children = answers; return(baseAnswer); } else { var baseAnswer = new SuccessAnswer($"Ran {count} step{(count == 1 ? "" : "s")}."); baseAnswer.Children = answers; return(baseAnswer); } }
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()}")); }
public override object DoRun() { LoadKeywords(); if (Technique == Technique.Show && Interpreter.IsDebugMode) { return(StepIntoScenario()); } if (_plan.Any(x => x is RunScenario)) { throw new ArgumentException("RunScenario cannot call underlying RunScenario keywords."); } while (!Iterator.IsEndOfList()) { var keyword = Iterator.Current; try { ConsoleView.Render(ConsoleColor.DarkGray, $"RunScenario: Starting step {Iterator.Index+1})\t{Iterator.Current}"); var result = (keyword).Execute(); if (result != null && result.Equals(KeywordResultSpecialCases.Skipped)) { Console.WriteLine("Skipping " + keyword); } ConsoleView.Render(ConsoleColor.DarkGray, $"RunScenario: Finished step {Iterator.Index+1})\t{Iterator.Current}\n{Iterator.Current.Status}"); if (result is IAnswer) { ConsoleView.Render((IAnswer)result); } else { ConsoleView.Render(new InformativeAnswer(result)); } Iterator.MoveNext(); if (UserInteropAdapter.IsKeyDown(Keys.Escape)) { Interpreter.IsDebugMode = true; return("Escape pressed. Interrupting..."); } } catch (Exception e) { if (Interpreter.IsDebugMode) { Interpreter.Iterator.MoveBack(1); var error = new CanIContinueRunScenarioEvenThoughIFoundError(this) { Children = new List <IAnswer>() { new ExceptionAnswer(e) } }; this.Iterator.MoveNext(); return(error); } Interpreter.OnScenarioFinished(new ScenarioEventArgs(Plan.ToList(), FileName)); Iterator.Index = 0; throw; } } Interpreter.OnScenarioFinished(new ScenarioEventArgs(Plan.ToList(), FileName)); Iterator.Index = 0; return(null); }
public void ConvertFromGraphicsToScreen(ref Point point) { UserInteropAdapter.GraphicsToScreen(ref point); }
public void ConvertFromScreenToGraphics(ref Rectangle rectangle) { UserInteropAdapter.ScreenToGraphics(ref rectangle); }
public void ConvertFromScreenToGraphics(ref Point point) { UserInteropAdapter.ScreenToGraphics(ref point); }