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 setTimeoutImplicit(WebDriver webDriver, String timeout) { WebDriver.Options options = webDriver.manage(); WebDriver.Timeouts timeouts = options.timeouts(); timeouts.implicitlyWait(GetterUtil.getInteger(timeout), TimeUnit.MILLISECONDS); }
public static void setTimeoutImplicit(WebDriver webDriver, String timeout) { WebDriver.Options options = webDriver.manage(); WebDriver.Timeouts timeouts = options.timeouts(); if (!PropsValues.BROWSER_TYPE.equals("safari")) { timeouts.implicitlyWait(GetterUtil.getInteger(timeout), TimeUnit.MILLISECONDS); } }
public static int getViewportHeight(WebDriver webDriver) { WebElement bodyWebElement = getWebElement(webDriver, "//body"); WrapsDriver wrapsDriver = (WrapsDriver) bodyWebElement; WebDriver wrappedWebDriver = wrapsDriver.getWrappedDriver(); JavascriptExecutor javascriptExecutor = (JavascriptExecutor) wrappedWebDriver; return GetterUtil.getInteger(javascriptExecutor.executeScript("return window.innerHeight;")); }
public static int getScrollOffsetY(WebDriver webDriver) { WebElement bodyWebElement = getWebElement(webDriver, "//body"); WrapsDriver wrapsDriver = (WrapsDriver) bodyWebElement; WebDriver wrappedWebDriver = wrapsDriver.getWrappedDriver(); JavascriptExecutor javascriptExecutor = (JavascriptExecutor) wrappedWebDriver; Object pageYOffset = javascriptExecutor.executeScript("return window.pageYOffset;"); return GetterUtil.getInteger(pageYOffset); }
public static void select(WebDriver webDriver, String selectLocator, String optionLocator) { WebElement webElement = getWebElement(webDriver, selectLocator); Select select = new Select(webElement); String label = optionLocator; if (optionLocator.startsWith("index=")) { String indexString = optionLocator.substring(6); int index = GetterUtil.getInteger(indexString); select.selectByIndex(index - 1); } else if (optionLocator.startsWith("value=")) { String value = optionLocator.substring(6); if (value.startsWith("regexp:")) { String regexp = value.substring(7); selectByRegexpValue(webDriver, selectLocator, regexp); } else { List<WebElement> optionWebElements = select.getOptions(); for (WebElement optionWebElement : optionWebElements) { String optionWebElementValue = optionWebElement.getAttribute("value"); if (optionWebElementValue.equals(value)) { label = optionWebElementValue; break; } } select.selectByValue(label); } } else { if (optionLocator.startsWith("label=")) { label = optionLocator.substring(6); } if (label.startsWith("regexp:")) { String regexp = label.substring(7); selectByRegexpText(webDriver, selectLocator, regexp); } else { select.selectByVisibleText(label); } } }
public static void addSelection(WebDriver webDriver, String locator, String optionLocator) { Select select = new Select(getWebElement(webDriver, locator)); if (optionLocator.startsWith("index=")) { select.selectByIndex(GetterUtil.getInteger(optionLocator.substring(6))); } else if (optionLocator.startsWith("label=")) { select.selectByVisibleText(optionLocator.substring(6)); } else if (optionLocator.startsWith("value=")) { select.selectByValue(optionLocator.substring(6)); } else { select.selectByVisibleText(optionLocator); } }
public static void runWhileElement(Element element) throws Exception { PoshiRunnerStackTraceUtil.setCurrentElement(element); XMLLoggerHandler.updateStatus(element, "pending"); int maxIterations = 15; if (element.attributeValue("max-iterations") != null) { maxIterations = GetterUtil.getInteger(element.attributeValue("max-iterations")); } List<Element> whileChildElements = element.elements(); Element conditionElement = whileChildElements.get(0); Element thenElement = element.element("then"); boolean conditionRun = false; for (int i = 0; i < maxIterations; i++) { if (!evaluateConditionalElement(conditionElement)) { break; } conditionRun = true; PoshiRunnerStackTraceUtil.setCurrentElement(thenElement); XMLLoggerHandler.updateStatus(thenElement, "pending"); parseElement(thenElement); XMLLoggerHandler.updateStatus(thenElement, "pass"); } if (conditionRun) { XMLLoggerHandler.updateStatus(element, "pass"); } else { XMLLoggerHandler.updateStatus(element, "conditional-fail"); } }
public static String getNumberIncrement(String value) { return StringUtil.valueOf(GetterUtil.getInteger(value) + 1); }
public static String getEmailSubject(String index) throws Exception { return EmailCommands.getEmailSubject(GetterUtil.getInteger(index)); }
public static void pause(String waitTime) throws Exception { Thread.sleep(GetterUtil.getInteger(waitTime)); }