Search in sources :

Example 1 with Parameters

use of de.otto.jlineup.config.Parameters in project jlineup by otto-de.

the class Main method main.

public static void main(String[] args) throws Exception {
    final Parameters parameters = new Parameters();
    final JCommander jCommander = new JCommander(parameters);
    jCommander.parse(args);
    jCommander.setProgramName("JLineup");
    if (parameters.isHelp()) {
        jCommander.usage();
        System.out.printf("Version: %s%n", Util.getVersion());
        return;
    }
    if (parameters.isVersion()) {
        System.out.printf("JLineup version %s", Util.getVersion());
        return;
    }
    if (parameters.isDebug()) {
        Util.setLogLevelToDebug();
    }
    Config config = null;
    try {
        config = buildConfig(parameters);
    } catch (FileNotFoundException e) {
        System.exit(1);
    }
    if (parameters.isPrintConfig()) {
        System.out.println(Util.createPrettyConfigJson(config));
        System.exit(0);
    }
    JLineupOptions jLineupOptions = new JLineupOptions(parameters);
    JLineup jLineup = new JLineup(config, jLineupOptions);
    int errorLevel = jLineup.run();
    if (errorLevel != 0) {
        System.exit(errorLevel);
    }
}
Also used : Parameters(de.otto.jlineup.config.Parameters) JCommander(com.beust.jcommander.JCommander) Config(de.otto.jlineup.config.Config) FileNotFoundException(java.io.FileNotFoundException)

Example 2 with Parameters

use of de.otto.jlineup.config.Parameters in project jlineup by otto-de.

the class ScreenshotsComparator method compare.

public Map<String, List<ScreenshotComparisonResult>> compare() throws IOException {
    LOG.debug("Comparing images...");
    if (config.urls == null) {
        LOG.debug("No urls configured, so no comparison.");
        return null;
    }
    Map<String, List<ScreenshotComparisonResult>> results = new HashMap<>();
    for (Map.Entry<String, UrlConfig> urlConfigEntry : config.urls.entrySet()) {
        List<ScreenshotComparisonResult> screenshotComparisonResults = new ArrayList<>();
        String url = BrowserUtils.prepareDomain(parameters, urlConfigEntry.getKey());
        UrlConfig urlConfig = urlConfigEntry.getValue();
        LOG.debug("Url: {}", url);
        for (String path : urlConfig.paths) {
            LOG.debug("Path: {}", path);
            String fullUrlWithPath = BrowserUtils.buildUrl(url, path, urlConfig.envMapping);
            final List<String> beforeFileNamesList = fileService.getFilenamesForStep(path, url, BEFORE);
            final List<String> afterFileNamesList = new ArrayList<>();
            beforeFileNamesList.forEach(filename -> afterFileNamesList.add(switchAfterWithBeforeInFileName(filename)));
            final Set<String> beforeFileNamesSet = new HashSet<>(beforeFileNamesList);
            final Set<String> afterFileNamesSet = new HashSet<>(fileService.getFilenamesForStep(path, url, AFTER));
            // we need after files that have no before file in the final report
            final List<String> afterFileNamesWithNoBeforeFile = new ArrayList<>();
            afterFileNamesSet.stream().filter(name -> !beforeFileNamesSet.contains(switchAfterWithBeforeInFileName(name))).forEach(afterFileNamesWithNoBeforeFile::add);
            for (int i = 0; i < beforeFileNamesList.size(); i++) {
                String beforeFileName = beforeFileNamesList.get(i);
                String afterFileName = afterFileNamesList.get(i);
                LOG.debug("Comparing '{}' with '{}'", beforeFileName, afterFileName);
                int yPosition = extractVerticalScrollPositionFromFileName(beforeFileName);
                int windowWidth = extractWindowWidthFromFileName(beforeFileName);
                BufferedImage imageBefore;
                try {
                    imageBefore = fileService.readScreenshot(beforeFileName);
                } catch (IIOException e) {
                    System.err.println("Can't read screenshot of 'before' step. Did you run JLineup with '--step before' parameter before trying to run '--step after' or --compare?");
                    throw e;
                }
                BufferedImage imageAfter;
                try {
                    imageAfter = fileService.readScreenshot(afterFileName);
                } catch (IIOException e) {
                    screenshotComparisonResults.add(ScreenshotComparisonResult.noAfterImageComparisonResult(fullUrlWithPath, windowWidth, yPosition, buildRelativePathFromReportDir(beforeFileName)));
                    continue;
                }
                ImageService.ImageComparisonResult imageComparisonResult = imageService.compareImages(imageBefore, imageAfter, config.windowHeight);
                String differenceImageFileName = null;
                if (imageComparisonResult.getDifference() > 0 && imageComparisonResult.getDifferenceImage().isPresent()) {
                    differenceImageFileName = Paths.get(fileService.writeScreenshot(imageComparisonResult.getDifferenceImage().orElse(null), url, path, windowWidth, yPosition, "DIFFERENCE")).getFileName().toString();
                }
                screenshotComparisonResults.add(new ScreenshotComparisonResult(fullUrlWithPath, windowWidth, yPosition, imageComparisonResult.getDifference(), buildRelativePathFromReportDir(beforeFileName), buildRelativePathFromReportDir(afterFileName), buildRelativePathFromReportDir(differenceImageFileName)));
            }
            addMissingBeforeFilesToResults(screenshotComparisonResults, fullUrlWithPath, afterFileNamesWithNoBeforeFile);
        }
        screenshotComparisonResults.sort(Comparator.<ScreenshotComparisonResult, String>comparing(r -> r.url).thenComparing(r -> r.width).thenComparing(r -> r.verticalScrollPosition));
        results.put(urlConfigEntry.getKey(), screenshotComparisonResults);
    }
    return results;
}
Also used : java.util(java.util) Logger(org.slf4j.Logger) BufferedImage(java.awt.image.BufferedImage) ImageService(de.otto.jlineup.image.ImageService) LoggerFactory(org.slf4j.LoggerFactory) UrlConfig(de.otto.jlineup.config.UrlConfig) IIOException(javax.imageio.IIOException) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) Config(de.otto.jlineup.config.Config) FileService(de.otto.jlineup.file.FileService) BrowserUtils(de.otto.jlineup.browser.BrowserUtils) Matcher(java.util.regex.Matcher) Parameters(de.otto.jlineup.config.Parameters) Paths(java.nio.file.Paths) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Pattern(java.util.regex.Pattern) IIOException(javax.imageio.IIOException) ImageService(de.otto.jlineup.image.ImageService) BufferedImage(java.awt.image.BufferedImage) UrlConfig(de.otto.jlineup.config.UrlConfig)

Example 3 with Parameters

use of de.otto.jlineup.config.Parameters in project jlineup by otto-de.

the class BrowserUtilsTest method shouldGenerateScreenshotsParameters.

@Test
public void shouldGenerateScreenshotsParameters() throws FileNotFoundException {
    // given
    Parameters parameters = mock(Parameters.class);
    Config config = Config.readConfig(".", "src/test/resources/lineup_test.json");
    when(parameters.getWorkingDirectory()).thenReturn("some/working/dir");
    when(parameters.getScreenshotDirectory()).thenReturn("screenshots");
    when(parameters.getUrlReplacements()).thenReturn(ImmutableMap.of("google", "doodle"));
    UrlConfig expectedUrlConfigForOttoDe = getExpectedUrlConfigForOttoDe();
    UrlConfig expectedUrlConfigForGoogleDe = getExpectedUrlConfigForGoogleDe();
    final List<ScreenshotContext> expectedScreenshotContextList = ImmutableList.of(ScreenshotContext.of("https://www.otto.de", "/", 600, true, expectedUrlConfigForOttoDe), ScreenshotContext.of("https://www.otto.de", "/", 800, true, expectedUrlConfigForOttoDe), ScreenshotContext.of("https://www.otto.de", "/", 1200, true, expectedUrlConfigForOttoDe), ScreenshotContext.of("https://www.otto.de", "multimedia", 600, true, expectedUrlConfigForOttoDe), ScreenshotContext.of("https://www.otto.de", "multimedia", 800, true, expectedUrlConfigForOttoDe), ScreenshotContext.of("https://www.otto.de", "multimedia", 1200, true, expectedUrlConfigForOttoDe), ScreenshotContext.of("http://www.doodle.de", "/", 1200, true, expectedUrlConfigForGoogleDe));
    // when
    final List<ScreenshotContext> screenshotContextList = BrowserUtils.buildScreenshotContextListFromConfigAndState(parameters, config, true);
    // then
    assertThat(screenshotContextList, containsInAnyOrder(expectedScreenshotContextList.toArray()));
}
Also used : Parameters(de.otto.jlineup.config.Parameters) UrlConfig(de.otto.jlineup.config.UrlConfig) UrlConfig(de.otto.jlineup.config.UrlConfig) Config(de.otto.jlineup.config.Config) Test(org.junit.Test)

Example 4 with Parameters

use of de.otto.jlineup.config.Parameters in project jlineup by otto-de.

the class BrowserUtilsTest method shouldPrepareDomain.

@Test
public void shouldPrepareDomain() {
    // given
    Parameters parameters = mock(Parameters.class);
    when(parameters.getUrlReplacements()).thenReturn(ImmutableMap.of(".otto.", ".bonprix."));
    // when
    String result = BrowserUtils.prepareDomain(parameters, "www.otto.de");
    // then
    assertThat(result, is("www.bonprix.de"));
}
Also used : Parameters(de.otto.jlineup.config.Parameters) Test(org.junit.Test)

Example 5 with Parameters

use of de.otto.jlineup.config.Parameters in project jlineup by otto-de.

the class ScreenshotsComparatorTest method setup.

@Before
public void setup() {
    initMocks(this);
    parameters = new Parameters();
    JCommander jCommander = new JCommander(parameters);
    jCommander.parse("-d", "src/test/resources/");
    config = configBuilder().withUrls(ImmutableMap.of("http://url", new UrlConfig(ImmutableList.of("/"), 0.05f, null, null, null, null, ImmutableList.of(1001), 10000, 2, 0, 0, 0, null, 5))).withWindowHeight(WINDOW_HEIGHT).build();
    testee = new ScreenshotsComparator(parameters, config, fileService, imageService);
}
Also used : Parameters(de.otto.jlineup.config.Parameters) UrlConfig(de.otto.jlineup.config.UrlConfig) JCommander(com.beust.jcommander.JCommander) Before(org.junit.Before)

Aggregations

Parameters (de.otto.jlineup.config.Parameters)5 Config (de.otto.jlineup.config.Config)3 UrlConfig (de.otto.jlineup.config.UrlConfig)3 JCommander (com.beust.jcommander.JCommander)2 Test (org.junit.Test)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 BrowserUtils (de.otto.jlineup.browser.BrowserUtils)1 FileService (de.otto.jlineup.file.FileService)1 ImageService (de.otto.jlineup.image.ImageService)1 BufferedImage (java.awt.image.BufferedImage)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 Paths (java.nio.file.Paths)1 java.util (java.util)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1 IIOException (javax.imageio.IIOException)1 Before (org.junit.Before)1 Logger (org.slf4j.Logger)1