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)); }
private void saveCapturedImage(String options, byte[] bytes, File file) throws IOException { if (options == null) { FileOutputStream out = null; try { LOG.html("Screen captured (%d): <br /> <img src='%s'/>", screenCaptureCtr, file.getName()); out = new FileOutputStream(file); IOUtils.write(bytes, out); } finally { IOUtils.closeQuietly(out); } } else { LOG.html("Screen captured (%d): <br /> <img src='%s'/>", screenCaptureCtr, file.getName()); BufferedImage fullImg = ImageIO.read(new ByteArrayInputStream(bytes)); ImageIO.write(processOption(fullImg, options), "png", file); } }
/** * Get Xpath Text Contents */ public List<Element> getXpathElements(String xpathExpression) throws TransformerException, XPathExpressionException { NodeList nodeList = getNodeList(xpathExpression); if (nodeList.getLength() == 0) { return Collections.emptyList(); } StringBuilder buf = new StringBuilder(); List<Element> list = new ArrayList<Element>(); for (int i = 0; i < nodeList.getLength(); i++) { Element element = (Element) nodeList.item(i); list.add(element); buf.append("<b>Element [").append(i).append("]:</b>").append(HighlighterUtils.INSTANCE.highlightXML(XMLFormatter.prettyPrint(element))); } LOG.pureHtml(buf.toString()); return list; }
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 String getCreatedJSONString() { if(lastAppender == null) { throw new IllegalStateException("No created json."); } if(CollectionUtils.isNotEmpty(appender)) { throw new IllegalStateException("json creation is not properly ended."); } String createdJSONString = lastAppender.toString(); LOG.createAppender() .appendBold("Created JSON String:") .appendJSON(JSONHelper.prettyPrint(createdJSONString)) .log(); return createdJSONString; }
public File elementCaptureScreenShot(String locator, String options) throws IOException { LOG.keywordAppender().appendLocator(locator); WebElement el = finder.find(locator); byte[] bytes = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES); File file = newScreenCaptureFile(); LOG.keywordAppender().appendArgument("File", file.getAbsolutePath()); LOG.html("Screen captured (%d): <br /> <img src='%s'/>", screenCaptureCtr, file.getName()); BufferedImage fullImg = ImageIO.read(new ByteArrayInputStream(bytes)); //Get the location of element on the page Point point = el.getLocation(); //Get width and height of the element int eleWidth = el.getSize().getWidth(); int eleHeight = el.getSize().getHeight(); LOG.keywordAppender() .appendArgument("Width", eleWidth) .appendArgument("Height", eleHeight) .appendArgument("X", point.getX()) .appendArgument("Y", point.getY()); //Crop the entire page screenshot to get only element screenshot BufferedImage eleScreenshot = fullImg.getSubimage(point.getX(), point.getY(), eleWidth, eleHeight); if (options != null) { eleScreenshot = processOption(eleScreenshot, options); } ImageIO.write(eleScreenshot, "png", file); return file; }
builder.command().addAll(arguments); LOG.info("Arguments: " + arguments); LOG.warn("Console: \n" + buf); throw new IllegalStateException("Script executed with failure. Exit Code: " + exitValue); LOG.info("Console: \n" + buf); LOG.html("Comparison: <br/> <table><tr><td><b>Baseline:</b></td><td><b>Screenshot:</b></td></tr><tr><td><img src='base/%s'/></td><td><img src='screenshot/%s'/></td></tr><tr><td colspan='2'><b>Difference:</b></td></tr><tr><td colspan='2'><img src='result/%s'/></td></tr></table>", filename, filename, filename); throw new IllegalStateException("Image Compare did not pass.");
private String callVerifyProperty(String functionName, String... args) { StringBuilder code = new StringBuilder(); StringBuilder verifyProperty = new StringBuilder(); verifyProperty.append("<VerifyProperty value=\"" + args[0] + "\" propertyString=\"" + args[1] + "\"/>"); LOG.info("VerifyProperty: " + verifyProperty); code.insert(0, String.format("return document['%s'].%s('%s', '%s')", flexAppID, functionName, verifyProperty, "")); LOG.info("Call: " + code); String result = String.valueOf(executor.executeScript(code.toString())); LOG.info("Result: " + result); return result; }
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."); } }
private Map<String,Collection<String>> parseImagesFiredAndReturnSiteCatalystVariables(String htmlSource){ Map<String,Collection<String>> eventMap = new HashMap<String,Collection<String>>(); Document doc = Jsoup.parse(htmlSource); Elements tds = doc.select("td"); String[] tdList = null; int counter = 0; String eventPrefix = "Event"; for (Element td : tds) { if (td.text().contains("Image")) { tdList = td.html().split("<br />"); List<String> actualList = new ArrayList<String>(Arrays.asList(tdList)); actualList.remove(0); // remove from list ---- <span style="font:bold 11px arial,sans-serif;color:#000000;">Image</span> List<String> unescapedList = new ArrayList<String>(); for (String data: actualList) { if (!data.contains("table")) { // Exclude parsed data with html tags like </table>. This is a duplicate data. unescapedList.add(StringEscapeUtils.unescapeXml(data)); } } eventMap.put(eventPrefix + counter, unescapedList); counter = counter + 1; } } eventMap.remove("Event0"); // This contains the first td element that is not needed LOG.createAppender() .appendBold("Number Of Events Captured") .appendCode(String.format("%s", eventMap.size())).log(); return eventMap; }
private String callArray(String functionName, String[] args) { String code = null; try { code = String.format("return document['%s'].%s(%s);", flexAppID, functionName, new JSONArray(args)); } catch (JSONException e) { throw new IllegalArgumentException(e.getMessage(), e); } LOG.info("Call: " + code); String result = String.valueOf(executor.executeScript(code)); LOG.info("Result: " + result); return result; } }
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 boolean isElementVisible(String locator) { LOG.keywordAppender().appendLocator(locator); boolean isVisible = isVisible(locator); LOG.keywordAppender().appendArgument("Visible", isVisible); return isVisible; }
/** * Get Xpath Text Contents */ public List<String> getXpathTextContents(String xpathExpression) throws TransformerException, XPathExpressionException { NodeList nodeList = getNodeList(xpathExpression); if (nodeList.getLength() == 0) { return Collections.emptyList(); } List<String> list = new ArrayList<String>(); for (int i = 0; i < nodeList.getLength(); i++) { Element element = (Element) nodeList.item(i); list.add(element.getTextContent()); } LOG.createAppender() .appendBold("Get Xpath Text Contents:") .appendProperty("Xpath Expression", xpathExpression) .appendProperty("Text Contents", String.valueOf(list)) .log(); return list; }
public void closeBrowser() { LOG.info("Closing browser"); driver.close(); }
public void collect(String filename) throws IOException { File screenShotFile = createScreenShotFile(collectImageDir, filename); File collected = new File(collectOutputImageDir, filename); FileInputStream in = null; FileOutputStream out = null; try { in = new FileInputStream(screenShotFile); out = new FileOutputStream(collected); IOUtils.copy(in, out); } finally { IOUtils.closeQuietly(in); IOUtils.closeQuietly(out); } LOG.html("Screen captured: <br /> <img src='collect/%s'/>", filename); }
/** * Get Xpath Text Contents */ public List<Element> getXpathElements(Element base, String xpathExpression) throws TransformerException, IOException, SAXException, XPathExpressionException, ParserConfigurationException { NodeList nodeList = getNodeList(base, xpathExpression); if (nodeList.getLength() == 0) { return Collections.emptyList(); } StringBuilder buf = new StringBuilder(); List<Element> list = new ArrayList<Element>(); for (int i = 0; i < nodeList.getLength(); i++) { Element element = (Element) nodeList.item(i); list.add(element); buf.append("<b>Element [").append(i).append("]:</b>").append(HighlighterUtils.INSTANCE.highlightXML(XMLFormatter.prettyPrint(element))); } LOG.pureHtml(buf.toString()); return list; }
public Boolean findElement(String locator) { LOG.keywordAppender().appendLocator(locator); if (!isElementPresent(locator)) { LOG.info(String.format("Page should have contained element '%s' but did not.", locator)); return false; } return true; }
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)); } }
private NodeList getNodeList(String xpathExpression) throws TransformerException, XPathExpressionException { validate(); NodeList nodeList = (NodeList) xPath.evaluate(xpathExpression, document, XPathConstants.NODESET); if (nodeList == null) { throw new IllegalArgumentException(String.format("Xpath Expression '%s' not found.", xpathExpression)); } LOG.createAppender() .appendBold("Get Node List:") .appendProperty("Xpath Expression", xpathExpression) .appendProperty("Number of Elements Found", nodeList.getLength()) .log(); return nodeList; } }