org.openqa.selenium.Point Java Examples

The following examples show how to use org.openqa.selenium.Point. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractAppiumTest.java    From test-samples with Apache License 2.0 6 votes vote down vote up
protected void swipeLeft(Point rootLocation, Dimension rootSize, int duration, float leftPad, float rightPad) {
    int offset = 1;
    int leftOffset = Math.round(rootSize.getWidth() * leftPad);
    int rightOffset = Math.round(rootSize.getWidth() * rightPad);
    Point center = new Point(rootLocation.x + rootSize.getWidth() / 2, rootLocation.y + rootSize.getHeight() / 2);
    logger.debug("Swiping left at" +
            " x1: " + (rootLocation.getX() + rootSize.getWidth() - rightOffset + offset) +
            " y1:" + center.getY() +
            " x2:" + (rootLocation.getX() + leftOffset) +
            " y2:" + center.getY());
    driver.swipe((rootLocation.getX() + rootSize.getWidth() - rightOffset + offset),
            center.getY(),
            (rootLocation.getX() + leftOffset),
            center.getY(),
            duration);
}
 
Example #2
Source File: MobileUtils.java    From carina with Apache License 2.0 6 votes vote down vote up
public static void zoom(Zoom type) {
    LOGGER.info("Zoom will be performed :" + type);
    MobileDriver<?> driver = (MobileDriver<?>) getDriver();
    Dimension scrSize = helper.performIgnoreException(() -> driver.manage().window().getSize());
    int height = scrSize.getHeight();
    int width = scrSize.getWidth();
    LOGGER.debug("Screen height : " + height);
    LOGGER.debug("Screen width : " + width);
    Point point1 = new Point(width / 2, height / 2 - 30);
    Point point2 = new Point(width / 2, height / 10 * 3);
    Point point3 = new Point(width / 2, height / 2 + 30);
    Point point4 = new Point(width / 2, (7 * height) / 10);
    switch (type) {
    case OUT:
        zoom(point1.getX(), point1.getY(), point2.getX(), point2.getY(), point3.getX(), point3.getY(), point4.getX(), point4.getY(),
                DEFAULT_TOUCH_ACTION_DURATION);
        break;
    case IN:
        zoom(point2.getX(), point2.getY(), point1.getX(), point1.getY(), point4.getX(), point4.getY(), point3.getX(), point3.getY(),
                DEFAULT_TOUCH_ACTION_DURATION);
        break;
    }
}
 
Example #3
Source File: DragAndDropTest.java    From selenium with Apache License 2.0 6 votes vote down vote up
@NoDriverAfterTest
// We can't reliably resize the window back afterwards, cross-browser, so have to kill the
// window, otherwise we are stuck with a small window for the rest of the tests.
// TODO(dawagner): Remove @NoDriverAfterTest when we can reliably do window resizing
@Test
@NotYetImplemented(SAFARI)
@NotYetImplemented(EDGE)
public void testShouldAllowUsersToDragAndDropToElementsOffTheCurrentViewPort() {
  driver.get(pages.dragAndDropPage);

  JavascriptExecutor js = (JavascriptExecutor) driver;
  js.executeScript("window.resizeTo(300, 300);");

  driver.get(pages.dragAndDropPage);
  WebElement img = driver.findElement(By.id("test3"));
  Point expectedLocation = img.getLocation();
  drag(img, expectedLocation, 100, 100);
  assertThat(img.getLocation()).isEqualTo(expectedLocation);
}
 
Example #4
Source File: SeleniumUtils.java    From NetDiscovery with Apache License 2.0 6 votes vote down vote up
public static void taskScreenShot(WebDriver driver,WebElement element,String pathName) {

        //指定了OutputType.FILE做为参数传递给getScreenshotAs()方法,其含义是将截取的屏幕以文件形式返回。
        File srcFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
        //利用IOUtils工具类的copyFile()方法保存getScreenshotAs()返回的文件对象。

        try {
            //获取元素在所处frame中位置对象
            Point p = element.getLocation();
            //获取元素的宽与高
            int width = element.getSize().getWidth();
            int height = element.getSize().getHeight();
            //矩形图像对象
            Rectangle rect = new Rectangle(width, height);
            BufferedImage img = ImageIO.read(srcFile);
            BufferedImage dest = img.getSubimage(p.getX(), p.getY(), rect.width, rect.height);
            ImageIO.write(dest, "png", srcFile);
            IOUtils.copyFile(srcFile, new File(pathName));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
 
Example #5
Source File: AndroidTouchTest.java    From java-client with Apache License 2.0 6 votes vote down vote up
@Test public void dragNDropByCoordinatesAndDurationTest() {
    Activity activity = new Activity("io.appium.android.apis", ".view.DragAndDropDemo");
    driver.startActivity(activity);
    AndroidElement dragDot1 = driver.findElement(By.id("io.appium.android.apis:id/drag_dot_1"));
    AndroidElement dragDot3 = driver.findElement(By.id("io.appium.android.apis:id/drag_dot_3"));

    WebElement dragText = driver.findElement(By.id("io.appium.android.apis:id/drag_text"));
    assertEquals("Drag text not empty", "", dragText.getText());

    Point center1 = dragDot1.getCenter();
    Point center2 = dragDot3.getCenter();

    TouchAction dragNDrop = new TouchAction(driver)
            .longPress(longPressOptions()
                    .withPosition(point(center1.x, center1.y))
                    .withDuration(ofSeconds(2)))
            .moveTo(point(center2.x, center2.y))
            .release();
    dragNDrop.perform();
    assertNotEquals("Drag text empty", "", dragText.getText());
}
 
Example #6
Source File: PerfectoDeviceSteps.java    From Quantum with MIT License 6 votes vote down vote up
/**
 * Performs the lo touch gesture according to the point coordinates.
 *
 * @param locator
 *            write in format of x,y. can be in pixels or
 *            percentage(recommended) for example 50%,50%.
 */
@Then("^I tap on \"(.*?)\" for \"(\\d*\\.?\\d*)\" seconds$")
public static void tapElement(String locator, int seconds) {

	QAFExtendedWebElement myElement = new QAFExtendedWebElement(locator);

	Point location = myElement.getLocation();
	Dimension size = myElement.getSize();

	// determine location to click and convert to an appropriate string
	int xToClick = location.getX() + (size.getWidth() / 2);
	int yToClick = location.getY() + (size.getHeight() / 2);
	String clickLocation = xToClick + "," + yToClick;

	DeviceUtils.longTouch(clickLocation, seconds);

}
 
Example #7
Source File: AbstractAppiumTest.java    From test-samples with Apache License 2.0 6 votes vote down vote up
protected void swipeUp(Point rootLocation, Dimension rootSize, int duration, float topPad, float bottomPad) {
    int offset = 1;
    int topOffset = Math.round(rootSize.getHeight() * topPad);
    int bottomOffset = Math.round(rootSize.getHeight() * bottomPad);
    Point center = new Point(rootLocation.x + rootSize.getWidth() / 2, rootLocation.y + rootSize.getHeight() / 2);
    logger.debug("Swiping up at" +
            " x1: " + center.getX() +
            " y1:" + (rootLocation.getY() + rootSize.getHeight() - bottomOffset + offset) +
            " x2:" + center.getX() +
            " y2:" + (rootLocation.getY() + topOffset));
    driver.swipe(center.getX(),
            rootLocation.getY() + rootSize.getHeight() - bottomOffset + offset,
            center.getX(),
            rootLocation.getY() + topOffset,
            duration);
}
 
Example #8
Source File: Edition029_W3C_Actions.java    From appiumpro with Apache License 2.0 6 votes vote down vote up
private void drawCircle (AppiumDriver driver, Point origin, double radius, int steps) {
    Point firstPoint = getPointOnCircle(0, steps, origin, radius);

    PointerInput finger = new PointerInput(Kind.TOUCH, "finger");
    Sequence circle = new Sequence(finger, 0);
    circle.addAction(finger.createPointerMove(NO_TIME, VIEW, firstPoint.x, firstPoint.y));
    circle.addAction(finger.createPointerDown(MouseButton.LEFT.asArg()));

    for (int i = 1; i < steps + 1; i++) {
        Point point = getPointOnCircle(i, steps, origin, radius);
        circle.addAction(finger.createPointerMove(STEP_DURATION, VIEW, point.x, point.y));
    }

    circle.addAction(finger.createPointerUp(MouseButton.LEFT.asArg()));
    driver.perform(Arrays.asList(circle));
}
 
Example #9
Source File: AbstractAppiumTest.java    From test-samples with Apache License 2.0 6 votes vote down vote up
protected void swipeRight(Point rootLocation, Dimension rootSize, int duration, float leftPad, float rightPad) {
    int offset = 1;
    int leftOffset = Math.round(rootSize.getWidth() * leftPad);
    int rightOffset = Math.round(rootSize.getWidth() * rightPad);
    Point center = new Point(rootLocation.x + rootSize.getWidth() / 2, rootLocation.y + rootSize.getHeight() / 2);
    logger.debug("Swiping right at" +
            " x1: " + (rootLocation.getX() + leftOffset) +
            " y1:" + center.getY() +
            " x2:" + (rootLocation.getX() + rootSize.getWidth() - rightOffset + offset) +
            " y2:" + center.getY());
    driver.swipe((rootLocation.getX() + leftOffset),
            center.getY(),
            (rootLocation.getX() + rootSize.getWidth() - rightOffset + offset),
            center.getY(),
            duration);
}
 
Example #10
Source File: AbstractDriver.java    From coteafs-selenium with Apache License 2.0 6 votes vote down vote up
private void setScreen(final PlaybackSetting playback) {
    final ScreenState state = playback.getScreenState();
    if (getPlatform() == DESKTOP) {
        LOG.i("Setting screen size of Browser to {}...", state);
        switch (state) {
            case FULL_SCREEN:
                manageWindow(Window::fullscreen);
                break;
            case MAXIMIZED:
                manageWindow(Window::maximize);
                break;
            case NORMAL:
            default:
                final ScreenResolution resolution = playback.getScreenResolution();
                LOG.i("Setting screen resolution to [{}]...", resolution);
                manageWindow(w -> w.setSize(new Dimension(resolution.getWidth(), resolution.getHeight())));
                manageWindow(w -> w.setPosition(new Point(0, 0)));
                break;
        }
    }
}
 
Example #11
Source File: JavaDriverTest.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public void windowSetPosition() throws Throwable {
    driver = new JavaDriver();
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });
    Window window = driver.manage().window();
    Point actual = window.getPosition();
    AssertJUnit.assertNotNull(actual);
    java.awt.Point expected = EventQueueWait.call(frame, "getLocation");
    AssertJUnit.assertEquals(expected.x, actual.x);
    AssertJUnit.assertEquals(expected.y, actual.y);
    window.setPosition(new Point(expected.x + 10, expected.y + 10));
    actual = window.getPosition();
    AssertJUnit.assertEquals(expected.x + 10, actual.x);
    AssertJUnit.assertEquals(expected.y + 10, actual.y);
}
 
Example #12
Source File: DragAndDropTest.java    From selenium with Apache License 2.0 6 votes vote down vote up
@Test
@Ignore(value = IE, reason = "IE fails this test if requireWindowFocus=true")
@NotYetImplemented(SAFARI)
@Ignore(MARIONETTE)
@NotYetImplemented(EDGE)
public void canDragAnElementNotVisibleInTheCurrentViewportDueToAParentOverflow() {
  driver.get(pages.dragDropOverflow);

  WebElement toDrag = driver.findElement(By.id("time-marker"));
  WebElement dragTo = driver.findElement(By.id("11am"));

  Point srcLocation = toDrag.getLocation();
  Point targetLocation = dragTo.getLocation();

  int yOffset = targetLocation.getY() - srcLocation.getY();
  assertThat(yOffset).isNotEqualTo(0);

  new Actions(driver).dragAndDropBy(toDrag, 0, yOffset).perform();

  assertThat(toDrag.getLocation()).isEqualTo(dragTo.getLocation());
}
 
Example #13
Source File: SwipeUtils.java    From coteafs-appium with Apache License 2.0 6 votes vote down vote up
/**
 * @param direction
 * @param startPosition
 * @param distancePercent
 * @param setting
 * @param screenSize
 * @param elementSize
 * @param elementLocation
 * @param actions
 * @return action
 * @author wasiq.bhamla
 * @since Sep 18, 2018 8:03:55 PM
 */
public static <T extends TouchAction<T>> T swipeTo(final SwipeDirection direction,
    final SwipeStartPosition startPosition, final int distancePercent, final PlaybackSetting setting,
    final Dimension screenSize, final Dimension elementSize, final Point elementLocation, final T actions) {
    final double distance = distancePercent / 100.0;
    final Point source = getStartPoint(startPosition, screenSize, elementSize, elementLocation);
    int endX = source.getX() + (int) (source.getX() * direction.getX() * distance);
    int endY = source.getY() + (int) (source.getY() * direction.getY() * distance);
    if (elementSize != null) {
        endX = source.getX() + (int) (elementSize.getWidth() * direction.getX() * distance);
        endY = source.getY() + (int) (elementSize.getHeight() * direction.getY() * distance);
    }
    return actions.press(PointOption.point(source.getX(), source.getY()))
        .waitAction(WaitOptions.waitOptions(Duration.ofMillis(setting.getDelayBeforeSwipe())))
        .moveTo(PointOption.point(endX, endY))
        .release();
}
 
Example #14
Source File: AbstractTwoFingerGesture.java    From xframium-java with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setParameters( Object[] parameterArray )
{
	startOne = (Point) parameterArray[ 0 ];
	startTwo = (Point) parameterArray[ 1 ];
	endOne = (Point) parameterArray[ 2 ];
	endTwo = (Point) parameterArray[ 3 ];
	
}
 
Example #15
Source File: Edition109_iPadOS_Split_Screen.java    From appiumpro with Apache License 2.0 5 votes vote down vote up
protected void dragElement(Rectangle elRect, double endXPct, double endYPct, Duration duration) {
    Point start = new Point((int)(elRect.x + elRect.width / 2), (int)(elRect.y + elRect.height / 2));
    Point end = new Point((int)(size.width * endXPct), (int)(size.height * endYPct));
    driver.executeScript("mobile: dragFromToForDuration", ImmutableMap.of(
        "fromX", start.x, "fromY", start.y,
        "toX", end.x, "toY", end.y,
        "duration", duration.toMillis() / 1000.0
    ));
}
 
Example #16
Source File: StringToListSequenceActionConverterTests.java    From vividus with Apache License 2.0 5 votes vote down vote up
@Test
void testConvertValuePoint()
{
    String pointAsString = "(100, 100)";
    Point point = mock(Point.class);
    when(pointConverter.convertValue(pointAsString, null)).thenReturn(point);
    String value = "|type          |argument  |\n"
                 + "|MOVE_BY_OFFSET|(100, 100)|";
    List<SequenceAction> actions = converter.convertValue(value, null);
    assertThat(actions, hasSize(1));
    verifySequenceAction(actions.get(0), SequenceActionType.MOVE_BY_OFFSET, point);
    verify(pointConverter).convertValue(pointAsString, null);
    verifyNoMoreInteractions(stringToSearchAttributesConverter, pointConverter);
}
 
Example #17
Source File: Edition067_Zoom_Touch_Gestures.java    From appiumpro with Apache License 2.0 5 votes vote down vote up
private Collection<Sequence> zoom(Point locus, int startRadius, int endRadius, int pinchAngle, Duration duration) {
    // convert degree angle into radians. 0/360 is top (12 O'clock).
    double angle = Math.PI / 2 - (2 * Math.PI / 360 * pinchAngle);

    // create the gesture for one finger
    Sequence fingerAPath = zoomSinglefinger("fingerA", locus, startRadius, endRadius, angle, duration);

    // flip the angle around to the other side of the locus and get the gesture for the second finger
    angle = angle + Math.PI;
    Sequence fingerBPath = zoomSinglefinger("fingerB", locus, startRadius, endRadius, angle, duration);

    return Arrays.asList(fingerAPath, fingerBPath);
}
 
Example #18
Source File: IOSDeviceElementActions.java    From coteafs-appium with Apache License 2.0 5 votes vote down vote up
@Override
public void dragDrop(final MobileElement dropElement) {
    log.info("Performing drag on element [{}]...", this.name);
    final Point fromCenter = this.element.getCenter();
    final Point fromLocation = this.element.getLocation();
    final Point toCenter = dropElement.getCenter();

    final Map<String, Object> param = prepareParam();
    param.put("duration", this.setting.getDelayBeforeSwipe());
    param.put("fromX", fromCenter.getX() - fromLocation.getX());
    param.put("fromY", fromCenter.getY() - fromLocation.getY());
    param.put("toX", toCenter.getX() - fromLocation.getX());
    param.put("toY", toCenter.getY() - fromLocation.getY());
    this.device.executeCommand("mobile: dragFromToForDuration", param);
}
 
Example #19
Source File: AppiumAndroidTest.java    From candybean with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void testLocation() throws Exception {
    WebElement button = driver.findElement(By.xpath("//button[1]"));

    Point location = button.getLocation();

    assertEquals(location.getX(), 157);
    assertEquals(location.getY(), 182);
}
 
Example #20
Source File: Edition067_Zoom_Touch_Gestures.java    From appiumpro with Apache License 2.0 5 votes vote down vote up
private Sequence zoomSinglefinger(String fingerName, Point locus, int startRadius, int endRadius, double angle, Duration duration) {
    PointerInput finger = new PointerInput(PointerInput.Kind.TOUCH, fingerName);
    Sequence fingerPath = new Sequence(finger, 0);

    double midpointRadius = startRadius + (endRadius > startRadius ? 1 : -1) * 20;

    // find coordinates for starting point of action (converting from polar coordinates to cartesian)
    int fingerStartx = (int)Math.floor(locus.x + startRadius * Math.cos(angle));
    int fingerStarty = (int)Math.floor(locus.y - startRadius * Math.sin(angle));

    // find coordinates for first point that pingers move quickly to
    int fingerMidx = (int)Math.floor(locus.x + (midpointRadius * Math.cos(angle)));
    int fingerMidy = (int)Math.floor(locus.y - (midpointRadius * Math.sin(angle)));

    // find coordinates for ending point of action (converting from polar coordinates to cartesian)
    int fingerEndx = (int)Math.floor(locus.x + endRadius * Math.cos(angle));
    int fingerEndy = (int)Math.floor(locus.y - endRadius * Math.sin(angle));

    // move finger into start position
    fingerPath.addAction(finger.createPointerMove(Duration.ZERO, PointerInput.Origin.viewport(), fingerStartx, fingerStarty));
    // finger comes down into contact with screen
    fingerPath.addAction(finger.createPointerDown(PointerInput.MouseButton.LEFT.asArg()));
    // finger moves a small amount very quickly
    fingerPath.addAction(finger.createPointerMove(Duration.ofMillis(1), PointerInput.Origin.viewport(), fingerMidx, fingerMidy));
    // pause for a little bit
    fingerPath.addAction(new Pause(finger, Duration.ofMillis(100)));
    // finger moves to end position
    fingerPath.addAction(finger.createPointerMove(duration, PointerInput.Origin.viewport(), fingerEndx, fingerEndy));
    // finger lets up, off the screen
    fingerPath.addAction(finger.createPointerUp(PointerInput.MouseButton.LEFT.asArg()));

    return fingerPath;
}
 
Example #21
Source File: DeviceElementActions.java    From coteafs-appium with Apache License 2.0 5 votes vote down vote up
/**
 * @param times
 * @author wasiqb
 * @since Oct 18, 2018
 */
public void nTaps(final int times) {
    perform(format("Performing [%d] taps on", times), e -> {
        final Point center = e.getCenter();
        for (int index = 0; index < times; index++) {
            this.touch.press(PointOption.point(center.getX(), center.getY()))
                .release()
                .perform();
        }
    });
}
 
Example #22
Source File: AppiumUtils.java    From Quantum with MIT License 5 votes vote down vote up
/**
 *
 * @return start and end points for horizontal(left-right) swipe
 */
private static Point[] getXYtoHSwipe() {
	// Get screen size.
	Dimension size = getAppiumDriver().manage().window().getSize();

	// Find starting point x which is at right side of screen.
	int startx = (int) (size.width * 0.70);
	// Find ending point x which is at left side of screen.
	int endx = (int) (size.width * 0.30);
	// Find y which is in middle of screen height.
	int startEndy = size.height / 2;

	return new Point[] { new Point(startx, startEndy), new Point(endx, startEndy) };
}
 
Example #23
Source File: ScreenServiceImpl.java    From NoraUi with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void saveScreenshot(String screenName, WebElement element) throws IOException {
    log.debug("saveScreenshot with the screen named [{}] and element [{}]", screenName, element.getTagName());

    final byte[] screenshot = ((TakesScreenshot) Context.getDriver()).getScreenshotAs(OutputType.BYTES);
    FileUtils.forceMkdir(new File(System.getProperty(USER_DIR) + File.separator + DOWNLOADED_FILES_FOLDER));

    InputStream in = new ByteArrayInputStream(screenshot);
    BufferedImage fullImg = ImageIO.read(in);

    // Get the location of element on the page
    Point point = element.getLocation();

    // Get width and height of the element
    int eleWidth = element.getSize().getWidth();
    int eleHeight = element.getSize().getHeight();

    // Crop the entire page screenshot to get only element screenshot
    try {
        BufferedImage eleScreenshot = fullImg.getSubimage(point.getX(), point.getY(), eleWidth, eleHeight);
        ImageIO.write(convertType(eleScreenshot, BufferedImage.TYPE_3BYTE_BGR), "jpg",
                new File(System.getProperty(USER_DIR) + File.separator + DOWNLOADED_FILES_FOLDER + File.separator + screenName + ".jpg"));
    } catch (RasterFormatException e) {
        // if image protrudes from the screen, the whole image is saved.
        log.warn("image protrudes from the screen, the whole image is saved.");
        scrollIntoView(element);
        ImageIO.write(convertType(fullImg, BufferedImage.TYPE_3BYTE_BGR), "jpg",
                new File(System.getProperty(USER_DIR) + File.separator + DOWNLOADED_FILES_FOLDER + File.separator + screenName + ".jpg"));
    }

}
 
Example #24
Source File: SportsEventTributeTest.java    From webDriverExperiments with MIT License 5 votes vote down vote up
@Test
public void bounceThatWindow(){
    WebDriver driver = new FirefoxDriver();
    driver.get("file://" + System.getProperty("user.dir") + "/jsrunner.html");
    driver.manage().window().maximize();
    Dimension fullScreenSize = driver.manage().window().getSize();

    int changeWidth = 200; int changeHeight = 210;
    int xDir = 8; int yDir = 8; int xDirIncrement = xDir; int yDirIncrement = yDir;

    driver.manage().window().setSize(new Dimension(changeWidth,changeHeight));

    Point position = driver.manage().window().getPosition();

    String banner = "***BANG****........ AND THEY ARE OFF........ Automation can be fun. " +
            " EvilTester.com present a javascript and browser" +
            " animation using Selenium 2 WebDriver tribute to the" +
            " sporting event that cannot be named lest we be sued";
    int bannerStart = 0;

    for(int bounceIterations = 0; bounceIterations < 1000; bounceIterations ++){

        position = position.moveBy(xDir,yDir);
        driver.manage().window().setPosition(position);

        if(position.getX()>(fullScreenSize.getWidth() - changeWidth)){ xDir = -1 * xDirIncrement; }
        if(position.getX()<0){ xDir = xDirIncrement; }
        if(position.getY()>(fullScreenSize.getHeight() - changeHeight)){ yDir = -1 * yDirIncrement; }
        if(position.getY()<0){ yDir = yDirIncrement; }

        //try {Thread.sleep(20);} catch (InterruptedException e) {}
        String displayBanner = banner.substring(bannerStart,bannerStart+30);
        ((JavascriptExecutor)driver).executeScript("document.title='" + displayBanner + "';");
        bannerStart++;
        if(bannerStart > banner.length()-35){banner += banner;}
    }

    driver.quit();
}
 
Example #25
Source File: Edition090_Image_Element_Optimization.java    From appiumpro with Apache License 2.0 5 votes vote down vote up
private void shootBird(AndroidDriver driver, WebElement birdEl, int xOffset, int yOffset) {
    Rectangle rect = birdEl.getRect();
    Point start = new Point(rect.x + rect.width / 2, rect.y + rect.height / 2);
    Point end = start.moveBy(xOffset, yOffset);
    Duration dragDuration = Duration.ofMillis(750);

    PointerInput finger = new PointerInput(Kind.TOUCH, "finger");
    Sequence shoot = new Sequence(finger, 0);
    shoot.addAction(finger.createPointerMove(Duration.ofMillis(0), Origin.viewport(), start.x, start.y));
    shoot.addAction(finger.createPointerDown(MouseButton.LEFT.asArg()));
    shoot.addAction(finger.createPointerMove(dragDuration, Origin.viewport(), end.x, end.y));
    shoot.addAction(finger.createPointerUp(MouseButton.LEFT.asArg()));
    driver.perform(Arrays.asList(shoot));
}
 
Example #26
Source File: ImageProcessorTest.java    From selenium-shutterbug with MIT License 5 votes vote down vote up
@Test
public void testHighlight() throws IOException {
    Point point = new Point(9,33);
    Dimension size = new Dimension(141,17);
    Coordinates coords = new Coordinates(point, size, 1D);
    BufferedImage clearImage = ImageIO.read(Thread.currentThread().getContextClassLoader().getResourceAsStream("clearImage.png"));
    BufferedImage highlightedExpectedImage = ImageIO.read(Thread.currentThread().getContextClassLoader().getResourceAsStream("highlightedImage.png"));
    BufferedImage highlightedActualImage = ImageProcessor.highlight(clearImage, coords, Color.red, 3);
    assertTrue("Images are not equal after highlighting",ImageProcessor.imagesAreEquals(highlightedExpectedImage, highlightedActualImage, 0.0));
}
 
Example #27
Source File: RectangleBasedImageAnnotation.java    From webtau with Apache License 2.0 5 votes vote down vote up
@Override
public void addAnnotationData(Map<String, Object> data, WebElement webElement) {
    Point location = webElement.getLocation();
    Dimension size = webElement.getSize();

    data.put("x", location.getX());
    data.put("y", location.getY());
    data.put("width", size.getWidth());
    data.put("height", size.getHeight());
}
 
Example #28
Source File: AbstractPressGesture.java    From xframium-java with GNU General Public License v3.0 5 votes vote down vote up
public void setParameters( Object[] parameterArray )
{
	setPressPosition( (Point) parameterArray[ 0 ] );
	setPressLength( ( (Long) parameterArray[ 1 ] ).intValue() );
	setPressCount( ( (Integer) parameterArray[ 2 ] ).intValue() );
	
}
 
Example #29
Source File: FeaturesMatchingResult.java    From java-client with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a list of matching points on the first image.
 *
 * @return The list of matching points on the first image.
 */
public List<Point> getPoints1() {
    verifyPropertyPresence(POINTS1);
    //noinspection unchecked
    return ((List<Map<String, Object>>) getCommandResult().get(POINTS1)).stream()
            .map(ComparisonResult::mapToPoint)
            .collect(Collectors.toList());
}
 
Example #30
Source File: WebUtility.java    From seleniumtestsframework with Apache License 2.0 5 votes vote down vote up
/**
 * Resize window to given dimensions.
 *
 * @param  width
 * @param  height
 */
public void resizeWindow(final int width, final int height) {
    try {
        TestLogging.logWebStep("Resize browser window to width " + width + " height " + height, false);

        Dimension size = new Dimension(width, height);
        driver.manage().window().setPosition(new Point(0, 0));
        driver.manage().window().setSize(size);
    } catch (Exception ex) { }
}