Skip to content
This repository has been archived by the owner on May 21, 2023. It is now read-only.

#15 AllureStepListener stop steps #16

Merged
merged 2 commits into from
Mar 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.plugatar.xteps.core.StepListener;
import io.qameta.allure.Allure;
import io.qameta.allure.AllureLifecycle;
import io.qameta.allure.model.Status;
import io.qameta.allure.model.StatusDetails;
import io.qameta.allure.model.StepResult;
Expand Down Expand Up @@ -49,10 +50,12 @@ public final void stepStarted(final String uuid,
@Override
public final void stepPassed(final String uuid,
final String stepName) {
Allure.getLifecycle().updateStep(
final AllureLifecycle allureLifecycle = Allure.getLifecycle();
allureLifecycle.updateStep(
uuid,
step -> step.setStatus(Status.PASSED)
);
allureLifecycle.stopStep(uuid);
}

@Override
Expand All @@ -61,9 +64,11 @@ public final void stepFailed(final String uuid,
final Throwable throwable) {
final Status status = ResultsUtils.getStatus(throwable).get();
final StatusDetails statusDetails = ResultsUtils.getStatusDetails(throwable).get();
Allure.getLifecycle().updateStep(
final AllureLifecycle allureLifecycle = Allure.getLifecycle();
allureLifecycle.updateStep(
uuid,
step -> step.setStatus(status).setStatusDetails(statusDetails)
);
allureLifecycle.stopStep(uuid);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@

import io.qameta.allure.Allure;
import io.qameta.allure.model.Stage;
import io.qameta.allure.model.Status;
import io.qameta.allure.model.StepResult;
import io.qameta.allure.util.ResultsUtils;
import org.junit.jupiter.api.Test;

import java.lang.reflect.Modifier;
Expand Down Expand Up @@ -73,15 +71,11 @@ void stepPassedMethod() {
listener.stepPassed(uuid, stepName);
final AtomicReference<StepResult> stepResult = new AtomicReference<>();
Allure.getLifecycle().updateStep(uuid, stepResult::set);
assertThat(stepResult.get()).isEqualTo(
new StepResult().setName(stepName)
.setStage(Stage.RUNNING)
.setStatus(Status.PASSED)
);
assertThat(stepResult.get()).isNull();
}

@Test
void stepFailedForAssertionErrorMethod() {
void stepFailedMethod() {
final AllureStepListener listener = new AllureStepListener();
final String uuid = UUID.randomUUID().toString();
final String stepName = "step name";
Expand All @@ -91,30 +85,6 @@ void stepFailedForAssertionErrorMethod() {
listener.stepFailed(uuid, stepName, error);
final AtomicReference<StepResult> stepResult = new AtomicReference<>();
Allure.getLifecycle().updateStep(uuid, stepResult::set);
assertThat(stepResult.get()).isEqualTo(
new StepResult().setName(stepName)
.setStage(Stage.RUNNING)
.setStatus(Status.FAILED)
.setStatusDetails(ResultsUtils.getStatusDetails(error).get())
);
}

@Test
void stepFailedForNotAssertionErrorMethod() {
final AllureStepListener listener = new AllureStepListener();
final String uuid = UUID.randomUUID().toString();
final String stepName = "step name";
final Throwable throwable = new Throwable();
Allure.getLifecycle().startStep(uuid, new StepResult().setName(stepName));

listener.stepFailed(uuid, stepName, throwable);
final AtomicReference<StepResult> stepResult = new AtomicReference<>();
Allure.getLifecycle().updateStep(uuid, stepResult::set);
assertThat(stepResult.get()).isEqualTo(
new StepResult().setName(stepName)
.setStage(Stage.RUNNING)
.setStatus(Status.BROKEN)
.setStatusDetails(ResultsUtils.getStatusDetails(throwable).get())
);
assertThat(stepResult.get()).isNull();
}
}