Skip to content

Commit d3c9f79

Browse files
committed
Update attachment embedding
1 parent a8050e3 commit d3c9f79

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

src/main/java/com/epam/reportportal/karate/ReportPortalHook.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,23 +326,34 @@ public void finishBackground(@Nullable StepResult stepResult, @Nonnull ScenarioR
326326
* @param itemId item ID future
327327
* @param embed Karate's Embed object
328328
*/
329-
protected void embedAttachment(Maybe<String> itemId, Embed embed) {
329+
protected void embedAttachment(@Nonnull Maybe<String> itemId, @Nonnull Embed embed) {
330330
ReportPortalUtils.embedAttachment(itemId, embed);
331331
}
332332

333+
/**
334+
* Embed an attachment to ReportPortal.
335+
*
336+
* @param itemId item ID future
337+
* @param embeddedEntities a list of Karate's Embed object
338+
*/
339+
protected void embedAttachments(@Nonnull Maybe<String> itemId, @Nullable List<Embed> embeddedEntities) {
340+
ofNullable(embeddedEntities).ifPresent(embeds -> embeds.forEach(embed -> embedAttachment(itemId, embed)));
341+
}
342+
333343
@Override
334344
public void afterScenario(ScenarioRuntime sr) {
335345
Maybe<String> scenarioId = scenarioIdMap.get(sr.scenario.getUniqueId());
346+
finishBackground(null, sr);
347+
336348
if (scenarioId == null) {
337349
LOGGER.error("ERROR: Trying to finish unspecified scenario.");
350+
return;
338351
}
339352

340-
finishBackground(null, sr);
341-
342353
try {
343354
@SuppressWarnings("unchecked")
344355
List<Embed> embeddedEntities = (List<Embed>) new Accessible(sr).field("embeds").getValue();
345-
ofNullable(embeddedEntities).ifPresent(embeds -> embeds.forEach(embed -> embedAttachment(scenarioId, embed)));
356+
embedAttachments(scenarioId, embeddedEntities);
346357
} catch (Exception e) {
347358
LOGGER.warn("Unable to get scenario embeddings", e);
348359
}

src/main/java/com/epam/reportportal/karate/ReportPortalPublisher.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,16 @@ protected void embedAttachment(Maybe<String> itemId, Embed embed) {
410410
ReportPortalUtils.embedAttachment(itemId, embed);
411411
}
412412

413+
/**
414+
* Embed an attachment to ReportPortal.
415+
*
416+
* @param itemId item ID future
417+
* @param embeddedEntities a list of Karate's Embed object
418+
*/
419+
protected void embedAttachments(@Nonnull Maybe<String> itemId, @Nullable List<Embed> embeddedEntities) {
420+
ofNullable(embeddedEntities).ifPresent(embeds -> embeds.forEach(embed -> embedAttachment(itemId, embed)));
421+
}
422+
413423
/**
414424
* Send Step execution results to ReportPortal.
415425
*
@@ -423,8 +433,7 @@ public void sendStepResults(StepResult stepResult) {
423433
sendLog(stepId, stepLog, LogLevel.DEBUG);
424434
}
425435

426-
// Embed attachments before failure logging
427-
ofNullable(stepResult.getEmbeds()).ifPresent(embeds -> embeds.forEach(embed -> embedAttachment(stepId, embed)));
436+
embedAttachments(stepId, stepResult.getEmbeds());
428437

429438
if (result.isFailed()) {
430439
String fullErrorMessage = step.getPrefix() + " " + step.getText();

src/main/java/com/epam/reportportal/karate/ReportPortalUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ public static void sendLog(Maybe<String> itemId, String message, LogLevel level)
471471
* @param itemId item ID future
472472
* @param embed Karate's Embed object
473473
*/
474-
public static void embedAttachment(Maybe<String> itemId, Embed embed) {
474+
public static void embedAttachment(@Nonnull Maybe<String> itemId, @Nonnull Embed embed) {
475475
ReportPortal.emitLog(itemId, id -> {
476476
SaveLogRQ rq = new SaveLogRQ();
477477
rq.setItemUuid(id);

0 commit comments

Comments
 (0)