public String getSelectedListLabel(String locator) { List<String> selectedLabels = getSelectedListLabels(locator); if (CollectionUtils.isEmpty(selectedLabels)) { throw new IllegalArgumentException(String.format("Select list with locator '%s' does not have a single selected value", locator)); } LOG.keywordAppender().appendArgument("Selected Label", selectedLabels.get(0)); return selectedLabels.get(0); }
public void elementShouldNotBeVisible(String locator) { LOG.keywordAppender().appendLocator(locator); boolean isVisible = isVisible(locator); LOG.keywordAppender().appendArgument("Visible", isVisible); if (isVisible) { throw new AssertionError("The element should not be visible, but it is not."); } }
public boolean isElementVisible(String locator) { LOG.keywordAppender().appendLocator(locator); boolean isVisible = isVisible(locator); LOG.keywordAppender().appendArgument("Visible", isVisible); return isVisible; }
public void cssShouldMatchXTimes(String cssLocator, int count) { LOG.keywordAppender().appendArgument("Expected Count", count); int actual = getMatchingCSSCount(cssLocator); if(actual != count) { throw new AssertionError(String.format("Matching css count for %s expected is %d, but was %d.", cssLocator, count, actual)); } }
public List<String> getWindowHandles() { List<String> handles = new ArrayList<String>(driver.getWindowHandles()); LOG.keywordAppender() .appendArgument("Handles", handles); return handles; }
public void pageShouldNotContainCheckbox(String locator) { LOG.keywordAppender().appendLocator(locator); if(isElementPresent(locator, "input", "type", "checkbox")) { throw new AssertionError(String.format("Page should not have contained checkbox '%s' but did.", locator)); } LOG.info(String.format("Current page contains checkbox '%s'.", locator)); }
public void pageShouldNotContainImage(String locator) { LOG.keywordAppender().appendLocator(locator); if(isElementPresent(locator,"img")) { throw new AssertionError(String.format("Page should not have contained image '%s' but did.", locator)); } LOG.info(String.format("Current page contains image '%s'.", locator)); }
public Object silentEvaluate(Object param) throws Exception { if(String.class.isInstance(param) && isSupported((String) param)) { try { LOG.keywordAppender().createPath(); return evaluate((String) param); } finally { LOG.keywordAppender().endPath(); } } return param; }
public boolean isElementSelected(String locator) { LOG.keywordAppender().appendLocator(locator); WebElement el = finder.find(locator, true, "input"); boolean selected = el.isSelected(); LOG.keywordAppender().appendArgument("Selected", selected); return selected; }
public void listShouldHaveNoSelection(String locator) { List<String> values = getListItems(locator); if(CollectionUtils.isNotEmpty(values)) { LOG.keywordAppender() .appendArgument("Values", values) .appendArgument("Texts", getSelectedListLabels(locator)); throw new IllegalArgumentException("List should have no selection."); } }
public void actionDoubleClick(String locator) { Validate.notNull(actions, "actions is not yet started."); LOG.keywordAppender() .appendLocator(locator); WebElement el = finder.find(locator); if (el == null) { throw new IllegalStateException(String.format("ERROR: Element %s not found", locator)); } actions.doubleClick(el); }
public void actionClickAndHold(String locator) { LOG.keywordAppender().appendLocator(locator); Validate.notNull(actions, "actions is not yet started."); WebElement el = finder.find(locator); if (el == null) { throw new IllegalStateException(String.format("ERROR: Element %s not found", locator)); } actions.clickAndHold(el); }
public void actionContextClick(String locator) { LOG.keywordAppender().appendLocator(locator); Validate.notNull(actions, "actions is not yet started."); WebElement el = finder.find(locator); if (el == null) { throw new IllegalStateException(String.format("ERROR: Element %s not found", locator)); } actions.contextClick(el); }
public void assignIdToElement(String id, String locator) { LOG.keywordAppender() .appendLocator(locator) .appendArgument("id", id); WebElement el = finder.find(locator); executor.executeScript(String.format("arguments[0].id = '%s';", id), el); }
public void inputPassword(String locator, String password) { LOG.keywordAppender() .appendArgument("Password", password) .appendLocator(locator); inputTextIntoTextField(locator, password); }
public void submitForm(String locator) { LOG.keywordAppender().appendLocator(locator); WebElement el = finder.find(locator, "form"); el.submit(); }
public int getVerticalPosition(String locator) { LOG.keywordAppender().appendLocator(locator); WebElement element = finder.find(locator); Point point = element.getLocation(); LOG.keywordAppender() .appendArgument("X", point.getX()) .appendArgument("Y", point.getY()); return point.getY(); }
public void actionSendKeys(String keys) { LOG.keywordAppender().appendArgument("Keys", keys); Validate.notNull(actions, "actions is not yet started."); actions.sendKeys(toKeys(keys)); }
public Set<Cookie> getCookies() { Set<Cookie> cookies = driver.manage().getCookies(); for (Cookie cookie : cookies) { LOG.keywordAppender().appendArgument(cookie.getName(), cookie.getValue()); } return cookies; }
public void dragAndDropByOffset(String locatorSrc, int xOffset, int yOffset) { LOG.keywordAppender() .appendLocator(locatorSrc) .appendArgument("xOffset", xOffset) .appendArgument("yOffset", yOffset); WebElement element = finder.find(locatorSrc); new Actions(driver).dragAndDropBy(element, xOffset, yOffset).perform(); }