Skip to content

Commit

Permalink
Enhance
Browse files Browse the repository at this point in the history
  • Loading branch information
ebekebe committed May 8, 2024
1 parent 445b208 commit 513c5dc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
19 changes: 15 additions & 4 deletions visual-java/src/main/java/com/saucelabs/visual/CheckOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.saucelabs.visual.model.IgnoreRegion;
import com.saucelabs.visual.model.VisualRegion;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import org.openqa.selenium.WebElement;

Expand Down Expand Up @@ -107,21 +108,31 @@ public Builder withFullPageConfig(FullPageScreenshotConfig fullPageScreenshotCon
return this;
}

public Builder disable(DiffingFlag flags) {
public Builder disable(EnumSet<DiffingFlag> flags) {
if (this.diffingOptions == null) {
this.diffingOptions = new DiffingOptionsIn();
DiffingFlag.setAll(this.diffingOptions, true);
}
flags.apply(this.diffingOptions, false);
for (DiffingFlag f : flags) f.apply(this.diffingOptions, false);
return this;
}

public Builder enable(DiffingFlag flags) {
public Builder enable(EnumSet<DiffingFlag> flags) {
if (this.diffingOptions == null) {
this.diffingOptions = new DiffingOptionsIn();
DiffingFlag.setAll(this.diffingOptions, false);
}
flags.apply(this.diffingOptions, true);
for (DiffingFlag f : flags) f.apply(this.diffingOptions, true);
return this;
}

public Builder enable(EnumSet<DiffingFlag> flags, WebElement element) {
this.regions.add(VisualRegion.ignoreChangesFor(element).except(flags));
return this;
}

public Builder disable(EnumSet<DiffingFlag> flags, WebElement element) {
this.regions.add(VisualRegion.detectChangesFor(element).except(flags));
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.saucelabs.visual.graphql.type.DiffingOptionsIn;
import com.saucelabs.visual.graphql.type.RegionIn;
import java.util.EnumSet;
import org.openqa.selenium.Rectangle;
import org.openqa.selenium.WebElement;

Expand All @@ -27,6 +28,11 @@ public VisualRegion(IgnoreRegion ir) {
this.y = ir.getY();
}

public VisualRegion(WebElement element, DiffingOptionsIn diffingOptions) {
this.options = diffingOptions;
this.element = element;
}

public static VisualRegion ignoreChangesFor(WebElement element) {
VisualRegion r = new VisualRegion();
r.options = setAllFlags(new DiffingOptionsIn(), false);
Expand Down Expand Up @@ -133,8 +139,10 @@ public void setY(int y) {
this.y = y;
}

public VisualRegion except(DiffingFlag flags) {
flags.apply(this.options, this.isIgnoreRegion);
public VisualRegion except(EnumSet<DiffingFlag> flags) {
for (DiffingFlag f : flags) {
f.apply(this.options, this.isIgnoreRegion);
}
return this;
}

Expand Down

0 comments on commit 513c5dc

Please sign in to comment.