/** * Create an instance of {@link Screenshot } * */ public Screenshot createScreenshot() { return new Screenshot(); }
@Override public String doRender(Object o) { if (!(o instanceof Screenshot)) return null; Screenshot screenshot = (Screenshot) o; return "Screenshot" + " -> " + screenshot.getUrl(); }
@Override public Object screenshot(String url, String description) { Screenshot screenshot = factory.createScreenshot(); screenshot.setUrl(url); screenshot.setDescription(description); return screenshot; }
@Override public Object screenshot(TakesScreenshot takesScreenshot, String description) { Screenshot screenshot = factory.createScreenshot(); screenshot.setDescription(description); File tempFile = takesScreenshot.getScreenshotAs(OutputType.FILE); File attachmentFile = null; try { attachmentFile = LogFileAttachment.getAttachmentFile("", "png"); FileUtils.copyFile(tempFile, attachmentFile); } catch (IOException e) { e.printStackTrace(); } if (attachmentFile != null) screenshot.setUrl(attachmentFile.getName()); return screenshot; }
@Override public String doRender(Object o) { if (!(o instanceof Comment)) return null; Comment comment = (Comment) o; StringBuilder builder = new StringBuilder(); builder.append("Comment" + " -> "); for (Object c : comment.getContent()) { if(c instanceof String) { builder.append((String)c); } if(c instanceof Textarea) { builder.append(((Textarea)c).getName()); } if(c instanceof Screenshot) { builder.append("Screenshot" + " [" + ((Screenshot)c).getUrl() + "]"); } builder.append("; "); } return builder.toString(); }