Skip to content

Commit c905aeb

Browse files
committed
tolerance for contains validations
1 parent 7512e0c commit c905aeb

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

src/main/java/net/itarray/automotion/internal/ResponsiveUIChunkValidatorBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ private void validateCenteredOnPageHorizontally(List<UIElement> elements) {
475475

476476
private void validateInsideOfContainer(UIElement containerElement, List<UIElement> elements) {
477477
for (UIElement element : elements) {
478-
element.validateInsideOfContainer(containerElement, errors);
478+
element.validateInsideOfContainer(containerElement, getContext(), errors);
479479
}
480480
}
481481

src/main/java/net/itarray/automotion/internal/UIElement.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public boolean hasSameHeightAs(UIElement other, Context context) {
146146
}
147147

148148
public boolean hasSameSizeAs(UIElement other, Context context) {
149-
return hasEqualExtendAs(other, Rectangle.ORIGIN_CORNER, context);
149+
return hasEqualExtendAs(other, ORIGIN_CORNER, context);
150150
}
151151

152152
public Scalar getLeft() {
@@ -221,8 +221,12 @@ private static String getShortenedText(String text) {
221221
return text.substring(0, maxLength-postfix.length()) + postfix;
222222
}
223223

224-
public boolean contains(UIElement other) {
225-
return rectangle.contains(other.rectangle);
224+
public boolean contains(UIElement other, Context context) {
225+
return
226+
Condition.lessOrEqualTo(other.getLeft()).isSatisfiedOn(getLeft(), context, RIGHT) &&
227+
Condition.lessOrEqualTo(getRight()).isSatisfiedOn(other.getRight(), context, RIGHT) &&
228+
Condition.lessOrEqualTo(other.getTop()).isSatisfiedOn(getTop(), context, DOWN) &&
229+
Condition.lessOrEqualTo(getBottom()).isSatisfiedOn(other.getBottom(), context, DOWN);
226230
}
227231

228232
public void validateLeftAlignedWith(UIElement element, Context context, Errors errors) {
@@ -454,16 +458,16 @@ public void validateHasCssValue(String cssProperty, String[] args, Errors errors
454458
}
455459
}
456460

457-
public void validateInsideOfContainer(UIElement containerElement, Errors errors) {
458-
if (!containerElement.contains(this)) {
461+
public void validateInsideOfContainer(UIElement containerElement, Context context, Errors errors) {
462+
if (!containerElement.contains(this, context)) {
459463
errors.add(String.format("Element '%s' is not inside of '%s'",
460464
getName(),
461465
containerElement.getName()));
462466
errors.draw(containerElement);
463467
}
464468
}
465469

466-
public void validateInsideOfContainer(UIElement element, Errors errors, Scalar top, Scalar left, Scalar right, Scalar bottom) {
470+
public void validateInsideOfContainer(UIElement element, Errors errors, Context context, Scalar top, Scalar left, Scalar right, Scalar bottom) {
467471
Vector originPadding = new Vector(left, top);
468472
Vector cornerPadding = new Vector(right, bottom);
469473

@@ -475,7 +479,7 @@ public void validateInsideOfContainer(UIElement element, Errors errors, Scalar t
475479
Vector originOffset = getOrigin().minus(element.getOrigin());
476480
Vector cornerOffset = getCorner().minus(element.getCorner());
477481

478-
if (!element.contains(paddedRoot)) {
482+
if (!element.contains(paddedRoot, context)) {
479483
errors.add(String.format("Padding of element %s is incorrect. Expected padding: top[%s], right[%s], bottom[%s], left[%s]. Actual padding: top[%s], right[%s], bottom[%s], left[%s]",
480484
getQuotedName(),
481485
originPadding.getY(),

src/main/java/net/itarray/automotion/internal/UIValidatorBase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ public UIValidatorBase isCenteredOnPageVertically() {
555555
*/
556556
@Override
557557
public UIValidatorBase isInsideOf(WebElement containerElement, String readableContainerName) {
558-
rootElement.validateInsideOfContainer(asElement(containerElement, readableContainerName), errors);
558+
rootElement.validateInsideOfContainer(asElement(containerElement, readableContainerName), getContext(), errors);
559559
return this;
560560
}
561561

@@ -566,7 +566,7 @@ public UIValidatorBase isInsideOf(WebElement containerElement, String readableCo
566566
Scalar right = percentOrPixels(padding.getRight()).evaluateIn(getContext(), Direction.RIGHT);
567567
Scalar bottom = percentOrPixels(padding.getBottom()).evaluateIn(getContext(), Direction.DOWN);
568568

569-
rootElement.validateInsideOfContainer(asElement(containerElement, readableContainerName), errors, top, left, right, bottom);
569+
rootElement.validateInsideOfContainer(asElement(containerElement, readableContainerName), errors, getContext(), top, left, right, bottom);
570570
return this;
571571
}
572572

0 commit comments

Comments
 (0)