Skip to content

Commit f297832

Browse files
committed
removed rectangles from JSON, drawing them immediately
1 parent 7761ffb commit f297832

File tree

2 files changed

+22
-44
lines changed

2 files changed

+22
-44
lines changed

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

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,37 @@
88
public class Errors {
99

1010
private final JSONArray messages = new JSONArray();
11+
private final ResponsiveUIValidatorBase responsiveUIValidatorBase;
1112
private String lastMessage;
1213

14+
public Errors(ResponsiveUIValidatorBase responsiveUIValidatorBase) {
15+
this.responsiveUIValidatorBase = responsiveUIValidatorBase;
16+
}
17+
1318
public String getLastMessage() {
1419
return lastMessage;
1520
}
1621

1722
public void add(String message) {
18-
internalAdd(message, null, null);
19-
}
20-
21-
public void add(String message, UIElement element) {
22-
internalAdd(message, element, encode(element));
23-
}
24-
25-
private void internalAdd(String message, UIElement element, JSONObject encodedElement) {
2623
lastMessage = message;
2724
JSONObject details = new JSONObject();
2825
JSONObject messageObject = new JSONObject();
2926
messageObject.put(MESSAGE, message);
30-
if (encodedElement != null) {
31-
messageObject.put(ELEMENT, encodedElement);
32-
}
3327
details.put(REASON, messageObject);
3428
messages.add(details);
3529
}
3630

37-
private JSONObject encode(UIElement element) {
38-
float xContainer = element.getX().intValue();
39-
float yContainer = element.getY().intValue();
40-
float widthContainer = element.getWidth().intValue();
41-
float heightContainer = element.getHeight().intValue();
31+
public void add(String message, UIElement element) {
32+
add(message);
33+
draw(element);
34+
}
4235

43-
JSONObject elDetails = new JSONObject();
44-
elDetails.put(X, xContainer);
45-
elDetails.put(Y, yContainer);
46-
elDetails.put(WIDTH, widthContainer);
47-
elDetails.put(HEIGHT, heightContainer);
48-
return elDetails;
36+
public void draw(UIElement element) {
37+
int x = element.getOrigin().getX().intValue();
38+
int y = element.getOrigin().getY().intValue();
39+
int width = element.getWidth().intValue();
40+
int height = element.getHeight().intValue();
41+
responsiveUIValidatorBase.getDrawableScreenshot().drawRectangle(x, y, width, height);
4942
}
5043

5144

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

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ public abstract class ResponsiveUIValidatorBase {
2828
private final double zoomFactor;
2929
private DrawableScreenshot drawableScreenshot;
3030
private Scalar tolerance;
31+
private boolean rootElementDrawn;
3132

3233
protected ResponsiveUIValidatorBase(UISnapshot snapshot) {
3334
this.snapshot = snapshot;
3435
this.driver = snapshot.getResponsiveUIValidator().getDriver();
35-
this.errors = new Errors();
36+
this.errors = new Errors(this);
3637
this.zoomFactor = snapshot.getZoomFactor();
3738
Dimension dimension = this.driver.retrievePageSize();
3839
this.page = UIElement.asElement(new net.itarray.automotion.internal.geometry.Rectangle(0, 0, dimension.getWidth(), dimension.getHeight()), "page");
@@ -41,19 +42,20 @@ protected ResponsiveUIValidatorBase(UISnapshot snapshot) {
4142
}
4243

4344

44-
private DrawableScreenshot getDrawableScreenshot() {
45+
public DrawableScreenshot getDrawableScreenshot() {
4546
if (drawableScreenshot == null) {
4647
File screenshotName = snapshot.takeScreenshot();
4748
Vector extend = driver.getExtend(screenshotName);
4849
this.drawableScreenshot = new DrawableScreenshot(extend, getTransform(), getDrawingConfiguration(), getNameOfToBeValidated(), screenshotName);
4950
}
51+
if (isWithReport() && !rootElementDrawn) {
52+
rootElementDrawn = true;
53+
drawRootElement();
54+
}
5055
return drawableScreenshot;
5156
}
5257

5358
protected void doSnapshot() {
54-
if (isWithReport()) {
55-
drawRootElement();
56-
}
5759
}
5860

5961
public Errors getErrors() {
@@ -133,23 +135,6 @@ public boolean isPixels() {
133135
protected abstract String getNameOfToBeValidated();
134136

135137
private void compileValidationReport() {
136-
if (isWithReport()) {
137-
for (Object obj : errors.getMessages()) {
138-
JSONObject det = (JSONObject) obj;
139-
JSONObject details = (JSONObject) det.get(REASON);
140-
JSONObject numE = (JSONObject) details.get(ELEMENT);
141-
142-
if (numE != null) {
143-
int x = (int) (float) numE.get(X);
144-
int y = (int) (float) numE.get(Y);
145-
int width = (int) (float) numE.get(WIDTH);
146-
int height = (int) (float) numE.get(HEIGHT);
147-
148-
getDrawableScreenshot().drawRectangle(x, y, width, height);
149-
}
150-
}
151-
}
152-
153138
if (isWithReport()) {
154139
getDrawableScreenshot().saveDrawing();
155140
}

0 commit comments

Comments
 (0)