/** * Write attachment from event using * {@link ru.yandex.qatools.allure.utils.AllureResultsUtils#writeAttachmentSafely(byte[], String, String)} * Then add attachment to step attachments. * * @param step to change */ @Override public void process(Step step) { Attachment attachment = writeAttachmentSafely(getAttachment(), getTitle(), getType()); step.getAttachments().add(attachment); }
/** * Constructs an new event with specified binary attachment source, title and MIME-type * * @param attachment as byte array. * @param title of attachment. Shown at report as name of attachment * @param type MIME-type of attachment */ public MakeAttachmentEvent(byte[] attachment, String title, String type) { setTitle(title); setType(type); setAttachment(attachment); }
@Override public void embedding(String mimeType, byte[] data) { ALLURE_LIFECYCLE.fire(new MakeAttachmentEvent(data, "attachment" + counter++, mimeType)); }
@Override public void write(String text) { ALLURE_LIFECYCLE.fire(new MakeAttachmentEvent(text.getBytes(), "message" + counter++, "text/plain")); }
private void createDataTableAttachment(final List<DataTableRow> dataTableRows) { if (dataTableRows != null && !dataTableRows.isEmpty()) { final StringBuilder dataTableCsv = new StringBuilder(); for (DataTableRow row : dataTableRows) { dataTableCsv.append(StringUtils.join(row.getCells().toArray(), "\t")); dataTableCsv.append('\n'); } ALLURE_LIFECYCLE.fire(new MakeAttachmentEvent(dataTableCsv.toString().getBytes(), "Data table", "text/tab-separated-values")); } }
/** * Process data returned from method annotated with {@link ru.yandex.qatools.allure.annotations.Attachment} * If returned data is not a byte array, then use toString() method, and get bytes from it using * {@link ru.yandex.qatools.allure.config.AllureConfig#attachmentsEncoding} * * @param joinPoint * @param result */ @AfterReturning(pointcut = "anyMethod() && withAttachmentAnnotation()", returning = "result") public void attachment(JoinPoint joinPoint, Object result) { MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature(); Attachment attachment = methodSignature.getMethod().getAnnotation(Attachment.class); String attachTitle = AllureAspectUtils.getTitle( attachment.value(), methodSignature.getName(), joinPoint.getThis(), joinPoint.getArgs() ); Charset charset = AllureConfig.newInstance().getAttachmentsEncoding(); byte[] bytes = (result instanceof byte[]) ? (byte[]) result : String.valueOf(result).getBytes(charset); ALLURE.fire(new MakeAttachmentEvent(bytes, attachTitle, attachment.type())); }