--- old/src/org/netbeans/jemmy/operators/ComponentOperator.java 2018-08-17 10:52:18.950192598 -0700 +++ new/src/org/netbeans/jemmy/operators/ComponentOperator.java 2018-08-17 10:52:18.882191656 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -59,8 +59,6 @@ import java.util.Hashtable; import java.util.Locale; -import static java.lang.Math.abs; - import org.netbeans.jemmy.CharBindingMap; import org.netbeans.jemmy.ComponentChooser; import org.netbeans.jemmy.ComponentSearcher; @@ -1222,6 +1220,48 @@ } /** + * Wait till the component reaches exact location on screen. + * + * @param exactLocation exact expected screen location. + */ + public void waitComponentLocationOnScreen(Point exactlocation) { + waitComponentLocationOnScreen(exactlocation, exactlocation); + } + + /** + * Wait till the component location on screen reaches between minLocation + * and maxLocation + * + * @param minLocation minimum expected location on screen. + * @param maxLocation maximum expected location on screen. + */ + public void waitComponentLocationOnScreen( + final Point minLocation, final Point maxLocation) { + waitState(new ComponentChooser() { + @Override + public boolean checkComponent(Component comp) { + Point location = comp.getLocationOnScreen(); + return location.x >= minLocation.x + && location.x <= maxLocation.x + && location.y >= minLocation.y + && location.y <= maxLocation.y; + } + + @Override + public String getDescription() { + return "Component location on screen reaches between :" + + minLocation + "and " + maxLocation; + } + + @Override + public String toString() { + return "ComponentOperator.waitComponentLocationOnScreen" + + ".Waitable{description = " + getDescription() + '}'; + } + }); + } + + /** * Returns information about component. */ @Override --- /dev/null 2018-02-03 01:34:01.991000000 -0800 +++ new/test/org/netbeans/jemmy/operators/ComponentOperatorTest.java 2018-08-17 10:52:19.199196047 -0700 @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package org.netbeans.jemmy.operators; + +import java.awt.Point; + +import javax.swing.JFrame; +import javax.swing.JLabel; + +import org.netbeans.jemmy.TimeoutExpiredException; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class ComponentOperatorTest { + + + private JFrame frame = null; + + @BeforeClass + protected void setUp() throws Exception { + frame = new JFrame(); + frame.setSize(400,400); + frame.setLocationRelativeTo(null); + } + + @AfterClass + protected void tearDown() throws Exception { + frame.setVisible(false); + frame.dispose(); + } + + @Test + public void testWaitComponentLocationOnScreen() { + final int locationDelta = 50; + final String LABEL_TEXT = "Sample Text"; + JLabel label = new JLabel(LABEL_TEXT); + frame.add(label); + frame.setVisible(true); + JLabelOperator labelOperator = new JLabelOperator(label); + + Point currentLocation = labelOperator.getLocation(); + Point currentScreenLocation = labelOperator.getLocationOnScreen(); + Point newScreenLocation = new Point(currentScreenLocation.x + + locationDelta, currentScreenLocation.y + locationDelta); + labelOperator.setLocation(currentLocation.x + locationDelta, + currentLocation.y + locationDelta); + labelOperator.waitComponentLocationOnScreen(newScreenLocation); + + // Negative scenario + try { + labelOperator.waitComponentLocationOnScreen(new Point(0, 0)); + Assert.fail(); + } catch (TimeoutExpiredException e) { + } + } +}