All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.giulong.spectrum.utils.ExtentReporterInline Maven / Gradle / Ivy

There is a newer version: 1.14.2
Show newest version
package io.github.giulong.spectrum.utils;

import lombok.NoArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

import java.nio.file.Files;
import java.nio.file.Path;

import static lombok.AccessLevel.PRIVATE;

@Slf4j
@NoArgsConstructor(access = PRIVATE)
public class ExtentReporterInline extends ExtentReporter {

    private static final ExtentReporterInline INSTANCE = new ExtentReporterInline();

    private final HtmlUtils htmlUtils = HtmlUtils.getInstance();

    public static ExtentReporterInline getInstance() {
        return INSTANCE;
    }

    @Override
    public void sessionOpened() {
        log.debug("Session opened hook");

        final Configuration.Extent extent = configuration.getExtent();
        if (!extent.isInline()) {
            return;
        }

        final String reportPath = getReportPathFrom(extent).toString().replace("\\", "/");
        final String reportName = extent.getReportName();

        log.info("After the execution, you'll find the '{}' inline report at file:///{}", reportName, reportPath);
    }

    @SneakyThrows
    @Override
    public void sessionClosed() {
        log.debug("Session closed hook");

        final Configuration.Extent extent = configuration.getExtent();
        final String inlineReportFolder = extent.getInlineReportFolder();
        if (extent.isInline()) {
            final String inlineReport = htmlUtils.inline(Files.readString(super.getReportPathFrom(extent)));

            fileUtils.write(Path.of(inlineReportFolder, extent.getFileName()), inlineReport);
        }

        cleanupOldReportsIn(inlineReportFolder);
    }

    @Override
    public Path getReportPathFrom(final Configuration.Extent extent) {
        return Path.of(extent.getInlineReportFolder(), extent.getFileName()).toAbsolutePath();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy