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

net.serenitybdd.core.photography.ScreenshotNegative Maven / Gradle / Ivy

There is a newer version: 4.2.1
Show newest version
package net.serenitybdd.core.photography;

import com.google.common.base.Optional;
import net.thucydides.core.screenshots.BlurLevel;

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

public class ScreenshotNegative {
    private final Path temporaryPath;
    private final Path screenshotPath;
    private final BlurLevel blurLevel;

    public ScreenshotNegative(Path temporaryPath, Path screenshotPath, BlurLevel blurLevel) {
        this.temporaryPath = temporaryPath;
        this.screenshotPath = screenshotPath;
        this.blurLevel = Optional.fromNullable(blurLevel).or(BlurLevel.NONE);
    }

    public Path getTemporaryPath() {
        return temporaryPath;
    }

    public Path getScreenshotPath() {
        return screenshotPath;
    }

    public BlurLevel getBlurLevel() {
        return blurLevel;
    }

    public static ScreenshotNegativeBuilder prepareNegativeIn(Path screenshotsDirectory) {
        return new ScreenshotNegativeBuilder(screenshotsDirectory);
    }

    public ScreenshotNegative withScreenshotPath(Path path) {
        return new ScreenshotNegative(temporaryPath, path, blurLevel);
    }

    public static class ScreenshotNegativeBuilder {

        private final Path screenshotsDirectory;
        private byte[] screenshotData;
        private BlurLevel blurLevel = BlurLevel.NONE;

        public ScreenshotNegativeBuilder(Path screenshotsDirectory) {
            this.screenshotsDirectory = screenshotsDirectory;
        }

        public ScreenshotNegativeBuilder withScreenshotData(byte[] screenshotData) {
            this.screenshotData = screenshotData;
            return this;
        }


        public ScreenshotNegative andTargetPathOf(Path finalScreenshotPath) throws IOException {
            Files.createDirectories(screenshotsDirectory);
            Path screenshotWorkingFile = Files.createTempFile(screenshotsDirectory, "screenshot-", "");
            Files.write(screenshotWorkingFile, screenshotData);
            return new ScreenshotNegative(screenshotWorkingFile, finalScreenshotPath, blurLevel);
        }

        public ScreenshotNegativeBuilder andBlurringOf(BlurLevel blurLevel) {
            this.blurLevel = blurLevel;
            return this;
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy