|
51 | 51 | import io.qameta.allure.model.TestResult; |
52 | 52 |
|
53 | 53 | import java.io.ByteArrayInputStream; |
54 | | -import java.io.InputStream; |
55 | 54 | import java.nio.charset.StandardCharsets; |
56 | 55 | import java.nio.file.Paths; |
57 | 56 | import java.util.Collections; |
|
63 | 62 | import java.util.Optional; |
64 | 63 | import java.util.UUID; |
65 | 64 | import java.util.concurrent.ConcurrentHashMap; |
66 | | -import java.util.function.Supplier; |
67 | 65 | import java.util.stream.Collectors; |
68 | 66 | import java.util.stream.IntStream; |
69 | 67 | import java.util.stream.Stream; |
@@ -276,13 +274,14 @@ private void handleStartPickleStep(final TestCase testCase, |
276 | 274 | .setName(step.getKeyword() + step.getText()) |
277 | 275 | .setStart(System.currentTimeMillis()); |
278 | 276 |
|
| 277 | + final AllureExternalKey stepKey = stepKey(pickleStep.getId().toString()); |
279 | 278 | lifecycle.setCurrent(testKey(uuid)); |
280 | | - lifecycle.startStep(stepKey(pickleStep.getId().toString()), stepResult); |
| 279 | + lifecycle.startStep(stepKey, stepResult); |
281 | 280 |
|
282 | 281 | final StepArgument stepArgument = step.getArgument(); |
283 | 282 | if (stepArgument instanceof DataTableArgument) { |
284 | 283 | final DataTableArgument dataTableArgument = (DataTableArgument) stepArgument; |
285 | | - createDataTableAttachment(dataTableArgument); |
| 284 | + createDataTableAttachment(stepKey, dataTableArgument); |
286 | 285 | } |
287 | 286 | } |
288 | 287 |
|
@@ -340,20 +339,28 @@ private static boolean isFixtureHook(final HookTestStep hook) { |
340 | 339 | } |
341 | 340 |
|
342 | 341 | private void handleWriteEvent(final WriteEvent event) { |
343 | | - addAttachmentToCurrent( |
344 | | - "Text output", |
345 | | - TEXT_PLAIN, |
346 | | - () -> new ByteArrayInputStream(Objects.toString(event.getText()).getBytes(StandardCharsets.UTF_8)), |
347 | | - AttachmentOptions.empty() |
| 342 | + // user output is genuinely ambient: it lands under whatever executable is current, |
| 343 | + // and is silently skipped (unsupported executables) — no key to address it by |
| 344 | + lifecycle.getCurrentExecutableKey().ifPresent( |
| 345 | + key -> lifecycle.addAttachment( |
| 346 | + key, |
| 347 | + "Text output", |
| 348 | + TEXT_PLAIN, |
| 349 | + new ByteArrayInputStream(Objects.toString(event.getText()).getBytes(StandardCharsets.UTF_8)), |
| 350 | + AttachmentOptions.empty() |
| 351 | + ) |
348 | 352 | ); |
349 | 353 | } |
350 | 354 |
|
351 | 355 | private void handleEmbedEvent(final EmbedEvent event) { |
352 | | - addAttachmentToCurrent( |
353 | | - event.name, |
354 | | - event.getMediaType(), |
355 | | - () -> new ByteArrayInputStream(event.getData()), |
356 | | - AttachmentOptions.empty() |
| 356 | + lifecycle.getCurrentExecutableKey().ifPresent( |
| 357 | + key -> lifecycle.addAttachment( |
| 358 | + key, |
| 359 | + event.name, |
| 360 | + event.getMediaType(), |
| 361 | + new ByteArrayInputStream(event.getData()), |
| 362 | + AttachmentOptions.empty() |
| 363 | + ) |
357 | 364 | ); |
358 | 365 | } |
359 | 366 |
|
@@ -440,11 +447,14 @@ private List<Parameter> getExamplesAsParameters( |
440 | 447 | .collect(Collectors.toList()); |
441 | 448 | } |
442 | 449 |
|
443 | | - private void createDataTableAttachment(final DataTableArgument dataTableArgument) { |
444 | | - addAttachmentToCurrent( |
| 450 | + private void createDataTableAttachment(final AllureExternalKey stepKey, |
| 451 | + final DataTableArgument dataTableArgument) { |
| 452 | + // the data table belongs to the step this adapter just started — address it by key |
| 453 | + lifecycle.addAttachment( |
| 454 | + stepKey, |
445 | 455 | "Data table", |
446 | 456 | "text/csv", |
447 | | - () -> new ByteArrayInputStream(toCsv(dataTableArgument).getBytes(StandardCharsets.UTF_8)), |
| 457 | + new ByteArrayInputStream(toCsv(dataTableArgument).getBytes(StandardCharsets.UTF_8)), |
448 | 458 | AttachmentOptions.empty() |
449 | 459 | ); |
450 | 460 | } |
@@ -472,24 +482,6 @@ private static String toCsv(final DataTableArgument dataTableArgument) { |
472 | 482 | return dataTableCsv.toString(); |
473 | 483 | } |
474 | 484 |
|
475 | | - /** |
476 | | - * Attaches to the current executable, or silently skips — including the content computation — when no |
477 | | - * executable is running (for example when Allure reporting is disabled). |
478 | | - */ |
479 | | - private void addAttachmentToCurrent(final String name, final String type, |
480 | | - final Supplier<InputStream> content, final AttachmentOptions options) { |
481 | | - lifecycle.getCurrentExecutableKey() |
482 | | - .ifPresent( |
483 | | - key -> lifecycle.addAttachment( |
484 | | - key, |
485 | | - name, |
486 | | - type, |
487 | | - content.get(), |
488 | | - options |
489 | | - ) |
490 | | - ); |
491 | | - } |
492 | | - |
493 | 485 | private void handleStopHookStep(final Result eventResult, |
494 | 486 | final HookTestStep hook) { |
495 | 487 | final String containerUuid = hookStepContainerUuid.get(hook.getId()); |
|
0 commit comments