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 sikuliAssertElementNotPresent(LiferaySelenium liferaySelenium, String image)
      throws Exception {

    ScreenRegion screenRegion = new DesktopScreenRegion();

    ImageTarget imageTarget = getImageTarget(liferaySelenium, image);

    if (screenRegion.wait(imageTarget, 5000) != null) {
      throw new Exception("Element is present");
    }
  }
  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());
  }
  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;
    }
  }
  // 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());
  }
  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);
        }
      }
    }
  }
  public static void sikuliAssertElementPresent(LiferaySelenium liferaySelenium, String image)
      throws Exception {

    ScreenRegion screenRegion = new DesktopScreenRegion();

    ImageTarget imageTarget = getImageTarget(liferaySelenium, image);

    screenRegion = screenRegion.wait(imageTarget, 5000);

    if (screenRegion == null) {
      throw new Exception("Element is not present");
    }

    Canvas canvas = new DesktopCanvas();

    ElementAdder elementAdder = canvas.add();

    ElementAreaSetter elementAreaSetter = elementAdder.box();

    elementAreaSetter.around(screenRegion);

    canvas.display(2);
  }
Exemplo n.º 9
0
  @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);
  }