/*** * Utility method to generate System properties attachment for the Allure report * * @return a formatted String of the Mule system properties of the given instance. */ @Attachment(value = "Properties") public String attachProperties() { return MapUtils.toString(properties, true).replaceAll("(?<=\\.password=)(.*)", "****"); }
/** * Process data returned from method annotated with {@link Attachment}. * If returned data is not a byte array, then use toString() method, and get bytes from it. * * @param joinPoint the join point to process. * @param result the returned value. */ @AfterReturning(pointcut = "anyMethod() && withAttachmentAnnotation()", returning = "result") public void attachment(final JoinPoint joinPoint, final Object result) { final MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature(); final Attachment attachment = methodSignature.getMethod() .getAnnotation(Attachment.class); final byte[] bytes = (result instanceof byte[]) ? (byte[]) result : Objects.toString(result) .getBytes(StandardCharsets.UTF_8); final String name = attachment.value().isEmpty() ? methodSignature.getName() : processNameTemplate(attachment.value(), getParametersMap(methodSignature, joinPoint.getArgs())); getLifecycle().addAttachment(name, attachment.type(), attachment.fileExtension(), bytes); }
/*** * Utility method to generate Runtime server log attachment for the Allure report * * @return a ByteArray representation of the log. */ @Attachment(value = "Server log ", type = "text/plain", fileExtension = ".log") public byte[] attachServerLog() { try { return Files.readAllBytes(mule.getLog().toPath()); } catch (IOException ignored) { } return null; }
/*** * Utility method to generate Application log attachment for the Allure report * * @param appName the application name * @return a ByteArray representation of the log. */ @Attachment(value = "Application {appName} log", type = "text/plain", fileExtension = ".log") public byte[] attachAppLog(String appName) { try { return Files.readAllBytes(mule.getLog(appName).toPath()); } catch (IOException ignored) { } return null; }
@Attachment(value = "Video on Failure", type = "video/mp4") private byte[] getVideo(URL videoCaptureURL) { try { return urlFetcher.fetchWithRetry(videoCaptureURL, 4); } catch (TimeoutException e) { logger.error("Failed fetching URL {}.", videoCaptureURL); return null; } }
@Attachment(value = "Screenshot on failure", type = "image/png") private byte[] writeScreenshotToFile(TakesScreenshot driver, Path screenshot) { try (OutputStream screenshotStream = Files.newOutputStream(screenshot)) { byte[] bytes = driver.getScreenshotAs(OutputType.BYTES); screenshotStream.write(bytes); screenshotStream.close(); return bytes; } catch (IOException e) { logger.error("Unable to write " + screenshot, e); } catch (WebDriverException e) { logger.error("Unable to take screenshot.", e); } return null; }
@Attachment @Step("Make screen shot of results page") public byte[] makeScreenShot() { return ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES); }