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

fix(allure-karate): fix duplicate scenarios when call or callonce keywords are used #1144

Merged
merged 3 commits into from
Nov 29, 2024

Conversation

umitozdemirf
Copy link
Contributor

@umitozdemirf umitozdemirf commented Nov 27, 2024

Context

Problem

  • Steps like call and callonce were being treated as separate test scenarios.
  • This was inflating the test count in Allure and making the reports harder to read.

Solution

  1. Locate the Issue:

    • Found that the issue was in the beforeStep and afterStep methods in the AllureKarate class.
  2. Update beforeStep:

    • Added a check to skip steps that start with call or callonce:
      @Override
      public boolean beforeStep(final Step step, final ScenarioRuntime sr) {
          final String parentUuid = (String) sr.magicVariables.get(ALLURE_UUID);
          if (Objects.isNull(parentUuid)) {
              return true;
          }
      
          // Skip 'call' and 'callonce' steps
          if (step.getText().startsWith("call") || step.getText().startsWith("callonce")) {
              LOGGER.info("Skipping Allure for call/callonce: " + step.getText());
              return true;
          }
      
          final String uuid = parentUuid + "-" + step.getIndex();
          final io.qameta.allure.model.StepResult stepResult = new io.qameta.allure.model.StepResult()
                  .setName(step.getText());
          lifecycle.startStep(parentUuid, uuid, stepResult);
      
          return true;
      }
  3. Update afterStep:

    • Also skipped these steps in afterStep to avoid processing them as separate tests:
      @Override
      public void afterStep(final StepResult result, final ScenarioRuntime sr) {
          final String parentUuid = (String) sr.magicVariables.get(ALLURE_UUID);
          if (Objects.isNull(parentUuid)) {
              return;
          }
      
          final Step step = result.getStep();
      
          // Skip 'call' and 'callonce' steps
          if (step.getText().startsWith("call") || step.getText().startsWith("callonce")) {
              LOGGER.info("Skipping Allure for call/callonce: " + step.getText());
              return;
          }
      
          final String uuid = parentUuid + "-" + step.getIndex();
          final Result stepResult = result.getResult();
      
          final Status status = !stepResult.isFailed()
                  ? Status.PASSED
                  : Optional.of(stepResult)
                          .map(Result::getError)
                          .flatMap(ResultsUtils::getStatus)
                          .orElse(null);
      
          final StatusDetails statusDetails = Optional.of(stepResult)
                  .map(Result::getError)
                  .flatMap(ResultsUtils::getStatusDetails)
                  .orElse(null);
      
          lifecycle.updateStep(uuid, s -> {
              s.setStatus(status);
              s.setStatusDetails(statusDetails);
          });
          lifecycle.stopStep(uuid);
      }
  4. Test the Fix:

    • After these changes, I tested the setup, and the call and callonce steps now show up as part of the parent scenario, not as separate tests.

Result

  • Test counts in Allure are accurate now.
  • Reports look much cleaner and more understandable.

Checklist

@CLAassistant
Copy link

CLAassistant commented Nov 27, 2024

CLA assistant check
All committers have signed the CLA.

@umitozdemirf umitozdemirf changed the title Call & Callonce duplicate bug fix (fixes #1143\) Call & Callonce duplicate bug fix (fixes #1143\) type:bug Nov 27, 2024
@baev baev added the type:bug Something isn't working label Nov 29, 2024
Copy link
Member

@baev baev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a test & sign CLA

@umitozdemirf
Copy link
Contributor Author

@baev I added tests and fix commit user, thank you.

@baev
Copy link
Member

baev commented Nov 29, 2024

@umitozdemirf great job 👍, thanks.

I would like to have spearate tests for call and callonce features as well as a test that checks the results metadata when call or callonce is used (you need to make sure all the steps are displayed correctly, no metadata is duplicated etc).

Feel free to provide an additional PR with such improvements!

@baev baev changed the title Call & Callonce duplicate bug fix (fixes #1143\) type:bug fix(allure-karate): fix duplicate scenarios when call or callonce keywords are used Nov 29, 2024
@baev baev merged commit af64da0 into allure-framework:main Nov 29, 2024
4 checks passed
@umitozdemirf
Copy link
Contributor Author

Thank you @baev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme:karate type:bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants