1212import org .openqa .selenium .Dimension ;
1313
1414import java .awt .*;
15- import java .io .BufferedWriter ;
16- import java .io .File ;
17- import java .io .FileOutputStream ;
18- import java .io .IOException ;
19- import java .io .OutputStreamWriter ;
20- import java .io .Writer ;
15+ import java .io .*;
2116import java .nio .charset .StandardCharsets ;
2217
2318import static net .itarray .automotion .validation .Constants .*;
2419
2520public abstract class ResponsiveUIValidatorBase {
2621
27- private final Errors errors ;
2822 protected final UIElement page ;
29- private final long startTime ;
3023 protected final UISnapshot snapshot ;
24+ private final Errors errors ;
25+ private final long startTime ;
3126 private final DriverFacade driver ;
3227 private final double zoomFactor ;
3328 private DrawableScreenshot drawableScreenshot ;
@@ -47,12 +42,12 @@ protected ResponsiveUIValidatorBase(UISnapshot snapshot) {
4742
4843
4944 public DrawableScreenshot getDrawableScreenshot () {
50- if (drawableScreenshot == null ) {
45+ if (drawableScreenshot == null && this . errors . hasMessages () ) {
5146 File screenshotName = snapshot .takeScreenshot ();
5247 Vector extend = driver .getExtend (screenshotName );
5348 this .drawableScreenshot = new DrawableScreenshot (extend , getTransform (), getDrawingConfiguration (), getNameOfToBeValidated (), screenshotName );
5449 }
55- if (isWithReport () && !rootElementDrawn ) {
50+ if (isWithReport () && !rootElementDrawn && this . errors . hasMessages () ) {
5651 rootElementDrawn = true ;
5752 drawRootElement ();
5853 }
@@ -104,7 +99,7 @@ public ResponsiveUIValidatorBase dontDrawMap() {
10499 public boolean validate () {
105100
106101 //if (errors.hasMessages()) {
107- compileValidationReport ();
102+ compileValidationReport ();
108103 //}
109104
110105 return !errors .hasMessages ();
@@ -127,7 +122,9 @@ public boolean isPixels() {
127122 }
128123
129124 @ Override
130- public Scalar getTolerance () { return tolerance ; }
125+ public Scalar getTolerance () {
126+ return tolerance ;
127+ }
131128
132129 @ Override
133130 public void add (String message ) {
@@ -136,29 +133,41 @@ public void add(String message) {
136133
137134 @ Override
138135 public void draw (UIElement element ) {
139- if (isWithReport ()) {
140- getDrawableScreenshot ().draw (element );
136+ DrawableScreenshot drawableScreenshot = getDrawableScreenshot ();
137+ if (drawableScreenshot != null ) {
138+ if (isWithReport ()) {
139+ getDrawableScreenshot ().draw (element );
140+ }
141141 }
142142 }
143143
144144 @ Override
145145 public void drawRoot (UIElement element ) {
146- if (isWithReport ()) {
147- getDrawableScreenshot ().drawRoot (element );
146+ DrawableScreenshot drawableScreenshot = getDrawableScreenshot ();
147+ if (drawableScreenshot != null ) {
148+ if (isWithReport ()) {
149+ getDrawableScreenshot ().drawRoot (element );
150+ }
148151 }
149152 }
150153
151154 @ Override
152155 public void drawHorizontalLine (Vector onLine ) {
153- if (isWithReport ()) {
154- getDrawableScreenshot ().drawHorizontalLine (onLine .getY ());
156+ DrawableScreenshot drawableScreenshot = getDrawableScreenshot ();
157+ if (drawableScreenshot != null ) {
158+ if (isWithReport ()) {
159+ getDrawableScreenshot ().drawHorizontalLine (onLine .getY ());
160+ }
155161 }
156162 }
157163
158164 @ Override
159165 public void drawVerticalLine (Vector onLine ) {
160- if (isWithReport ()) {
161- getDrawableScreenshot ().drawVerticalLine (onLine .getX ());
166+ DrawableScreenshot drawableScreenshot = getDrawableScreenshot ();
167+ if (drawableScreenshot != null ) {
168+ if (isWithReport ()) {
169+ getDrawableScreenshot ().drawVerticalLine (onLine .getX ());
170+ }
162171 }
163172 }
164173
@@ -173,8 +182,12 @@ public int errorCount() {
173182 protected abstract String getNameOfToBeValidated ();
174183
175184 private void compileValidationReport () {
176- if (isWithReport ()) {
177- getDrawableScreenshot ().saveDrawing ();
185+ DrawableScreenshot drawableScreenshot = getDrawableScreenshot ();
186+
187+ if (drawableScreenshot != null ) {
188+ if (isWithReport ()) {
189+ getDrawableScreenshot ().saveDrawing ();
190+ }
178191 }
179192
180193 if (isWithReport ()) {
@@ -224,8 +237,8 @@ private void writeResults(DrawableScreenshot drawableScreenshot) {
224237 jsonResults .put (ROOT_ELEMENT , rootDetails );
225238 jsonResults .put (TIME_EXECUTION , String .valueOf (System .currentTimeMillis () - startTime ) + " milliseconds" );
226239 jsonResults .put (ELEMENT_NAME , getNameOfToBeValidated ());
227- jsonResults .put (SCREENSHOT , drawableScreenshot .getScreenshotName ().getName ());
228- jsonResults .put (DRAWINGS , drawableScreenshot .getDrawingsOutput ().getName ());
240+ jsonResults .put (SCREENSHOT , drawableScreenshot != null ? drawableScreenshot .getScreenshotName ().getName () : "" );
241+ jsonResults .put (DRAWINGS , drawableScreenshot != null ? drawableScreenshot .getDrawingsOutput ().getName () : "" );
229242
230243 long ms = System .currentTimeMillis ();
231244 String uuid = Helper .getGeneratedStringWithLength (7 );
0 commit comments