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);
}
}
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;
}
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()));
}
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"));
}
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);
}
Aggregations