Best Galen code snippet using com.galenframework.validation.MetaBasedValidation
Source:SpecValidationInside.java
...46 for (Location location : spec.getLocations()) {47 Range range = location.getRange();48 List<String> perLocationErrors = new LinkedList<>();49 for (Side side : location.getSides()) {50 SimpleValidationResult svr = MetaBasedValidation.forObjectsWithRange(objectName, spec.getObject(), range)51 .withBothEdges(side)52 .withInvertedCalculation(side == Side.RIGHT || side == Side.BOTTOM)53 .validate(mainArea, secondArea, pageValidation, side);54 meta.add(svr.getMeta());55 if (svr.isError()) {56 perLocationErrors.add(svr.getError());57 }58 }59 if (!perLocationErrors.isEmpty()) {60 errorMessages.add(format("%s %s", joinMessages(perLocationErrors, " and "), range.getErrorMessageSuffix()));61 }62 }63 if (errorMessages.size() > 0) {64 throw new ValidationErrorException()...
Source:MetaBasedValidation.java
...23/**24 * This class is used in order to validate distance between edges of two objects.25 * It is used by different specs so that it can also construct layout meta for each validation26 */27public class MetaBasedValidation {28 private final String firstObject;29 private final String secondObject;30 private final Range expectedRange;31 private Side firstEdge = Side.LEFT;32 private Side secondEdge = Side.LEFT;33 private boolean isInverted = false;34 private MetaBasedValidation(String firstObject, String secondObject, Range expectedRange) {35 this.firstObject = firstObject;36 this.secondObject = secondObject;37 this.expectedRange = expectedRange;38 }39 public static MetaBasedValidation forObjectsWithRange(String firstObject, String secondObject, Range expectedRange) {40 return new MetaBasedValidation(firstObject, secondObject, expectedRange);41 }42 public MetaBasedValidation withBothEdges(Side side) {43 this.firstEdge = side;44 this.secondEdge = side;45 return this;46 }47 public SimpleValidationResult validate(Rect firstArea, Rect secondArea, PageValidation pageValidation, String direction) {48 int offset = getOffset(firstArea, secondArea);49 double calculatedOffset = pageValidation.convertValue(expectedRange, offset);50 ;51 if (!expectedRange.holds(calculatedOffset)) {52 if (expectedRange.isPercentage()) {53 int precision = expectedRange.findPrecision();54 String actualDistance = format("%s%% [%dpx]", new RangeValue(calculatedOffset, precision).toString(), offset);55 return SimpleValidationResult.error(56 format("%s %s", actualDistance, direction),57 LayoutMeta.distance(firstObject, firstEdge, secondObject, secondEdge, expectedRange.prettyString("%"), actualDistance)58 );59 } else {60 return SimpleValidationResult.error(61 format("%dpx %s", offset, direction),62 LayoutMeta.distance(firstObject, firstEdge, secondObject, secondEdge, expectedRange.prettyString(), offset + "px")63 );64 }65 }66 return SimpleValidationResult.success(LayoutMeta.distance(firstObject, firstEdge, secondObject, secondEdge, expectedRange.prettyString(), offset + "px"));67 }68 private int getOffset(Rect firstArea, Rect secondArea) {69 int offset = firstArea.getEdgePosition(firstEdge) - secondArea.getEdgePosition(secondEdge);70 if (isInverted) {71 return -offset;72 } else {73 return offset;74 }75 }76 public MetaBasedValidation withInvertedCalculation(boolean isInverted) {77 this.isInverted = isInverted;78 return this;79 }80 public MetaBasedValidation withFirstEdge(Side firstEdge) {81 this.firstEdge = firstEdge;82 return this;83 }84 public MetaBasedValidation withSecondEdge(Side secondEdge) {85 this.secondEdge = secondEdge;86 return this;87 }88}...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!