
de.otto.jlineup.config.UrlConfig Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jlineup-core Show documentation
Show all versions of jlineup-core Show documentation
The core module of JLineup
The newest version!
package de.otto.jlineup.config;
import com.fasterxml.jackson.annotation.JsonAlias;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.google.common.collect.ImmutableList;
import java.util.*;
import java.util.stream.Collectors;
import static de.otto.jlineup.config.JobConfig.*;
@JsonDeserialize(builder = UrlConfig.Builder.class)
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class UrlConfig {
public final String url;
public final List paths;
public final List setupPaths;
public final List cleanupPaths;
public final double maxDiff;
public final List cookies;
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public final List> alternatingCookies;
public final Map envMapping;
public final Map localStorage;
public final Map sessionStorage;
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public final List windowWidths;
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public final List devices;
public final int maxScrollHeight;
public final float waitAfterPageLoad;
public final float waitAfterScroll;
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
public final float waitForNoAnimationAfterScroll;
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
public final float warmupBrowserCacheTime;
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
public final float waitForFontsTime;
@JsonProperty("javascript")
public final String javaScript;
@JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = HttpCheckFilter.class)
public final HttpCheckConfig httpCheck;
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
public final boolean hideImages;
public final Set removeSelectors;
public final Set waitForSelectors;
public final float waitForSelectorsTimeout;
public final boolean failIfSelectorsNotFound;
public final boolean ignoreAntiAliasing;
public final double maxAntiAliasColorDistance;
public final boolean strictColorComparison;
public final double maxColorDistance;
/* For Jackson */
private UrlConfig() {
this.url = null;
this.paths = null;
this.setupPaths = null;
this.cleanupPaths = null;
this.maxDiff = DEFAULT_MAX_DIFF;
this.cookies = null;
this.alternatingCookies = null;
this.envMapping = null;
this.localStorage = null;
this.sessionStorage = null;
this.windowWidths = null;
this.devices = null;
this.maxScrollHeight = DEFAULT_MAX_SCROLL_HEIGHT;
this.waitAfterPageLoad = DEFAULT_WAIT_AFTER_PAGE_LOAD;
this.waitAfterScroll = DEFAULT_WAIT_AFTER_SCROLL;
this.waitForNoAnimationAfterScroll = DEFAULT_WAIT_FOR_NO_ANIMATION_AFTER_SCROLL;
this.warmupBrowserCacheTime = DEFAULT_WARMUP_BROWSER_CACHE_TIME;
this.waitForFontsTime = DEFAULT_WAIT_FOR_FONTS_TIME;
this.javaScript = null;
this.httpCheck = DEFAULT_HTTP_CHECK_CONFIG;
this.hideImages = false;
this.removeSelectors = null;
this.waitForSelectors = null;
this.waitForSelectorsTimeout = DEFAULT_WAIT_FOR_SELECTORS_TIMEOUT;
this.failIfSelectorsNotFound = false;
this.ignoreAntiAliasing = false;
this.maxAntiAliasColorDistance = DEFAULT_MAX_ANTI_ALIAS_COLOR_DISTANCE;
this.strictColorComparison = false;
this.maxColorDistance = DEFAULT_MAX_COLOR_DISTANCE;
}
private UrlConfig(Builder builder) {
url = builder.url;
paths = builder.paths;
setupPaths = builder.setupPaths;
cleanupPaths = builder.cleanupPaths;
maxDiff = builder.maxDiff;
cookies = builder.cookies;
alternatingCookies = builder.alternatingCookies;
envMapping = builder.envMapping;
localStorage = builder.localStorage;
sessionStorage = builder.sessionStorage;
windowWidths = builder.windowWidths;
devices = builder.devices;
maxScrollHeight = builder.maxScrollHeight;
waitAfterPageLoad = builder.waitAfterPageLoad;
waitAfterScroll = builder.waitAfterScroll;
waitForNoAnimationAfterScroll = builder.waitForNoAnimationAfterScroll;
warmupBrowserCacheTime = builder.warmupBrowserCacheTime;
waitForFontsTime = builder.waitForFontsTime;
javaScript = builder.javaScript;
httpCheck = builder.httpCheck;
hideImages = builder.hideImages;
ignoreAntiAliasing = builder.ignoreAntiAliasing;
maxAntiAliasColorDistance = builder.maxAntiAliasColorDistance;
strictColorComparison = builder.strictColorComparison;
maxColorDistance = builder.maxColorDistance;
removeSelectors = builder.removeSelectors;
waitForSelectors = builder.waitForSelectors;
waitForSelectorsTimeout = builder.waitForSelectorsTimeout;
failIfSelectorsNotFound = builder.failIfSelectorsNotFound;
}
/*
*
*
*
* BEGIN of getters block
*
* For GraalVM (JSON is empty if no getters are here)
*
*
*
*/
public String getUrl() {
return url;
}
public List getPaths() {
return paths;
}
public List getSetupPaths() {
return setupPaths;
}
public List getCleanupPaths() {
return cleanupPaths;
}
public double getMaxDiff() {
return maxDiff;
}
public List getCookies() {
return cookies;
}
public List> getAlternatingCookies() {
return alternatingCookies;
}
public Map getEnvMapping() {
return envMapping;
}
public Map getLocalStorage() {
return localStorage;
}
public Map getSessionStorage() {
return sessionStorage;
}
public List getWindowWidths() {
return windowWidths;
}
public List getDevices() {
return devices;
}
public int getMaxScrollHeight() {
return maxScrollHeight;
}
public float getWaitAfterPageLoad() {
return waitAfterPageLoad;
}
public float getWaitAfterScroll() {
return waitAfterScroll;
}
public float getWaitForNoAnimationAfterScroll() {
return waitForNoAnimationAfterScroll;
}
public float getWarmupBrowserCacheTime() {
return warmupBrowserCacheTime;
}
public float getWaitForFontsTime() {
return waitForFontsTime;
}
public String getJavaScript() {
return javaScript;
}
public HttpCheckConfig getHttpCheck() {
return httpCheck;
}
public boolean isHideImages() {
return hideImages;
}
public boolean isIgnoreAntiAliasing() {
return ignoreAntiAliasing;
}
public double getMaxAntiAliasColorDistance() {
return maxAntiAliasColorDistance;
}
public boolean isStrictColorComparison() {
return strictColorComparison;
}
public double getMaxColorDistance() {
return maxColorDistance;
}
public Set getRemoveSelectors() {
return removeSelectors;
}
public Set getWaitForSelectors() {
return waitForSelectors;
}
public float getWaitForSelectorsTimeout() {
return waitForSelectorsTimeout;
}
public boolean isFailIfSelectorsNotFound() {
return failIfSelectorsNotFound;
}
/*
*
*
*
* END of getters block
*
* For GraalVM (JSON is empty if no getters are here)
*
*
*
*/
public static Builder urlConfigBuilder() {
return new Builder();
}
public static Builder copyOfBuilder(UrlConfig copy) {
Builder builder = new Builder();
builder.url = copy.url;
builder.setupPaths = copy.setupPaths;
builder.cleanupPaths = copy.cleanupPaths;
builder.paths = copy.paths;
builder.maxDiff = copy.maxDiff;
builder.cookies = copy.cookies;
builder.alternatingCookies = copy.alternatingCookies;
builder.envMapping = copy.envMapping;
builder.localStorage = copy.localStorage;
builder.sessionStorage = copy.sessionStorage;
builder.windowWidths = copy.windowWidths;
builder.devices = copy.devices;
builder.maxScrollHeight = copy.maxScrollHeight;
builder.waitAfterPageLoad = copy.waitAfterPageLoad;
builder.waitAfterScroll = copy.waitAfterScroll;
builder.waitForNoAnimationAfterScroll = copy.waitForNoAnimationAfterScroll;
builder.warmupBrowserCacheTime = copy.warmupBrowserCacheTime;
builder.waitForFontsTime = copy.waitForFontsTime;
builder.javaScript = copy.javaScript;
builder.httpCheck = copy.httpCheck;
builder.hideImages = copy.hideImages;
builder.ignoreAntiAliasing = copy.ignoreAntiAliasing;
builder.maxAntiAliasColorDistance = copy.maxAntiAliasColorDistance;
builder.strictColorComparison = copy.strictColorComparison;
builder.maxColorDistance = copy.maxColorDistance;
builder.removeSelectors = copy.removeSelectors;
builder.waitForSelectors = copy.waitForSelectors;
builder.waitForSelectorsTimeout = copy.waitForSelectorsTimeout;
builder.failIfSelectorsNotFound = copy.failIfSelectorsNotFound;
return builder;
}
/**
* This replaces all cookie, local and session storage values with sanitized values.
*/
public UrlConfig sanitize() {
return copyOfBuilder(this)
.withCookies(cookies != null ? cookies.stream().map(Cookie::sanitize).collect(Collectors.toList()) : null)
.withAlternatingCookies(alternatingCookies != null ? alternatingCookies.stream().map(alternatingCookies -> alternatingCookies.stream().map(Cookie::sanitize).collect(Collectors.toList())).collect(Collectors.toList()) : null)
.withLocalStorage(localStorage != null ? localStorage.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> "*****")) : null)
.withSessionStorage(sessionStorage != null ? sessionStorage.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> "*****")) : null)
.build();
}
//@JsonNaming(PropertyNamingStrategy.KebabCaseStrategy.class)
public static final class Builder {
private String url = null;
private List paths = null;
private List setupPaths = Collections.emptyList();
private List cleanupPaths = Collections.emptyList();
private double maxDiff = DEFAULT_MAX_DIFF;
private List cookies;
private List> alternatingCookies = Collections.emptyList();
private Map envMapping;
private Map localStorage;
private Map sessionStorage;
private List windowWidths;
private List devices;
private int maxScrollHeight = DEFAULT_MAX_SCROLL_HEIGHT;
private float waitAfterPageLoad = DEFAULT_WAIT_AFTER_PAGE_LOAD;
private float waitAfterScroll = DEFAULT_WAIT_AFTER_SCROLL;
private float waitForNoAnimationAfterScroll = DEFAULT_WAIT_FOR_NO_ANIMATION_AFTER_SCROLL;
private float warmupBrowserCacheTime = DEFAULT_WARMUP_BROWSER_CACHE_TIME;
private float waitForFontsTime = DEFAULT_WAIT_FOR_FONTS_TIME;
private String javaScript;
private HttpCheckConfig httpCheck = DEFAULT_HTTP_CHECK_CONFIG;
private boolean hideImages;
private boolean ignoreAntiAliasing;
private double maxAntiAliasColorDistance = DEFAULT_MAX_ANTI_ALIAS_COLOR_DISTANCE;
private boolean strictColorComparison;
private double maxColorDistance = DEFAULT_MAX_COLOR_DISTANCE;
private Set removeSelectors;
private Set waitForSelectors;
private float waitForSelectorsTimeout = DEFAULT_WAIT_FOR_SELECTORS_TIMEOUT;
private boolean failIfSelectorsNotFound;
private Builder() {
}
public Builder withUrl(String val) {
url = val;
return this;
}
public Builder withPaths(List val) {
paths = val;
return this;
}
public Builder withSetupPaths(List val) {
setupPaths = val;
return this;
}
public Builder withCleanupPaths(List val) {
cleanupPaths = val;
return this;
}
public Builder withMaxDiff(double val) {
maxDiff = val;
return this;
}
public Builder withCookies(List val) {
cookies = val;
return this;
}
public Builder withCookie(Cookie val) {
cookies = Collections.singletonList(val);
return this;
}
public Builder withAlternatingCookies(List> val) {
//Magic! Alternating cookies are automagically screenshot context giving!
alternatingCookies = val != null ? val.stream().map(alternatingCookies -> alternatingCookies != null ? alternatingCookies.stream().map(cookie -> Cookie.copyOfBuilder(cookie).withScreenshotContextGiving(true).build()).collect(Collectors.toList()) : null).collect(Collectors.toList()) : null;
return this;
}
public Builder withEnvMapping(Map val) {
envMapping = val;
return this;
}
public Builder withHttpCheck(HttpCheckConfig val) {
httpCheck = val;
return this;
}
public Builder withLocalStorage(Map val) {
localStorage = val;
return this;
}
public Builder withSessionStorage(Map val) {
sessionStorage = val;
return this;
}
@JsonAlias({"resolutions","widths"})
public Builder withWindowWidths(List val) {
windowWidths = val;
return this;
}
public Builder withDevices(List val) {
devices = val;
return this;
}
public Builder addDeviceConfig(DeviceConfig deviceConfig) {
if (devices == null) {
devices = new ArrayList<>();
}
devices.add(deviceConfig);
return this;
}
public Builder withMaxScrollHeight(int val) {
maxScrollHeight = val;
return this;
}
public Builder withWaitAfterPageLoad(float val) {
waitAfterPageLoad = val;
return this;
}
public Builder withWaitAfterScroll(float val) {
waitAfterScroll = val;
return this;
}
public Builder withWaitForNoAnimationAfterScroll(float val) {
waitForNoAnimationAfterScroll = val;
return this;
}
public Builder withWarmupBrowserCacheTime(float val) {
warmupBrowserCacheTime = val;
return this;
}
public Builder withWaitForFontsTime(float val) {
waitForFontsTime = val;
return this;
}
@JsonProperty("javascript")
public Builder withJavaScript(String val) {
javaScript = val;
return this;
}
public Builder withHideImages(boolean val) {
hideImages = val;
return this;
}
public Builder withIgnoreAntiAliasing(boolean val) {
ignoreAntiAliasing = val;
return this;
}
public Builder withMaxAntiAliasColorDistance(double val) {
maxAntiAliasColorDistance = val;
return this;
}
public Builder withStrictColorComparison(boolean val) {
strictColorComparison = val;
return this;
}
public Builder withMaxColorDistance(double val) {
maxColorDistance = val;
return this;
}
public Builder withRemoveSelectors(Set val) {
removeSelectors = val;
return this;
}
public Builder withWaitForSelectors(Set val) {
waitForSelectors = val;
return this;
}
public Builder withWaitForSelectorsTimeout(float val) {
waitForSelectorsTimeout = val;
return this;
}
public Builder withFailIfSelectorsNotFound(boolean val) {
failIfSelectorsNotFound = val;
return this;
}
public Builder withPath(String val) {
paths = ImmutableList.of(val);
return this;
}
public UrlConfig build() {
return new UrlConfig(this);
}
}
@Override
public String toString() {
return "UrlConfig{" +
"url='" + url + '\'' +
", paths=" + paths +
", setupPaths=" + setupPaths +
", cleanupPaths=" + cleanupPaths +
", maxDiff=" + maxDiff +
", cookies=" + cookies +
", alternatingCookies=" + alternatingCookies +
", envMapping=" + envMapping +
", localStorage=" + localStorage +
", sessionStorage=" + sessionStorage +
", windowWidths=" + windowWidths +
", devices=" + devices +
", maxScrollHeight=" + maxScrollHeight +
", waitAfterPageLoad=" + waitAfterPageLoad +
", waitAfterScroll=" + waitAfterScroll +
", waitForNoAnimationAfterScroll=" + waitForNoAnimationAfterScroll +
", warmupBrowserCacheTime=" + warmupBrowserCacheTime +
", waitForFontsTime=" + waitForFontsTime +
", javaScript='" + javaScript + '\'' +
", httpCheck=" + httpCheck +
", hideImages=" + hideImages +
", removeSelectors=" + removeSelectors +
", waitForSelectors=" + waitForSelectors +
", waitForSelectorsTimeout=" + waitForSelectorsTimeout +
", failIfSelectorsNotFound=" + failIfSelectorsNotFound +
", ignoreAntiAliasing=" + ignoreAntiAliasing +
", maxAntiAliasColorDistance=" + maxAntiAliasColorDistance +
", strictColorComparison=" + strictColorComparison +
", maxColorDistance=" + maxColorDistance +
'}';
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
UrlConfig urlConfig = (UrlConfig) o;
return Double.compare(maxDiff, urlConfig.maxDiff) == 0 && maxScrollHeight == urlConfig.maxScrollHeight && Float.compare(waitAfterPageLoad, urlConfig.waitAfterPageLoad) == 0 && Float.compare(waitAfterScroll, urlConfig.waitAfterScroll) == 0 && Float.compare(waitForNoAnimationAfterScroll, urlConfig.waitForNoAnimationAfterScroll) == 0 && Float.compare(warmupBrowserCacheTime, urlConfig.warmupBrowserCacheTime) == 0 && Float.compare(waitForFontsTime, urlConfig.waitForFontsTime) == 0 && hideImages == urlConfig.hideImages && Float.compare(waitForSelectorsTimeout, urlConfig.waitForSelectorsTimeout) == 0 && failIfSelectorsNotFound == urlConfig.failIfSelectorsNotFound && ignoreAntiAliasing == urlConfig.ignoreAntiAliasing && Double.compare(maxAntiAliasColorDistance, urlConfig.maxAntiAliasColorDistance) == 0 && strictColorComparison == urlConfig.strictColorComparison && Double.compare(maxColorDistance, urlConfig.maxColorDistance) == 0 && Objects.equals(url, urlConfig.url) && Objects.equals(paths, urlConfig.paths) && Objects.equals(setupPaths, urlConfig.setupPaths) && Objects.equals(cleanupPaths, urlConfig.cleanupPaths) && Objects.equals(cookies, urlConfig.cookies) && Objects.equals(alternatingCookies, urlConfig.alternatingCookies) && Objects.equals(envMapping, urlConfig.envMapping) && Objects.equals(localStorage, urlConfig.localStorage) && Objects.equals(sessionStorage, urlConfig.sessionStorage) && Objects.equals(windowWidths, urlConfig.windowWidths) && Objects.equals(devices, urlConfig.devices) && Objects.equals(javaScript, urlConfig.javaScript) && Objects.equals(httpCheck, urlConfig.httpCheck) && Objects.equals(removeSelectors, urlConfig.removeSelectors) && Objects.equals(waitForSelectors, urlConfig.waitForSelectors);
}
@Override
public int hashCode() {
return Objects.hash(url, paths, setupPaths, cleanupPaths, maxDiff, cookies, alternatingCookies, envMapping, localStorage, sessionStorage, windowWidths, devices, maxScrollHeight, waitAfterPageLoad, waitAfterScroll, waitForNoAnimationAfterScroll, warmupBrowserCacheTime, waitForFontsTime, javaScript, httpCheck, hideImages, removeSelectors, waitForSelectors, waitForSelectorsTimeout, failIfSelectorsNotFound, ignoreAntiAliasing, maxAntiAliasColorDistance, strictColorComparison, maxColorDistance);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy