|
6 | 6 | import com.saucelabs.visual.exception.VisualApiException;
|
7 | 7 | import com.saucelabs.visual.graphql.*;
|
8 | 8 | import com.saucelabs.visual.graphql.type.*;
|
| 9 | +import com.saucelabs.visual.model.*; |
9 | 10 | import com.saucelabs.visual.model.DiffingMethodSensitivity;
|
10 |
| -import com.saucelabs.visual.model.DiffingMethodTolerance; |
11 |
| -import com.saucelabs.visual.model.FullPageScreenshotConfig; |
12 |
| -import com.saucelabs.visual.model.IgnoreRegion; |
13 |
| -import com.saucelabs.visual.model.VisualRegion; |
14 | 11 | import com.saucelabs.visual.utils.CapabilityUtils;
|
15 | 12 | import com.saucelabs.visual.utils.ConsoleColors;
|
16 | 13 | import com.saucelabs.visual.utils.EnvironmentVariables;
|
|
24 | 21 | import java.util.regex.Pattern;
|
25 | 22 | import java.util.stream.Collectors;
|
26 | 23 | import org.apache.http.client.config.RequestConfig;
|
27 |
| -import org.openqa.selenium.By; |
28 |
| -import org.openqa.selenium.Capabilities; |
29 |
| -import org.openqa.selenium.OutputType; |
30 |
| -import org.openqa.selenium.WebElement; |
| 24 | +import org.openqa.selenium.*; |
31 | 25 | import org.openqa.selenium.remote.*;
|
32 | 26 | import org.slf4j.Logger;
|
33 | 27 | import org.slf4j.LoggerFactory;
|
@@ -622,6 +616,27 @@ private void sauceVisualCheckLocal(String snapshotName, CheckOptions options) {
|
622 | 616 | // upload image
|
623 | 617 | this.client.upload(uploadResult.getImageUploadUrl(), screenshot, "image/png");
|
624 | 618 |
|
| 619 | + // add ignore regions |
| 620 | + WindowScroll scroll = getWindowScroll(); |
| 621 | + List<RegionIn> ignoreRegions = extractIgnoreList(options); |
| 622 | + |
| 623 | + for (WebElement element : options.getIgnoreElements()) { |
| 624 | + RegionIn ignoreRegion = VisualRegion.ignoreChangesFor(element).toRegionIn(); |
| 625 | + ignoreRegions.add(ignoreRegion); |
| 626 | + } |
| 627 | + |
| 628 | + for (IgnoreSelectorIn selector : options.getIgnoreSelectors()) { |
| 629 | + VisualRegion region = getIgnoreRegionFromSelector(selector); |
| 630 | + if (region != null) { |
| 631 | + ignoreRegions.add(region.toRegionIn()); |
| 632 | + } |
| 633 | + } |
| 634 | + |
| 635 | + for (RegionIn region : ignoreRegions) { |
| 636 | + region.setX(region.getX() - scroll.getX()); |
| 637 | + region.setY(region.getY() - scroll.getY()); |
| 638 | + } |
| 639 | + |
625 | 640 | // upload dom if present / enabled
|
626 | 641 | Boolean shouldCaptureDom = Optional.ofNullable(options.getCaptureDom()).orElse(this.captureDom);
|
627 | 642 | if (shouldCaptureDom != null && shouldCaptureDom) {
|
@@ -657,7 +672,7 @@ private void sauceVisualCheckLocal(String snapshotName, CheckOptions options) {
|
657 | 672 | .withSuiteName(getOrInferSuiteName(options))
|
658 | 673 | .withDiffingMethod(toDiffingMethod(options))
|
659 | 674 | .withDiffingOptions(options.getDiffingOptions())
|
660 |
| - .withIgnoreRegions(extractIgnoreList(options)) |
| 675 | + .withIgnoreRegions(ignoreRegions) |
661 | 676 | .withDiffingMethodSensitivity(
|
662 | 677 | Optional.ofNullable(getDiffingMethodSensitivity(options))
|
663 | 678 | .map(DiffingMethodSensitivity::asGraphQLType)
|
@@ -714,6 +729,38 @@ private DiffingMethodTolerance getDiffingMethodTolerance(CheckOptions checkOptio
|
714 | 729 | return sensitivity != null ? sensitivity : this.diffingMethodTolerance;
|
715 | 730 | }
|
716 | 731 |
|
| 732 | + private WindowScroll getWindowScroll() { |
| 733 | + Object result = driver.executeScript("return [window.scrollX, window.scrollY]"); |
| 734 | + if (!(result instanceof List<?>)) { |
| 735 | + return new WindowScroll(0, 0); |
| 736 | + } |
| 737 | + |
| 738 | + List<?> list = (List<?>) result; |
| 739 | + Object rawScrollX = list.get(0); |
| 740 | + Object rawScrollY = list.get(1); |
| 741 | + |
| 742 | + int scrollX = rawScrollX instanceof Long ? ((Long) rawScrollX).intValue() : 0; |
| 743 | + int scrollY = rawScrollY instanceof Long ? ((Long) rawScrollY).intValue() : 0; |
| 744 | + |
| 745 | + return new WindowScroll(scrollX, scrollY); |
| 746 | + } |
| 747 | + |
| 748 | + private VisualRegion getIgnoreRegionFromSelector(IgnoreSelectorIn ignoreSelector) { |
| 749 | + SelectorIn selector = ignoreSelector.getSelector(); |
| 750 | + By bySelector; |
| 751 | + |
| 752 | + switch (selector.getType()) { |
| 753 | + case XPATH: |
| 754 | + bySelector = By.xpath(selector.getValue()); |
| 755 | + break; |
| 756 | + default: |
| 757 | + return null; |
| 758 | + } |
| 759 | + |
| 760 | + WebElement element = driver.findElement(bySelector); |
| 761 | + return new VisualRegion(element, ignoreSelector.getDiffingOptions()); |
| 762 | + } |
| 763 | + |
717 | 764 | private static DiffingMethod toDiffingMethod(CheckOptions options) {
|
718 | 765 | if (options == null || options.getDiffingMethod() == null) {
|
719 | 766 | return DiffingMethod.BALANCED;
|
|
0 commit comments