allure-framework / allure-java

Allure integrations for Java test frameworks
Apache License 2.0
352 stars 223 forks source link

Unable to add links to report in Cucumber from code #483

Closed elantsov closed 5 months ago

elantsov commented 3 years ago

[//]: # ( . Note: for support questions, please use Stackoverflow or Gitter. . This repository's issues are reserved for feature requests and bug reports. . . In case of any problems with Allure Jenkins plugin please use the following repository . to create an issue: https://github.com/jenkinsci/allure-plugin/issues . . Make sure you have a clear name for your issue. The name should start with a capital . letter and no dot is required in the end of the sentence. An example of good issue names: . . - The report is broken in IE11 . - Add an ability to disable default plugins . - Support emoji in test descriptions )

I'm submitting a ...

What is the current behavior?

The links are not added to report if trying to add them from hooks or steps code as: Allure.link("https://example.org")

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem

Can't provide the demo project but I did a little research.

When Allure tries to add a link it makes: final Optional<String> root = threadContext.getRoot(); final String uuid = root.get(); final Optional<TestResult> found = storage.getTestResult(uuid);

The problem is that in threadContext there is only Cucumber step or fixture uuid (depending on the place feom which you run Allure.link) and there's no actual root uuid pointing to TestResult uuid. Therefore, found.isPresent == false and TestResult is not getting updated with the link.

Not sure, but I have a feeling that the root cause of this problem is threadContext.clear() that causes real root uuid to be lost.

It seems to have been working fine in Allure 2.9.0 and got broken in 2.10.0.

What is the expected behavior?

Allure.link should add links to the report if executed from Cucumber steps code and from Cucumber hooks code.

Please tell us about your environment:

Allure version 2.13.6
Test framework testng@7.1.0
Cucumber cucumber-spring@5.7.0
Allure integration allure-cucumber5-jvm@2.13.6
Generate report using allure-maven@2.10

Other information

[//]: # ( . e.g. detailed explanation, stacktraces, related issues, suggestions . how to fix, links for us to have more context, eg. Stackoverflow, Gitter etc )

elantsov commented 3 years ago

PR with breaking change is "Fix parallel run and rft lifecycle #253"

I've created a simple Cucumber Spring reproducer and detected the order of methods called in AllureLifecycle.java:

Therefore, unit test reproducing the issue is:

void shouldUpdateTestWithFixture() {
    final String containerUuid = randomId();
    final String containerName = randomName();
    TestResultContainer container = new TestResultContainer()
            .setUuid(containerUuid)
            .setName(containerName);
    lifecycle.startTestContainer(container);

    final String uuid = randomId();
    final String name = randomName();

    final TestResult result = new TestResult().setUuid(uuid).setName(name);
    lifecycle.scheduleTestCase(result);
    lifecycle.startTestCase(uuid);

    final String firstUuid = randomId();
    final String firstName = randomName();
    final FixtureResult first = new FixtureResult().setName(firstName);

    lifecycle.startPrepareFixture(containerUuid, firstUuid, first);
    lifecycle.stopFixture(firstUuid);

    final String stepUuid = randomId();
    final String stepName = randomName();

    final StepResult step = new StepResult().setName(stepName);
    lifecycle.startStep(uuid, stepUuid, step);

    final String description = randomName();
    final String fullName = randomName();

    lifecycle.updateTestCase(uuid, testResult -> testResult.setDescription(description));
    lifecycle.updateTestCase(testResult -> testResult.setFullName(fullName));

    lifecycle.stopStep(stepUuid);

    lifecycle.stopTestCase(uuid);

    lifecycle.stopTestContainer(containerUuid);

    lifecycle.writeTestCase(uuid);
    lifecycle.writeTestContainer(containerUuid);

    final ArgumentCaptor<TestResult> captor = forClass(TestResult.class);
    verify(writer, times(1)).write(captor.capture());

    final TestResult actual = captor.getValue();
    assertThat(actual)
            .isNotNull()
            .hasFieldOrPropertyWithValue("uuid", uuid)
            .hasFieldOrPropertyWithValue("description", description)
            .hasFieldOrPropertyWithValue("name", name)
            .hasFieldOrPropertyWithValue("fullName", fullName);

    assertThat(actual.getSteps())
            .flatExtracting(StepResult::getName)
            .containsExactly(stepName);
}

Proposed fix is to remove threadContext.clear() from methods startFixture and stopFixture. Not quite sure if it breaks something as all unit tests pass with this fix.

elantsov commented 3 years ago

PR with proposed fix #531

ylazakovich commented 2 years ago

@elantsov try to use the follow tags like in this example https://github.com/allure-framework/allure-java/blob/master/allure-cucumber6-jvm/src/test/resources/features/tags.feature#L4 In cucumber it works, I checked

elantsov commented 2 years ago

@y-lazakovich as far as I recall the issue reproduces only if you try to add a link programmatically like this Allure.link("https://example.org"). And in our case we had to add them dynamically.

baev commented 5 months ago

fixed via https://github.com/allure-framework/allure-java/pull/1011

released as 2.26.0