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 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 sikuliRightMouseUp(LiferaySelenium liferaySelenium) throws Exception { liferaySelenium.pause("1000"); Mouse mouse = new DesktopMouse(); mouse.rightRelease(); }
public static void sikuliLeftMouseDown(LiferaySelenium liferaySelenium) throws Exception { liferaySelenium.pause("1000"); Mouse mouse = new DesktopMouse(); mouse.press(); }
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()); }
// TODO: this is not working yet public static void main(String[] args) throws IOException, InterruptedException { URL backgroundImage = Images.GoogleSearchPage; URL dragTargetImage = Images.OSXDockIcon; DragDropFrame imageFrame = new DragDropFrame(backgroundImage, dragTargetImage); imageFrame.autoClose(10000); ScreenRegion s = new DesktopScreenRegion(); Mouse mouse = new DesktopMouse(); URL imageURL = Images.OSXDockIcon; Target imageTarget = new ImageTarget(imageURL); ScreenRegion r = s.wait(imageTarget, 1000); mouse.drag(r.getCenter()); imageURL = Images.GoogleMicrophoneIcon; imageTarget = new ImageTarget(imageURL); r = s.wait(imageTarget, 1000); mouse.drop(r.getCenter()); ScreenLocation c = mouse.getLocation(); mouse.drag(c); mouse.drop(Relative.to(c).left(200).above(50).getScreenLocation()); }
@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); }