public static void main(String[] args) { simulator.start(); ScreenRegion s = new DesktopScreenRegion(); URL imageURL = Images.GoogleSearchButton; Target imageTarget = new ImageTarget(imageURL); ScreenRegion r = s.find(imageTarget); canvas.addBox(Relative.to(r).right(100).getScreenRegion()); canvas.addLabel(Relative.to(r).right(100).center().getScreenLocation(), "right"); canvas.addBox(Relative.to(r).left(100).getScreenRegion()); canvas.addLabel(Relative.to(r).left(100).center().getScreenLocation(), "left"); canvas.addBox(Relative.to(r).above(100).getScreenRegion()); canvas.addLabel(Relative.to(r).above(100).center().getScreenLocation(), "above"); canvas.addBox(Relative.to(r).below(100).getScreenRegion()); canvas.addLabel(Relative.to(r).below(100).center().getScreenLocation(), "below"); canvas.display(3); mouse.click(Relative.to(r).center().getScreenLocation()); mouse.click(Relative.to(r).topLeft().getScreenLocation()); mouse.click(Relative.to(r).topRight().getScreenLocation()); mouse.click(Relative.to(r).bottomRight().getScreenLocation()); mouse.click(Relative.to(r).bottomLeft().getScreenLocation()); }
public static void sikuliDragAndDrop( LiferaySelenium liferaySelenium, String image, String coordString) throws Exception { ScreenRegion screenRegion = new DesktopScreenRegion(); ImageTarget imageTarget = getImageTarget(liferaySelenium, image); screenRegion = screenRegion.find(imageTarget); Mouse mouse = new DesktopMouse(); mouse.move(screenRegion.getCenter()); Robot robot = new Robot(); robot.delay(1000); mouse.press(); robot.delay(2000); String[] coords = coordString.split(","); Location location = screenRegion.getCenter(); int x = location.getX() + GetterUtil.getInteger(coords[0]); int y = location.getY() + GetterUtil.getInteger(coords[1]); robot.mouseMove(x, y); robot.delay(1000); mouse.release(); }
public static void sikuliClick(LiferaySelenium liferaySelenium, String image) throws Exception { ScreenRegion screenRegion = new DesktopScreenRegion(); ImageTarget imageTarget = getImageTarget(liferaySelenium, image); screenRegion = screenRegion.find(imageTarget); Mouse mouse = new DesktopMouse(); mouse.click(screenRegion.getCenter()); }
public void run() { ScreenRegion currentTargetRegion = null; if (lastTargetRegion == null) { currentTargetRegion = screenRegion.find(target); if (currentTargetRegion != null) { // appear setLastTargetRegion(currentTargetRegion); listener.targetAppeared(createTargetEvent()); logger.debug(target + " has appeared"); } else { // still vanished } } else { if (isTargetVisibleAt(target, lastTargetRegion)) { // still there } else { currentTargetRegion = screenRegion.find(target); if (currentTargetRegion == null) { // vanished listener.targetVanished(createTargetEvent()); setLastTargetRegion(null); logger.debug(target + " has vanished"); } else { // moved setLastTargetRegion(currentTargetRegion); listener.targetMoved(createTargetEvent()); logger.debug(target + " has moved to " + currentTargetRegion); } } } }
private static boolean isTargetVisibleAt(Target target, ScreenRegion region) { if (region == null) return false; ScreenRegion neighborRegion = Relative.to(region).taller(2).wider(2).getScreenRegion(); ScreenRegion newRegion = neighborRegion.find(target); if (newRegion == null) { logger.debug(target + " is not visible at " + newRegion); return false; } else { logger.debug(target + " is visible at " + newRegion); return true; } }
@Test public void functionName() throws FindFailed { // Create a new instance of the Firefox driver WebDriver driver = new FirefoxDriver(); // And now use this to visit Google driver.get("http://www.google.com"); // Create and initialize an instance of Screen object Screen screen = new Screen(); screen.keyDown(Key.SPACE); screen.type(null, Key.SPACE + "n", 0); screen.keyUp(Key.SPACE); ScreenRegion s = new DesktopScreenRegion(); Target target = new ImageTarget(new File("C:\\testsuk.sikuli\\GoogleSearch.png")); ScreenRegion r = s.find(target); // Create a mouse object Mouse mouse = new DesktopMouse(); // Use the mouse object to click on the center of the target region mouse.click(r.getCenter()); System.out.println(r.getBounds()); // Add image path // Pattern image = new Pattern("C:\\testsuk.sikuli\\searchButton.png"); // Wait 10ms for image // s.wait(image, 10); // Click on the image // screen.click(image); }