public void add(String key, Object value) { LOG.keywordAppender().appendProperty("Add Variable Key", key); if(value != null) { LOG.keywordAppender().appendProperty("Add Variable Class", value.getClass().getName()); } LOG.keywordAppender().appendProperty("Add Variable Value", value); variables.put(key, value); }
public void inputPassword(String locator, String password) { LOG.keywordAppender() .appendArgument("Password", password) .appendLocator(locator); inputTextIntoTextField(locator, password); }
public Set<String> getAllButtons() { Set<String> links = new HashSet<String>(); List<WebElement> elList = driver.findElements(By.cssSelector("button")); for(WebElement el:elList) { System.out.println("================================="); System.out.println("el id=" + el.getAttribute("id")); System.out.println("el text=" + el.getText()); System.out.println("el href=" + el.getAttribute("button")); links.add(el.getAttribute("href")); LOG.keywordAppender() .append("el id ", el.getAttribute("id")) .append("el text", el.getText()) .append("el href", el.getAttribute("button")); } return links; }
public void checkboxShouldNotBeSelected(String locator) { WebElement el = getCheckbox(locator); LOG.keywordAppender() .appendBold("Checkbox Should Not e Selected:") .appendLocator(locator) .appendArgument("Selected", el.isSelected()); if (el.isSelected()) { throw new IllegalArgumentException("Checkbox should not have been selected."); } }
@Override public Object handle(Object parameter) { String expression = (String) parameter; try { LOG.keywordAppender().createPath(); return helper.evaluate(expression); } catch (Exception e) { throw new IllegalArgumentException(String.format("Unable to evaluate expression '%s'.", expression), e); } finally { LOG.keywordAppender().endPath(); } } }
public void alertShouldBePresent(String expectedAlertText) { String actualAlertText = getAlertMessage(); LOG.keywordAppender() .appendArgument("Actual Alert Text", actualAlertText) .appendArgument("Expected Alert Text", expectedAlertText); if (!StringUtils.equals(actualAlertText, expectedAlertText)) { throw new IllegalArgumentException("Alert text is not equal."); } }
private WebElement getRadioButtonWithValue(String groupName, String value) { String xpath = String.format("//input[@type='radio' and @name='%s' and (@value='%s' or @id='%s')]", groupName, value, value); LOG.keywordAppender().appendLocator("xpath=" + xpath); return ElementFinder.findByXpath(driver, xpath, null, null); }
public Object executeJavascript(String locator, String code, Object... args) throws IOException { if (StringUtils.startsWith(code, "file:") || StringUtils.startsWith(code, "classpath:") || StringUtils.startsWith(code, "http:") || StringUtils.startsWith(code, "https:")) { LOG.keywordAppender().appendArgument("Resource", code); ResourceEditor editor = new ResourceEditor(); editor.setAsText(code); LOG.keywordAppender().appendLocator(locator); LOG.keywordAppender().appendJavascript(code); LOG.keywordAppender().appendArgument("Returned Value", returnedValue);
public boolean waitForJavaScriptCondition(final String javaScript, int timeOutInSeconds) { boolean jscondition; LOG.keywordAppender() .appendJavascript(javaScript) .appendArgument("timeOutInSeconds", timeOutInSeconds); try{ driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); //nullify implicitlyWait() (new WebDriverWait(driver, timeOutInSeconds)).until(new ExpectedCondition<Boolean>() { @Override public Boolean apply(WebDriver driverObject) { return (Boolean) ((JavascriptExecutor) driverObject).executeScript(javaScript); } }); jscondition = (Boolean) ((JavascriptExecutor) driver).executeScript(javaScript); driver.manage().timeouts().implicitlyWait(implicitWaitInSeconds, TimeUnit.SECONDS); //reset implicitlyWait return jscondition; } catch (Exception e) { String.format("timeout (%d s) reached.", timeOutInSeconds); } return false; }
public Object evaluate(String expression) throws Exception { Matcher matcher = EXPRESSION_PATTERN.matcher(expression); if(!matcher.find()) { throw new IllegalArgumentException(String.format("Invalid expression format '%s'.", expression)); } String content = matcher.group(1); LOG.keywordAppender().appendExpression(expression); Matcher prefixMatcher = PREFIX_EXPRESSION_PATTERN.matcher(content); if (prefixMatcher.matches()) { String prefix = prefixMatcher.group(1); String prefixContent = prefixMatcher.group(2); return expressionManager.evaluation(prefix, prefixContent); } else { return expressionManager.defaultEvaluation(content); } }
public String getSource() { String source = driver.getPageSource(); LOG.keywordAppender().appendXML(source); return source; }
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 checkboxShouldBeSelected(String locator) { WebElement el = getCheckbox(locator); LOG.keywordAppender() .appendBold("Checkbox Should Be Selected:") .appendLocator(locator) .appendArgument("Selected", el.isSelected()); if (!el.isSelected()) { throw new IllegalArgumentException("Checkbox should have been selected."); } }
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 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 void chooseFile(String locator, String filePath) { File file = new File(filePath); LOG.keywordAppender().appendLocator(locator) .appendArgument("File Path", filePath) .appendArgument("Is File", file.isFile()); if (!file.isFile()) { throw new IllegalArgumentException("File does not exist on the local file system."); } WebElement el = finder.find(locator); el.sendKeys(toKeys(filePath)); }
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 clear() { for(Map.Entry<String, Object> entry : variables.entrySet()) { LOG.keywordAppender().appendProperty(String.format("Remove Variable ['%s']", entry.getKey()), entry.getValue()); } variables.clear(); } }
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 void elementAttributeValueShouldBe(String attributeLocator, String expectedValue) { LOG.keywordAppender().appendLocator(attributeLocator); String actualValue = getElementAttribute(attributeLocator); LOG.keywordAppender() .appendArgument("Actual Element Attribute Value", actualValue) .appendArgument("Expected Element Attribute Value", expectedValue); if (!StringUtils.equals(StringUtils.trim(actualValue), StringUtils.trim(expectedValue))) { throw new AssertionError("The attribute value of the element is not as expected."); } }