Skip to content
Merged
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 @@ -26,7 +26,6 @@
import com.intuit.karate.core.StepResult;
import io.qameta.allure.Allure;
import io.qameta.allure.AllureLifecycle;
import io.qameta.allure.model.Attachment;
import io.qameta.allure.model.Label;
import io.qameta.allure.model.Link;
import io.qameta.allure.model.Parameter;
Expand All @@ -50,8 +49,6 @@
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.stream.Collectors;

import static io.qameta.allure.util.ResultsUtils.createLabel;
Expand All @@ -71,11 +68,6 @@ public class AllureKarate implements RuntimeHook {

private final AllureLifecycle lifecycle;

private final ReadWriteLock lock = new ReentrantReadWriteLock();

private final Map<String, String> stepsAndTcUuids = new HashMap<>();
private final Map<String, Step> stepAndUuids = new HashMap<>();

private final List<String> tcUuids = new ArrayList<>();

public AllureKarate() {
Expand Down Expand Up @@ -221,14 +213,6 @@ public void afterStep(final StepResult result,
});
lifecycle.stopStep(uuid);

if (stepResult.isFailed()
&& sr.engine.getConfig().getDriverOptions() != null
&& (Boolean) sr.engine.getConfig().getDriverOptions().get("screenshotOnFailure")
) {
addToStepsAndTcUuids(uuid, lifecycle.getCurrentTestCase().get());
addToStepAndUuids(uuid, step);
}

if (Objects.nonNull(result.getEmbeds())) {
result.getEmbeds().forEach(embed -> {
try (InputStream is = new BufferedInputStream(Files.newInputStream(embed.getFile().toPath()))) {
Expand All @@ -248,30 +232,6 @@ public void afterStep(final StepResult result,

@Override
public void afterFeature(final FeatureRuntime fr) {

if (!stepsAndTcUuids.isEmpty()) {
fr.result.getScenarioResults()
.forEach(sc -> {
if (Objects.nonNull(sc.getFailedStep())) {
getKeySetFromStepAndUuids().forEach(uuid -> {
if (getValueFromStepAndUuids(uuid) == sc.getFailedStep().getStep()) {
final List<Attachment> attachments = new ArrayList<>();
sc.getFailedStep().getEmbeds().forEach(e -> attachments.add(
new Attachment()
.setSource(e.getFile().getPath())
.setType(e.getResourceType().contentType)
.setName(e.getFile().getName())
)
);
lifecycle.updateTestCase(getValueFromStepsAndTcUuids(uuid), result ->
result.setAttachments(attachments)
);
}
});
}
});
}

tcUuids.forEach(lifecycle::writeTestCase);
}

Expand Down Expand Up @@ -321,49 +281,4 @@ private List<Link> getLinks(final List<String> labels) {
}
return allureLinks;
}

private void addToStepsAndTcUuids(final String stepUuid, final String tcUuid) {
lock.writeLock().lock();
try {
stepsAndTcUuids.put(stepUuid, tcUuid);
} finally {
lock.writeLock().unlock();
}
}

private void addToStepAndUuids(final String stepUuid, final Step step) {
lock.writeLock().lock();
try {
stepAndUuids.put(stepUuid, step);
} finally {
lock.writeLock().unlock();
}
}

private String getValueFromStepsAndTcUuids(final String stepUuid) {
lock.readLock().lock();
try {
return stepsAndTcUuids.get(stepUuid);
} finally {
lock.readLock().unlock();
}
}

private Step getValueFromStepAndUuids(final String stepUuid) {
lock.readLock().lock();
try {
return stepAndUuids.get(stepUuid);
} finally {
lock.readLock().unlock();
}
}

private Set<String> getKeySetFromStepAndUuids() {
lock.readLock().lock();
try {
return stepAndUuids.keySet();
} finally {
lock.readLock().unlock();
}
}
}