@Override public void mouseMoveAt(String locator, String coordString) { WebElement webElement = getWebElement(locator); WrapsDriver wrapsDriver = (WrapsDriver) webElement; WebDriver webDriver = wrapsDriver.getWrappedDriver(); Actions actions = new Actions(webDriver); if (coordString.contains(",")) { String[] coords = coordString.split(","); int x = GetterUtil.getInteger(coords[0]); int y = GetterUtil.getInteger(coords[1]); actions.moveToElement(webElement, x, y); actions.clickAndHold(webElement); } else { actions.moveToElement(webElement); actions.clickAndHold(webElement); } Action action = actions.build(); action.perform(); }
@Override public void keyUp(String locator, String keySequence) { WebElement webElement = getWebElement(locator); if (keySequence.startsWith("\\")) { int index = GetterUtil.getInteger(keySequence.substring(1)); Keys keys = _keysArray[index]; if ((index >= 48) && (index <= 90)) { webElement.sendKeys(StringPool.ASCII_TABLE[index]); } else if ((index == 16) || (index == 17) || (index == 18)) { WrapsDriver wrapsDriver = (WrapsDriver) webElement; WebDriver webDriver = wrapsDriver.getWrappedDriver(); Actions actions = new Actions(webDriver); actions.keyUp(webElement, keys); Action action = actions.build(); action.perform(); } else { webElement.sendKeys(keys); } } else { webElement.sendKeys(keySequence); } }
@Override public void clickAt(String locator, String coordString) { if (locator.contains("x:")) { String url = getHtmlNodeHref(locator); open(url); } else { WebElement webElement = getWebElement(locator); if (coordString.contains(",")) { WrapsDriver wrapsDriver = (WrapsDriver) webElement; WebDriver webDriver = wrapsDriver.getWrappedDriver(); Actions actions = new Actions(webDriver); String[] coords = coordString.split(","); int x = GetterUtil.getInteger(coords[0]); int y = GetterUtil.getInteger(coords[1]); actions.moveToElement(webElement, x, y); actions.click(); Action action = actions.build(); action.perform(); } else { webElement.click(); } } }
@Test public void testTooltipPosition() throws Exception { openTestURL(); for (int i = 0; i < TooltipPosition.NUMBER_OF_BUTTONS; i++) { ButtonElement button = $(ButtonElement.class).get(i); // Move the mouse to display the tooltip. Actions actions = new Actions(driver); actions.moveToElement(button, 10, 10); actions.build().perform(); waitUntil(tooltipToBeInsideWindow(By.cssSelector(".v-tooltip"), driver.manage().window())); if (i < TooltipPosition.NUMBER_OF_BUTTONS - 1) { // Remove the tooltip by moving the mouse. actions = new Actions(driver); actions.moveByOffset(300, 0); actions.build().perform(); waitUntil(tooltipNotToBeShown(By.cssSelector(".v-tooltip"), driver.manage().window())); } } }
@Override public void mouseRelease() { WebElement bodyWebElement = getWebElement("//body"); WrapsDriver wrapsDriver = (WrapsDriver) bodyWebElement; WebDriver webDriver = wrapsDriver.getWrappedDriver(); Actions actions = new Actions(webDriver); actions.release(); Action action = actions.build(); action.perform(); }
@Override public void doubleClick(String locator) { WebElement webElement = getWebElement(locator); WrapsDriver wrapsDriver = (WrapsDriver) webElement; WebDriver webDriver = wrapsDriver.getWrappedDriver(); Actions actions = new Actions(webDriver); actions.doubleClick(webElement); Action action = actions.build(); action.perform(); }
protected void checkContextMenuRenderedAtCorrectPosition( WebElement target, WebElement contextMenuPopup, InvocationType type, ExpectedCondition<Boolean> conditionTargetIsFocused) { if (conditionTargetIsFocused != null) { target.click(); Graphene.waitGui(webDriver).withTimeout(2, TimeUnit.SECONDS).until(conditionTargetIsFocused); } waitGui(); // clicks in the middle of the target switch (type) { case LEFT_CLICK: actions.click(target); break; case RIGHT_CLICK: actions.contextClick(target); break; default: throw new IllegalArgumentException("Wrong type of context menu invocation!"); } actions.build().perform(); Graphene.waitGui() .withTimeout(2, TimeUnit.SECONDS) .until() .element(contextMenuPopup) .is() .visible(); Point locationOfTarget = target.getLocation(); Point locationOfCtxMenu = contextMenuPopup.getLocation(); double witdth = getTargetWidth(target); double height = getTargetHeight(target); double halfOfDiagonal = Math.sqrt((height * height) + (witdth * witdth)) / 2.0; double distance = getDistance(locationOfTarget, locationOfCtxMenu); double result = halfOfDiagonal - distance; assertTrue( result >= 0 && result < TOLERANCE, "The context menu was not rendered on the correct position! The difference is: " + result); }
@Override public void mouseOut(String locator) { WebElement webElement = getWebElement(locator); WrapsDriver wrapsDriver = (WrapsDriver) webElement; WebDriver webDriver = wrapsDriver.getWrappedDriver(); Actions actions = new Actions(webDriver); actions.moveToElement(webElement); actions.moveByOffset(10, 10); Action action = actions.build(); action.perform(); }
@Override public void mouseDown(String locator) { WebElement webElement = getWebElement(locator); WrapsDriver wrapsDriver = (WrapsDriver) webElement; WebDriver webDriver = wrapsDriver.getWrappedDriver(); Actions actions = new Actions(webDriver); actions.moveToElement(webElement); actions.clickAndHold(webElement); Action action = actions.build(); action.perform(); }
@Override public void dragAndDropToObject( String locatorOfObjectToBeDragged, String locatorOfDragDestinationObject) { WebElement objectToBeDraggedWebElement = getWebElement(locatorOfObjectToBeDragged); WrapsDriver wrapsDriver = (WrapsDriver) objectToBeDraggedWebElement; WebDriver webDriver = wrapsDriver.getWrappedDriver(); Actions actions = new Actions(webDriver); WebElement dragDestinationObjectWebElement = getWebElement(locatorOfDragDestinationObject); actions.dragAndDrop(objectToBeDraggedWebElement, dragDestinationObjectWebElement); Action action = actions.build(); action.perform(); }