Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IRIS-927-align-java-fps-options #38

Merged
merged 5 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public CheckOptions(
private DiffingOptionsIn diffingOptions;
private Boolean captureDom;
private String clipSelector;

private FullPageScreenshotConfig fullPageScreenshotConfig;

public static class Builder {
Expand Down
32 changes: 31 additions & 1 deletion visual-java/src/main/java/com/saucelabs/visual/VisualApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.saucelabs.visual.exception.VisualApiException;
import com.saucelabs.visual.graphql.*;
import com.saucelabs.visual.graphql.type.*;
import com.saucelabs.visual.model.FullPageScreenshotConfig;
import com.saucelabs.visual.model.IgnoreRegion;
import com.saucelabs.visual.model.VisualRegion;
import com.saucelabs.visual.utils.ConsoleColors;
Expand Down Expand Up @@ -34,6 +35,7 @@ public static class Builder {
private String defaultBranchName;
private String buildName;
private Boolean captureDom;
private FullPageScreenshotConfig fullPageScreenshotConfig;

public Builder(RemoteWebDriver driver, String username, String accessKey) {
this(driver, username, accessKey, DataCenter.US_WEST_1.endpoint);
Expand Down Expand Up @@ -75,6 +77,11 @@ public Builder withCaptureDom(Boolean captureDom) {
return this;
}

public Builder withFullPageScreenshot(FullPageScreenshotConfig fullPageScreenshotConfig) {
this.fullPageScreenshotConfig = fullPageScreenshotConfig;
return this;
}

public VisualApi build() {
VisualApi api =
new VisualApi(
Expand All @@ -87,6 +94,9 @@ public VisualApi build() {
if (this.captureDom != null) {
api.setCaptureDom(this.captureDom);
}
if (this.fullPageScreenshotConfig != null) {
api.enableFullPageScreenshots(this.fullPageScreenshotConfig);
}
return api;
}
}
Expand All @@ -98,6 +108,7 @@ public VisualApi build() {
private final String sessionId;
private final List<String> uploadedDiffIds = new ArrayList<>();
private Boolean captureDom;
private FullPageScreenshotConfig fullPageScreenshotConfig;
private String sessionMetadataBlob;

/**
Expand Down Expand Up @@ -188,6 +199,20 @@ public void setCaptureDom(Boolean captureDom) {
this.captureDom = captureDom;
}

/** Enables full page screenshots */
public void enableFullPageScreenshots() {
this.fullPageScreenshotConfig = new FullPageScreenshotConfig.Builder().build();
}

/**
* Enables full page screenshots
*
* @param fullPageScreenshotConfig config for full page screenshots
*/
public void enableFullPageScreenshots(FullPageScreenshotConfig fullPageScreenshotConfig) {
this.fullPageScreenshotConfig = fullPageScreenshotConfig;
}

private WebdriverSessionInfoQuery.Result webdriverSessionInfo() {
WebdriverSessionInfoQuery query =
new WebdriverSessionInfoQuery(
Expand Down Expand Up @@ -358,7 +383,12 @@ public void sauceVisualCheck(String snapshotName, CheckOptions options) {
input.setClipSelector(clipSelector);
}

input.setFullPageConfig(options.getFullPageScreenshotConfig());
FullPageScreenshotConfig fullPageScreenshotConfig =
Optional.ofNullable(options.getFullPageScreenshotConfig())
.orElse(this.fullPageScreenshotConfig);
if (fullPageScreenshotConfig != null) {
input.setFullPageConfig(fullPageScreenshotConfig);
}

CreateSnapshotFromWebDriverMutation mutation = new CreateSnapshotFromWebDriverMutation(input);
CreateSnapshotFromWebDriverMutation.Data check =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,68 @@
public class FullPageScreenshotConfig {

private int delayAfterScrollMs;
private Boolean disableCSSAnimation;
private List<String> hideAfterFirstScroll;
private Boolean hideScrollBars;
private int scrollLimit;

public FullPageScreenshotConfig(int delayAfterScrollMs, List<String> hideAfterFirstScroll) {
public FullPageScreenshotConfig(
int delayAfterScrollMs,
Boolean disableCSSAnimation,
List<String> hideAfterFirstScroll,
Boolean hideScrollBars,
int scrollLimit) {
this.delayAfterScrollMs = delayAfterScrollMs;
this.disableCSSAnimation = disableCSSAnimation;
this.hideAfterFirstScroll = hideAfterFirstScroll;
this.hideScrollBars = hideScrollBars;
this.scrollLimit = scrollLimit;
}

public static class Builder {
private int delayAfterScrollMs;
private Boolean disableCSSAnimation;
private List<String> hideAfterFirstScroll;
private Boolean hideScrollBars;
private int scrollLimit;

public Builder withDelayAfterScrollMs(int delayAfterScrollMs) {
this.delayAfterScrollMs = delayAfterScrollMs;
return this;
}

public Builder withDisableCSSAnimation(Boolean disableCSSAnimation) {
this.disableCSSAnimation = disableCSSAnimation;
return this;
}

public Builder withHideAfterFirstScroll(String... hideAfterFirstScroll) {
this.hideAfterFirstScroll = Arrays.asList(hideAfterFirstScroll);
return this;
}

public Builder withHideScrollBars(Boolean hideScrollBars) {
this.hideScrollBars = hideScrollBars;
return this;
}

public Builder withScrollLimit(int scrollLimit) {
if (scrollLimit > 0 && scrollLimit <= 10) {
this.scrollLimit = scrollLimit;
} else {
FriggaHel marked this conversation as resolved.
Show resolved Hide resolved
this.scrollLimit = 10;
}

return this;
}

public FullPageScreenshotConfig build() {
return new FullPageScreenshotConfig(delayAfterScrollMs, hideAfterFirstScroll);
return new FullPageScreenshotConfig(
delayAfterScrollMs,
disableCSSAnimation,
hideAfterFirstScroll,
hideScrollBars,
scrollLimit);
}
}

Expand All @@ -40,11 +79,35 @@ public void setDelayAfterScrollMs(int delayAfterScrollMs) {
this.delayAfterScrollMs = delayAfterScrollMs;
}

public Boolean getDisableCSSAnimation() {
return disableCSSAnimation;
}

public void setDisableCSSAnimation(Boolean disableCSSAnimation) {
this.disableCSSAnimation = disableCSSAnimation;
}

public List<String> getHideAfterFirstScroll() {
return hideAfterFirstScroll;
}

public void setHideAfterFirstScroll(String... hideAfterFirstScroll) {
this.hideAfterFirstScroll = Arrays.asList(hideAfterFirstScroll);
}

public Boolean getHideScrollBars() {
return hideScrollBars;
}

public void setHideScrollBars(Boolean hideScrollBars) {
this.hideScrollBars = hideScrollBars;
}

public int getScrollLimit() {
return scrollLimit;
}

public void setScrollLimit(int scrollLimit) {
this.scrollLimit = scrollLimit;
}
}
2 changes: 2 additions & 0 deletions visual-java/src/test/java/com/saucelabs/visual/SmokeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ void testFullPageOptions() {
CheckOptions options = new CheckOptions();
FullPageScreenshotConfig config =
new FullPageScreenshotConfig.Builder()
.withHideScrollBars(false)
.withScrollLimit(2)
.withDelayAfterScrollMs(200)
.withHideAfterFirstScroll("#searchform")
.build();
Expand Down
Loading