List of usage examples for org.openqa.selenium.interactions Actions moveByOffset
public Actions moveByOffset(int xOffset, int yOffset)
From source file:org.richfaces.tests.metamer.ftest.richDragIndicator.TestDragIndicator.java
License:Open Source License
@Test public void testDragging() { dragIndicatorAttributes.set(draggingClass, DRAGGING_CLASS); dragIndicatorAttributes.set(acceptClass, ACCEPT_CLASS); Actions actionQueue = new Actions(driver); // before any mouse move, no indicator appears on page elementNotPresent.element(page.indicator).apply(driver); // firstly just drag and don't move. Indicator no displayed Action dragging = actionQueue.clickAndHold(page.drag1).build(); dragging.perform();//from w w w. j a va2 s . com elementNotPresent.element(page.indicator); // just small move to display indicator dragging = actionQueue.moveByOffset(1, 1).build(); dragging.perform(); assertTrue(page.indicator.isDisplayed()); assertTrue(page.indicator.getAttribute("class").contains(DRAGGING_CLASS)); // then move out of drag area (but not over drop area) dragging = actionQueue.moveByOffset(550, 10).build(); dragging.perform(); assertTrue(page.indicator.isDisplayed()); assertTrue(page.indicator.getAttribute("class").contains(DRAGGING_CLASS)); // this one as well dragging = actionQueue.release().build(); dragging.perform(); elementNotPresent.element(page.indicator); }
From source file:org.richfaces.tests.metamer.ftest.richDragIndicator.TestDragIndicator.java
License:Open Source License
@Test public void testAccepting() { dragIndicatorAttributes.set(draggingClass, DRAGGING_CLASS); dragIndicatorAttributes.set(acceptClass, ACCEPT_CLASS); Actions actionQueue = new Actions(driver); Action dragging = actionQueue.clickAndHold(page.drag1).build(); dragging.perform();/*w w w . j av a 2 s . com*/ elementNotPresent.element(page.indicator); // just small move to display indicator dragging = actionQueue.moveByOffset(1, 1).build(); dragging.perform(); assertTrue(page.indicator.isDisplayed()); assertTrue(page.indicator.getAttribute("class").contains(DRAGGING_CLASS)); dragging = actionQueue.moveToElement(page.drop1).build(); dragging.perform(); assertTrue(page.indicator.isDisplayed()); assertTrue(page.indicator.getAttribute("class").contains(ACCEPT_CLASS)); // then release dragging = actionQueue.release().build(); dragging.perform(); elementNotPresent.element(page.indicator); }
From source file:org.richfaces.tests.metamer.ftest.richDragIndicator.TestDragIndicator.java
License:Open Source License
@Test public void testRejecting() { dragIndicatorAttributes.set(draggingClass, DRAGGING_CLASS); dragIndicatorAttributes.set(rejectClass, REJECT_CLASS); Actions actionQueue = new Actions(driver); Action dragging = actionQueue.clickAndHold(page.drag1).build(); dragging.perform();/*from ww w .ja v a2 s . c om*/ elementNotPresent.element(page.indicator); // just small move to display indicator dragging = actionQueue.moveByOffset(1, 1).build(); dragging.perform(); assertTrue(page.indicator.isDisplayed()); assertTrue(page.indicator.getAttribute("class").contains(DRAGGING_CLASS)); dragging = actionQueue.moveToElement(page.drop2).build(); dragging.perform(); assertTrue(page.indicator.isDisplayed()); assertTrue(page.indicator.getAttribute("class").contains(REJECT_CLASS)); // then release dragging = actionQueue.release().build(); dragging.perform(); elementNotPresent.element(page.indicator); }
From source file:org.richfaces.tests.metamer.ftest.richDragIndicator.TestDragIndicator.java
License:Open Source License
@Test public void testMovingOverDifferentStates() { dragIndicatorAttributes.set(draggingClass, DRAGGING_CLASS); dragIndicatorAttributes.set(rejectClass, REJECT_CLASS); dragIndicatorAttributes.set(acceptClass, ACCEPT_CLASS); for (int i = 0; i <= 20; ++i) { Actions actionQueue = new Actions(driver); Action dragging = actionQueue.clickAndHold(page.drag1).build(); dragging.perform();/*w w w .j av a 2 s.c om*/ elementNotPresent.element(page.indicator); // just small move to display indicator dragging = actionQueue.moveByOffset(1, 1).build(); dragging.perform(); assertTrue(page.indicator.isDisplayed()); assertTrue(page.indicator.getAttribute("class").contains(DRAGGING_CLASS)); // then move out of drag area (but not over drop area) dragging = actionQueue.moveByOffset(550, 10).build(); dragging.perform(); assertTrue(page.indicator.isDisplayed()); assertTrue(page.indicator.getAttribute("class").contains(DRAGGING_CLASS)); dragging = actionQueue.moveToElement(page.drop1).build(); dragging.perform(); assertTrue(page.indicator.isDisplayed()); assertTrue(page.indicator.getAttribute("class").contains(ACCEPT_CLASS)); dragging = actionQueue.moveToElement(page.drop2).build(); dragging.perform(); assertTrue(page.indicator.isDisplayed()); assertTrue(page.indicator.getAttribute("class").contains(REJECT_CLASS)); // then release dragging = actionQueue.release().build(); dragging.perform(); elementNotPresent.element(page.indicator); } }
From source file:org.richfaces.tests.metamer.ftest.richDragSource.AbstractDragSourceTest.java
License:Open Source License
public void testDefaultIndicator() { indicator = new Indicator(page.defaultIndicator); indicator.setDefaultIndicator(true); dragSourceAttributes.set(dragIndicator, ""); Actions actionQueue = new Actions(driver); Action clickAndHold = actionQueue.clickAndHold(page.drag1).build(); clickAndHold.perform();//from w w w . j a v a 2 s. com assertTrue(elementNotPresent.element(page.defaultIndicator).apply(driver)); Action move = actionQueue.moveByOffset(1, 1).build(); move.perform(); assertTrue(elementPresent.element(page.defaultIndicator).apply(driver)); testMovingOverDifferentStates(); Action drop = actionQueue.release(page.drop1).build(); drop.perform(); }
From source file:org.richfaces.tests.metamer.ftest.richDragSource.AbstractDragSourceTest.java
License:Open Source License
public void testRendered() { dragSourceAttributes.set(dragIndicator, "indicator2"); dragSourceAttributes.set(rendered, true); // before any mouse move, no indicator appears on page elementNotPresent.element(page.indicator2).apply(driver); // indicator = new IndicatorWD(indicatorLoc); indicator = new Indicator(page.indicator2); Actions actionQueue = new Actions(driver); // firstly just drag and don't move. Indicator no displayed Action dragging = actionQueue.clickAndHold(page.drag1).build(); dragging.perform();//from w w w . j av a2s . c o m elementNotPresent.element(page.indicator2).apply(driver); // just small move to display indicator dragging = actionQueue.moveByOffset(1, 1).build(); dragging.perform(); elementPresent.element(page.indicator2).apply(driver); dragging = actionQueue.release().build(); elementPresent.element(page.indicator2).apply(driver); dragging.perform(); elementNotPresent.element(page.indicator2).apply(driver); }
From source file:org.safs.selenium.webdriver.lib.WDLibrary.java
License:Open Source License
/** * @param we WebElement, the component to hover mouse * @param point Point, the position relative to the component to hover the mouse * @param millisStay double, the period to hover the mouse, in milliseconds * @throws SeleniumPlusException if the hover fail *///from w w w.j a va 2 s.co m public static void mouseHover(WebElement we, Point point, int millisStay) throws SeleniumPlusException { try { //Hover mouse on the webelement Actions action = new Actions(lastUsedWD); action.moveToElement(we); if (point != null) { int xOffset = point.x - we.getSize().width / 2; int yOffset = point.y - we.getSize().height / 2; action.moveByOffset(xOffset, yOffset); } action.build().perform(); //Pause a while StringUtilities.sleep(millisStay); //Move out the mouse //action.moveByOffset(-Robot.SCREENSZIE.width, -Robot.SCREENSZIE.height);//This will throw exception //action.build().perform(); Robot.getRobot().mouseMove(-Robot.SCREENSZIE.width, -Robot.SCREENSZIE.height); } catch (Exception e) { IndependantLog.warn(StringUtils.debugmsg(false) + "Failed to hover mouse by Selenium API: " + StringUtils.debugmsg(e)); Point screenPoint = new Point(point.x, point.y); try { translatePoint(we, screenPoint); IndependantLog.warn(StringUtils.debugmsg(false) + "Try SAFS Robot to hover mouse at screen point [" + screenPoint.x + "," + screenPoint.y + "]"); Robot.mouseHover(screenPoint, millisStay); } catch (Exception e2) { throw new SeleniumPlusException( "Failed to hover mouse at point [" + point.x + "," + point.y + "] relative to webelement."); } } }