diff --git a/src/main/java/net/itarray/automotion/internal/ResponsiveUIChunkValidatorBase.java b/src/main/java/net/itarray/automotion/internal/ResponsiveUIChunkValidatorBase.java index 4ca5d15..1fa1daf 100644 --- a/src/main/java/net/itarray/automotion/internal/ResponsiveUIChunkValidatorBase.java +++ b/src/main/java/net/itarray/automotion/internal/ResponsiveUIChunkValidatorBase.java @@ -281,7 +281,7 @@ private void validateElementsAreNotOverlapped(List elements) { UIElement first = elements.get(firstIndex); for (int secondIndex = firstIndex+1; secondIndex < elements.size(); secondIndex++) { UIElement second = elements.get(secondIndex); - if (first.overlaps(second, context)) { + if (!first.notOverlaps(second, context)) { context.add("Elements are overlapped"); context.draw(first); break; diff --git a/src/main/java/net/itarray/automotion/internal/UIElement.java b/src/main/java/net/itarray/automotion/internal/UIElement.java index 0d5f21c..a60c3f3 100644 --- a/src/main/java/net/itarray/automotion/internal/UIElement.java +++ b/src/main/java/net/itarray/automotion/internal/UIElement.java @@ -172,6 +172,13 @@ public boolean overlaps(UIElement other, Context context) { Condition.lessThan(getBottom()).isSatisfiedOn(other.getTop(), context, DOWN); } + public boolean notOverlaps(UIElement other, Context context) { + return Condition.greaterOrEqualTo(other.getRight()).isSatisfiedOn(getLeft(), context, RIGHT) || + Condition.greaterOrEqualTo(getRight()).isSatisfiedOn(other.getLeft(), context, RIGHT) || + Condition.greaterOrEqualTo(other.getBottom()).isSatisfiedOn(getTop(), context, DOWN) || + Condition.greaterOrEqualTo(getBottom()).isSatisfiedOn(other.getTop(), context, DOWN); + } + private Scalar getOffset(Direction direction, UIElement page) { return direction.signedDistance(getEnd(direction), page.getEnd(direction)); } @@ -347,7 +354,7 @@ public void validateOverlappingWithElement(UIElement element, Context context) { } public void validateNotOverlappingWithElement(UIElement element, Context context) { - if (overlaps(element, context)) { + if (!notOverlaps(element, context)) { context.add(String.format("Element %s is overlapped with element %s but should not", getQuotedName(), element.getQuotedName())); diff --git a/src/main/java/util/validator/ResponsiveUIValidator.java b/src/main/java/util/validator/ResponsiveUIValidator.java index 60da8bd..79db8e0 100644 --- a/src/main/java/util/validator/ResponsiveUIValidator.java +++ b/src/main/java/util/validator/ResponsiveUIValidator.java @@ -32,6 +32,11 @@ protected ResponsiveUIValidator(net.itarray.automotion.validation.ResponsiveUIVa responsiveUIValidator.dontDrawMap(); } + public ResponsiveUIValidator withTolerance(int tolerance) { + responsiveUIValidator.withTolerance(tolerance); + return this; + } + public boolean isWithReport() { return responsiveUIValidator.isWithReport(); } diff --git a/src/test/java/rectangles/IntersectionTest.java b/src/test/java/rectangles/IntersectionTest.java index e0128b1..7b31c0a 100644 --- a/src/test/java/rectangles/IntersectionTest.java +++ b/src/test/java/rectangles/IntersectionTest.java @@ -59,7 +59,7 @@ public void shouldNotOverlap() { @Test public void areNotOverlapped() { - assertThat(areNotOverlappedWithEachOther(Arrays.asList(root, other))) + assertThat(doNotOverlap(Arrays.asList(root, other))) .withFailMessage(failMessage(intersectionExpectation())) .isEqualTo(!intersects); } diff --git a/src/test/java/rectangles/TestAssumptions.java b/src/test/java/rectangles/TestAssumptions.java index 6a09316..e71341e 100644 --- a/src/test/java/rectangles/TestAssumptions.java +++ b/src/test/java/rectangles/TestAssumptions.java @@ -10,13 +10,12 @@ import java.util.function.BiConsumer; import java.util.function.Consumer; -import static net.itarray.automotion.validation.properties.Expression.percentOrPixels; import static net.itarray.automotion.validation.properties.Condition.*; import static rectangles.DummyDriverFacade.createWebDriver; public class TestAssumptions { - public static boolean validate(WebElement root, Consumer assumption) { - ResponsiveUIValidator temporary = new ResponsiveUIValidator(createWebDriver()).init(); + public static boolean validate(WebElement root, Consumer assumption, int tolerance) { + ResponsiveUIValidator temporary = new ResponsiveUIValidator(createWebDriver()).withTolerance(tolerance).init(); UIValidator validator = temporary.findElement(root, "Bla"); @@ -24,8 +23,8 @@ public static boolean validate(WebElement root, Consumer assumption return validator.validate(); } - public static boolean validate(WebElement root, WebElement other, BiConsumer assumption) { - ResponsiveUIValidator temporary = new ResponsiveUIValidator(createWebDriver()).init(); + public static boolean validate(WebElement root, WebElement other, BiConsumer assumption, int tolerance) { + ResponsiveUIValidator temporary = new ResponsiveUIValidator(createWebDriver()).withTolerance(tolerance).init(); UIValidator validator = temporary.findElement(root, "Bla"); @@ -33,8 +32,8 @@ public static boolean validate(WebElement root, WebElement other, BiConsumer others, BiConsumer> assumption) { - ResponsiveUIValidator temporary = new ResponsiveUIValidator(createWebDriver()).init(); + public static boolean validate(WebElement root, List others, BiConsumer> assumption, int tolerance) { + ResponsiveUIValidator temporary = new ResponsiveUIValidator(createWebDriver()).withTolerance(tolerance).init(); UIValidator validator = temporary.findElement(root, "Bla"); @@ -42,8 +41,8 @@ public static boolean validate(WebElement root, List others, BiConsu return validator.validate(); } - public static boolean validate(List elements, Consumer assumption) { - ResponsiveUIValidator temporary = new ResponsiveUIValidator(createWebDriver()).init(); + public static boolean validate(List elements, Consumer assumption, int tolerance) { + ResponsiveUIValidator temporary = new ResponsiveUIValidator(createWebDriver()).withTolerance(tolerance).init(); ResponsiveUIChunkValidator validator = temporary.findElements(elements); @@ -52,242 +51,274 @@ public static boolean validate(List elements, Consumer uiValidator.minOffset(top, right, bottom, left)); + return validate(root, uiValidator -> uiValidator.minOffset(top, right, bottom, left), 0); } public static boolean hasLeftOffsetToPageGreaterOrEqualTo(WebElement root, int value) { - return validate(root, uiValidator -> uiValidator.hasLeftOffsetToPage(greaterOrEqualTo(value))); + return validate(root, uiValidator -> uiValidator.hasLeftOffsetToPage(greaterOrEqualTo(value)), 0); } public static boolean hasLeftOffsetToPageLessOrEqualTo(WebElement root, int value) { - return validate(root, uiValidator -> uiValidator.hasLeftOffsetToPage(lessOrEqualTo(value))); + return validate(root, uiValidator -> uiValidator.hasLeftOffsetToPage(lessOrEqualTo(value)), 0); } public static boolean hasRightOffsetToPageGreaterOrEqualTo(WebElement root, int value) { - return validate(root, uiValidator -> uiValidator.hasRightOffsetToPage(greaterOrEqualTo(value))); + return validate(root, uiValidator -> uiValidator.hasRightOffsetToPage(greaterOrEqualTo(value)), 0); } public static boolean hasRightOffsetToPageLessOrEqualTo(WebElement root, int value) { - return validate(root, uiValidator -> uiValidator.hasRightOffsetToPage(lessOrEqualTo(value))); + return validate(root, uiValidator -> uiValidator.hasRightOffsetToPage(lessOrEqualTo(value)), 0); } public static boolean hasTopOffsetToPageGreaterOrEqualTo(WebElement root, int value) { - return validate(root, uiValidator -> uiValidator.hasTopOffsetToPage(greaterOrEqualTo(value))); + return validate(root, uiValidator -> uiValidator.hasTopOffsetToPage(greaterOrEqualTo(value)), 0); } public static boolean hasTopOffsetToPageLessOrEqualTo(WebElement root, int value) { - return validate(root, uiValidator -> uiValidator.hasTopOffsetToPage(lessOrEqualTo(value))); + return validate(root, uiValidator -> uiValidator.hasTopOffsetToPage(lessOrEqualTo(value)), 0); } public static boolean hasBottomOffsetToPageGreaterOrEqualTo(WebElement root, int value) { - return validate(root, uiValidator -> uiValidator.hasBottomOffsetToPage(greaterOrEqualTo(value))); + return validate(root, uiValidator -> uiValidator.hasBottomOffsetToPage(greaterOrEqualTo(value)), 0); } public static boolean hasBottomOffsetToPageLessOrEqualTo(WebElement root, int value) { - return validate(root, uiValidator -> uiValidator.hasBottomOffsetToPage(lessOrEqualTo(value))); + return validate(root, uiValidator -> uiValidator.hasBottomOffsetToPage(lessOrEqualTo(value)), 0); } public static boolean maxOffset(WebElement root, int top, int right, int bottom, int left) { - return validate(root, uiValidator -> uiValidator.maxOffset(top, right, bottom, left)); + return validate(root, uiValidator -> uiValidator.maxOffset(top, right, bottom, left), 0); } public static boolean isCenteredOnPageHorizontally(WebElement root) { - return validate(root, UIValidator::isCenteredOnPageHorizontally); + return validate(root, UIValidator::isCenteredOnPageHorizontally, 0); } public static boolean areCenteredOnPageVertically(List elements) { - return validate(elements, ResponsiveUIChunkValidator::areCenteredOnPageVertically); + return validate(elements, ResponsiveUIChunkValidator::areCenteredOnPageVertically, 0); } public static boolean isCenteredOnPageVertically(WebElement root) { - return validate(root, UIValidator::isCenteredOnPageVertically); + return validate(root, UIValidator::isCenteredOnPageVertically, 0); } public static boolean areCenteredOnPageHorizontally(List elements) { - return validate(elements, ResponsiveUIChunkValidator::areCenteredOnPageHorizontally); + return validate(elements, ResponsiveUIChunkValidator::areCenteredOnPageHorizontally, 0); } public static boolean isLeftAlignedWith(WebElement root, WebElement other) { - return validate(root, uiValidator -> uiValidator.isLeftAlignedWith(other, "Blub")); + return validate(root, uiValidator -> uiValidator.isLeftAlignedWith(other, "Blub"), 0); } public static boolean isLeftAlignedWith(WebElement root, List elements) { - return validate(root, elements, UIValidator::isLeftAlignedWith); + return validate(root, elements, UIValidator::isLeftAlignedWith, 0); } public static boolean areLeftAligned(List elements) { - return validate(elements, ResponsiveUIChunkValidator::areLeftAligned); + return validate(elements, ResponsiveUIChunkValidator::areLeftAligned, 0); } public static boolean isRightAlignedWith(WebElement root, WebElement other) { - return validate(root, uiValidator -> uiValidator.isRightAlignedWith(other, "Blub")); + return validate(root, uiValidator -> uiValidator.isRightAlignedWith(other, "Blub"), 0); } public static boolean isRightAlignedWith(WebElement root, List elements) { - return validate(root, elements, UIValidator::isRightAlignedWith); + return validate(root, elements, UIValidator::isRightAlignedWith, 0); } public static boolean areRightAligned(List elements) { - return validate(elements, ResponsiveUIChunkValidator::areRightAligned); + return validate(elements, ResponsiveUIChunkValidator::areRightAligned, 0); } public static boolean isTopAlignedWith(WebElement root, WebElement other) { - return validate(root, uiValidator -> uiValidator.isTopAlignedWith(other, "Blub")); + return validate(root, uiValidator -> uiValidator.isTopAlignedWith(other, "Blub"), 0); } public static boolean isTopAlignedWith(WebElement root, List elements) { - return validate(root, elements, UIValidator::isTopAlignedWith); + return validate(root, elements, UIValidator::isTopAlignedWith, 0); } public static boolean areTopAligned(List elements) { - return validate(elements, ResponsiveUIChunkValidator::areTopAligned); + return validate(elements, ResponsiveUIChunkValidator::areTopAligned, 0); } public static boolean isBottomAlignedWith(WebElement root, WebElement other) { - return validate(root, other, (uiValidator, webElement) -> uiValidator.isBottomAlignedWith(other, "Blub")); + return validate(root, other, (uiValidator, webElement) -> uiValidator.isBottomAlignedWith(other, "Blub"), 0); } public static boolean isBottomAlignedWith(WebElement root, List elements) { - return validate(root, elements, UIValidator::isBottomAlignedWith); + return validate(root, elements, UIValidator::isBottomAlignedWith, 0); } public static boolean areBottomAligned(List elements) { - return validate(elements, ResponsiveUIChunkValidator::areBottomAligned); + return validate(elements, ResponsiveUIChunkValidator::areBottomAligned, 0); } public static boolean isAbove(WebElement root, WebElement other, int minMargin, int maxMargin) { - return validate(root, other, (uiValidator, webElement) -> uiValidator.isAbove(other, between(minMargin).and(maxMargin))); + return validate(root, other, (uiValidator, webElement) -> uiValidator.isAbove(other, between(minMargin).and(maxMargin)), 0); } public static boolean isAbove(WebElement other, WebElement root) { - return validate(root, other, UIValidator::isAbove); + return validate(root, other, UIValidator::isAbove, 0); } public static boolean isBelow(WebElement root, WebElement other, int minMargin, int maxMargin) { - return validate(root, other, (uiValidator, webElement) -> uiValidator.isBelow(other, between(minMargin).and(maxMargin))); + return validate(root, other, (uiValidator, webElement) -> uiValidator.isBelow(other, between(minMargin).and(maxMargin)), 0); } public static boolean isBelow(WebElement root, WebElement other) { - return validate(root, other, UIValidator::isBelow); + return validate(root, other, UIValidator::isBelow, 0); } public static boolean isRightOf(WebElement root, WebElement other, int minMargin, int maxMargin) { - return validate(root, uiValidator -> uiValidator.isRightOf(other, between(minMargin).and(maxMargin))); + return validate(root, uiValidator -> uiValidator.isRightOf(other, between(minMargin).and(maxMargin)), 0); } public static boolean isRightOf(WebElement root, WebElement other) { - return validate(root, other, UIValidator::isRightOf); + return validate(root, other, UIValidator::isRightOf, 0); } public static boolean isLeftOf(WebElement root, WebElement other, int minMargin, int maxMargin) { - return validate(root, uiValidator -> uiValidator.isLeftOf(other, between(minMargin).and(maxMargin))); + return validate(root, uiValidator -> uiValidator.isLeftOf(other, between(minMargin).and(maxMargin)), 0); } public static boolean isLeftOf(WebElement root, WebElement other) { - return validate(root, other, UIValidator::isLeftOf); + return validate(root, other, UIValidator::isLeftOf, 0); } public static boolean isOverlapping(WebElement root, WebElement other) { - return validate(root, uiValidator -> uiValidator.isOverlapping(other, "Blub")); + return validate(root, uiValidator -> uiValidator.isOverlapping(other, "Blub"), 0); } public static boolean isNotOverlapping(WebElement root, WebElement other) { - return validate(root, uiValidator -> uiValidator.isNotOverlapping(other, "Blub")); + return isNotOverlapping(root, other, 0); } - public static boolean areNotOverlappedWithEachOther(List elements) { - return validate(elements, ResponsiveUIChunkValidator::doNotOverlap); + public static boolean isNotOverlapping(WebElement root, WebElement other, int tolerance) { + return validate(root, uiValidator -> uiValidator.isNotOverlapping(other, "Blub"), tolerance); + } + + public static boolean isNotOverlapping(WebElement root, List others, int tolerance) { + return validate(root, others, UIValidator::isNotOverlapping, tolerance); + } + + public static boolean doNotOverlap(List elements) { + return doNotOverlap(elements, 0); + } + + public static boolean doNotOverlap(List elements, int tolerance) { + return validate(elements, ResponsiveUIChunkValidator::doNotOverlap, tolerance); } public static boolean isInsideOf(WebElement root, WebElement other) { - return validate(root, uiValidator -> uiValidator.isInsideOf(other, "Blub")); + return validate(root, uiValidator -> uiValidator.isInsideOf(other, "Blub"), 0); } public static boolean isInsideOf(WebElement root, WebElement other, Padding padding) { - return validate(root, uiValidator -> uiValidator.isInsideOf(other, "Blub", padding)); + return validate(root, uiValidator -> uiValidator.isInsideOf(other, "Blub", padding), 0); } public static boolean areInsideOf(List elements, WebElement container) { - return validate(elements, validator -> validator.areInsideOf(container, "Bla")); + return validate(elements, validator -> validator.areInsideOf(container, "Bla"), 0); } public static boolean hasEqualWidthAs(WebElement root, WebElement other) { - return validate(root, uiValidator -> uiValidator.hasEqualWidthAs(other, "Blub")); + return validate(root, uiValidator -> uiValidator.hasEqualWidthAs(other, "Blub"), 0); } public static boolean hasEqualWidthAs(WebElement root, List others) { - return validate(root, uiValidator -> uiValidator.hasEqualWidthAs(others)); + return validate(root, uiValidator -> uiValidator.hasEqualWidthAs(others), 0); } public static boolean haveEqualWidth(List elements) { - return validate(elements, ResponsiveUIChunkValidator::haveEqualWidth); + return validate(elements, ResponsiveUIChunkValidator::haveEqualWidth, 0); } public static boolean haveDifferentWidths(List elements) { - return validate(elements, ResponsiveUIChunkValidator::haveDifferentWidths); + return haveDifferentWidths(elements, 0); + } + + public static boolean haveDifferentWidths(List elements, int tolerance) { + return validate(elements, ResponsiveUIChunkValidator::haveDifferentWidths, tolerance); } public static boolean hasEqualHeightAs(WebElement root, WebElement other) { - return validate(root, uiValidator -> uiValidator.hasEqualHeightAs(other, "Blub")); + return validate(root, uiValidator -> uiValidator.hasEqualHeightAs(other, "Blub"), 0); } public static boolean hasEqualHeightAs(WebElement root, List others) { - return validate(root, others, UIValidator::hasEqualHeightAs); + return validate(root, others, UIValidator::hasEqualHeightAs, 0); } public static boolean haveEqualHeight(List elements) { - return validate(elements, ResponsiveUIChunkValidator::haveEqualHeight); + return validate(elements, ResponsiveUIChunkValidator::haveEqualHeight, 0); } public static boolean haveDifferentHeights(List elements) { - return validate(elements, ResponsiveUIChunkValidator::haveDifferentHeights); + return haveDifferentHeights(elements, 0); + } + + public static boolean haveDifferentHeights(List elements, int tolerance) { + return validate(elements, ResponsiveUIChunkValidator::haveDifferentHeights, tolerance); } public static boolean hasEqualSizeAs(WebElement root, WebElement other) { - return validate(root, uiValidator -> uiValidator.hasEqualSizeAs(other, "Blub")); + return validate(root, uiValidator -> uiValidator.hasEqualSizeAs(other, "Blub"), 0); } public static boolean hasEqualSizeAs(WebElement root, List others) { - return validate(root, uiValidator -> uiValidator.hasEqualSizeAs(others)); + return validate(root, uiValidator -> uiValidator.hasEqualSizeAs(others), 0); } public static boolean haveEqualSize(List elements) { - return validate(elements, ResponsiveUIChunkValidator::haveEqualSize); + return validate(elements, ResponsiveUIChunkValidator::haveEqualSize, 0); } public static boolean hasDifferentSizeAs(WebElement root, WebElement other) { - return validate(root, uiValidator -> uiValidator.hasDifferentSizeAs(other, "Blub")); + return hasDifferentSizeAs(root, other, 0); + } + + public static boolean hasDifferentSizeAs(WebElement root, WebElement other, int tolerance) { + return validate(root, uiValidator -> uiValidator.hasDifferentSizeAs(other, "Blub"), tolerance); } public static boolean hasDifferentSizeAs(WebElement root, List others) { - return validate(root, uiValidator -> uiValidator.hasDifferentSizeAs(others)); + return hasDifferentSizeAs(root, others, 0); + } + + public static boolean hasDifferentSizeAs(WebElement root, List others, int tolerance) { + return validate(root, uiValidator -> uiValidator.hasDifferentSizeAs(others), tolerance); } public static boolean haveDifferentSizes(List elements) { - return validate(elements, ResponsiveUIChunkValidator::haveDifferentSizes); + return haveDifferentSizes(elements, 0); + } + + public static boolean haveDifferentSizes(List elements, int tolerance) { + return validate(elements, ResponsiveUIChunkValidator::haveDifferentSizes, tolerance); } public static boolean hasHeightBetween(WebElement root, int min, int max) { - return validate(root, uiValidator -> uiValidator.hasHeight(between(min).and(max))); + return validate(root, uiValidator -> uiValidator.hasHeight(between(min).and(max)), 0); } public static boolean hasWidthBetween(WebElement root, int min, int max) { - return validate(root, uiValidator -> uiValidator.hasWidth(between(min).and(max))); + return validate(root, uiValidator -> uiValidator.hasWidth(between(min).and(max)), 0); } public static boolean hasWidthGreaterOrEqualTo(WebElement root, int value) { - return validate(root, uiValidator -> uiValidator.hasWidth(greaterOrEqualTo(value))); + return validate(root, uiValidator -> uiValidator.hasWidth(greaterOrEqualTo(value)), 0); } public static boolean hasWidthLessOrEqualTo(WebElement root, int value) { - return validate(root, uiValidator -> uiValidator.hasWidth(lessOrEqualTo(value))); + return validate(root, uiValidator -> uiValidator.hasWidth(lessOrEqualTo(value)), 0); } public static boolean hasHeightGreaterOrEqualTo(WebElement root, int value) { - return validate(root, uiValidator -> uiValidator.hasHeight(greaterOrEqualTo(value))); + return validate(root, uiValidator -> uiValidator.hasHeight(greaterOrEqualTo(value)), 0); } public static boolean hasHeightLessOrEqualTo(WebElement root, int value) { - return validate(root, uiValidator -> uiValidator.hasHeight(lessOrEqualTo(value))); + return validate(root, uiValidator -> uiValidator.hasHeight(lessOrEqualTo(value)), 0); } } diff --git a/src/test/java/rectangles/ToleranceOnNegativeAssumptionsTest.java b/src/test/java/rectangles/ToleranceOnNegativeAssumptionsTest.java new file mode 100644 index 0000000..f124715 --- /dev/null +++ b/src/test/java/rectangles/ToleranceOnNegativeAssumptionsTest.java @@ -0,0 +1,94 @@ +package rectangles; + +import org.assertj.core.api.AbstractBooleanAssert; +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.WebElement; + +import static java.util.Arrays.asList; +import static org.assertj.core.api.Assertions.assertThat; +import static rectangles.TestAssumptions.*; + +public class ToleranceOnNegativeAssumptionsTest { + + private final int x = 100; + private final int y = 1000; + private final int width = 200; + private final int height = 300; + private WebElement root; + + @Before + public void setUp() { + root = createElement(x, y); + } + + public WebElement createElement(int x, int y) { + return DummyWebElement.createElement(x, y, x + width, y + height); + } + + @Test + public void isNotOverlappingWithTolerance() { + assertThatNotOverlappingWithTolerance(x+width, y).isTrue(); + assertThatNotOverlappingWithTolerance(x+width-1, y).isTrue(); + assertThatNotOverlappingWithTolerance(x+width-2, y).isFalse(); + assertThatNotOverlappingWithTolerance(x-width, y).isTrue(); + assertThatNotOverlappingWithTolerance(x-width+1, y).isTrue(); + assertThatNotOverlappingWithTolerance(x-width+2, y).isFalse(); + assertThatNotOverlappingWithTolerance(x, y+height).isTrue(); + assertThatNotOverlappingWithTolerance(x, y+height-1).isTrue(); + assertThatNotOverlappingWithTolerance(x, y+height-2).isFalse(); + assertThatNotOverlappingWithTolerance(x, y-height).isTrue(); + assertThatNotOverlappingWithTolerance(x, y-height+1).isTrue(); + assertThatNotOverlappingWithTolerance(x, y-height+2).isFalse(); + } + + @Test + public void hasDifferentSizeAsWithTolerance() { + assertThatHasDifferentSizeWithTolerance(-2, 0).isTrue(); + assertThatHasDifferentSizeWithTolerance(-1, 0).isFalse(); + assertThatHasDifferentSizeWithTolerance( 0, 0).isFalse(); + assertThatHasDifferentSizeWithTolerance(+1, 0).isFalse(); + assertThatHasDifferentSizeWithTolerance(+2, 0).isTrue(); + assertThatHasDifferentWidthWithTolerance(-2).isTrue(); + assertThatHasDifferentWidthWithTolerance(-1).isFalse(); + assertThatHasDifferentWidthWithTolerance( 0).isFalse(); + assertThatHasDifferentWidthWithTolerance(+1).isFalse(); + assertThatHasDifferentWidthWithTolerance(+2).isTrue(); + assertThatHasDifferentSizeWithTolerance(0, -2).isTrue(); + assertThatHasDifferentSizeWithTolerance(0, -1).isFalse(); + assertThatHasDifferentSizeWithTolerance(0, 0).isFalse(); + assertThatHasDifferentSizeWithTolerance(0, +1).isFalse(); + assertThatHasDifferentSizeWithTolerance(0, +2).isTrue(); + assertThatHasDifferentHeightWithTolerance(-2).isTrue(); + assertThatHasDifferentHeightWithTolerance(-1).isFalse(); + assertThatHasDifferentHeightWithTolerance( 0).isFalse(); + assertThatHasDifferentHeightWithTolerance(+1).isFalse(); + assertThatHasDifferentHeightWithTolerance(+2).isTrue(); + } + + public AbstractBooleanAssert assertThatHasDifferentSizeWithTolerance(int deltaWidth, int deltaHeight) { + WebElement element = DummyWebElement.createElement(x, y, x + width + deltaWidth, y + height + deltaHeight); + return assertThat(hasDifferentSizeAs(root, element, 1) && + hasDifferentSizeAs(root, asList(element), 1) && + haveDifferentSizes(asList(root, element), 1)); + } + + public AbstractBooleanAssert assertThatHasDifferentHeightWithTolerance(int deltaHeight) { + WebElement element = DummyWebElement.createElement(x, y, x + width, y + height + deltaHeight); + return assertThat(haveDifferentHeights(asList(root, element), 1)); + } + + public AbstractBooleanAssert assertThatHasDifferentWidthWithTolerance(int deltaWidth) { + WebElement element = DummyWebElement.createElement(x, y, x + width + deltaWidth, y + height); + return assertThat(haveDifferentWidths(asList(root, element), 1)); + } + + private AbstractBooleanAssert assertThatNotOverlappingWithTolerance(int x, int y) { + WebElement element = createElement(x, y); + return assertThat(isNotOverlapping(root, element, 1) && + doNotOverlap(asList(root, element), 1) && + isNotOverlapping(root, asList(element), 1)); + } + + +}