Skip to content
Closed
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
2 changes: 1 addition & 1 deletion allure-selenide/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
description = "Allure Selenide Integration"

val selenideVersion = "5.1.0"
val selenideVersion = "5.2.3"

dependencies {
api(project(":allure-java-commons"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@
*/
@SuppressWarnings("unused")
public class AllureSelenide implements LogEventListener {

private boolean saveScreenshots = true;
private boolean savePageHtml = true;

private String stepUUID;

private final AllureLifecycle lifecycle;

public AllureSelenide() {
Expand All @@ -60,40 +61,39 @@ public AllureSelenide savePageSource(final boolean savePageHtml) {
}

@Override
public void onEvent(final LogEvent event) {
lifecycle.getCurrentTestCase().ifPresent(uuid -> {
final String stepUUID = UUID.randomUUID().toString();
lifecycle.startStep(stepUUID, new StepResult()
.setName(event.toString())
.setStatus(Status.PASSED));
public void beforeEvent(final LogEvent event) {
stepUUID = UUID.randomUUID().toString();
Copy link

Choose a reason for hiding this comment

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

should it really set status to PASSED? Unlike in the old implementation, this is logged before event even happened.

Copy link
Author

Choose a reason for hiding this comment

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

Previous logic not changed. Except lifecycle.getCurrentTestCase unwrap that was unused before.

lifecycle.startStep(stepUUID, new StepResult()
.setName(event.toString())
.setStatus(Status.PASSED));
}

lifecycle.updateStep(stepResult -> stepResult.setStart(stepResult.getStart() - event.getDuration()));
@Override
public void afterEvent(final LogEvent event) {
lifecycle.updateStep(stepResult -> stepResult.setStart(stepResult.getStart() - event.getDuration()));

if (LogEvent.EventStatus.FAIL.equals(event.getStatus())) {
if (saveScreenshots) {
lifecycle.addAttachment("Screenshot", "image/png", "png", getScreenshotBytes());
}
if (savePageHtml) {
lifecycle.addAttachment("Page source", "text/html", "html", getPageSourceBytes());
}
lifecycle.updateStep(stepResult -> {
final StatusDetails details = ResultsUtils.getStatusDetails(event.getError())
.orElse(new StatusDetails());
stepResult.setStatus(ResultsUtils.getStatus(event.getError()).orElse(Status.BROKEN));
stepResult.setStatusDetails(details);
});
if (LogEvent.EventStatus.FAIL.equals(event.getStatus())) {
if (saveScreenshots) {
lifecycle.addAttachment("Screenshot", "image/png", "png", getScreenshotBytes());
}
lifecycle.stopStep(stepUUID);
});
if (savePageHtml) {
lifecycle.addAttachment("Page source", "text/html", "html", getPageSourceBytes());
}
lifecycle.updateStep(stepResult -> {
final StatusDetails details = ResultsUtils.getStatusDetails(event.getError())
.orElse(new StatusDetails());
stepResult.setStatus(ResultsUtils.getStatus(event.getError()).orElse(Status.BROKEN));
stepResult.setStatusDetails(details);
});
}
lifecycle.stopStep(stepUUID);
}


private static byte[] getScreenshotBytes() {
return ((TakesScreenshot) WebDriverRunner.getWebDriver()).getScreenshotAs(OutputType.BYTES);
}

private static byte[] getPageSourceBytes() {
return WebDriverRunner.getWebDriver().getPageSource().getBytes(StandardCharsets.UTF_8);
}

}