Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
1 task done
elantsov opened this issue Oct 26, 2020 · 5 comments
Closed
1 task done

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

elantsov opened this issue Oct 26, 2020 · 5 comments
Labels
theme:cucumber-jvm CucumberJVM related issue

Comments

@elantsov
Copy link

I'm submitting a ...

  • bug report

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

@elantsov
Copy link
Author

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:

  • startTestContainer
  • startTestCase
  • startPrepareFixture
  • startFixture
  • updateFixture
  • stopFixture
  • startStep
  • updateTestCase
  • updateStep
  • stopStep
  • stopTestCase
  • stopTestContainer
  • writeTestCase
  • writeTestContainer

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
Copy link
Author

PR with proposed fix #531

@ylazakovich
Copy link

ylazakovich commented Aug 29, 2022

@elantsov
Copy link
Author

elantsov commented Aug 30, 2022

@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 baev added the theme:cucumber-jvm CucumberJVM related issue label Sep 1, 2023
@baev
Copy link
Member

baev commented Mar 18, 2024

fixed via #1011

released as 2.26.0

@baev baev closed this as completed Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme:cucumber-jvm CucumberJVM related issue
Projects
None yet
Development

No branches or pull requests

3 participants