44import org .apache .log4j .Logger ;
55import org .json .simple .JSONArray ;
66import org .json .simple .JSONObject ;
7+ import org .json .simple .parser .ParseException ;
78import org .openqa .selenium .Dimension ;
89import org .openqa .selenium .*;
910import org .openqa .selenium .Point ;
1011import util .driver .PageValidator ;
12+ import util .general .HtmlReportBuilder ;
13+ import util .general .SystemHelper ;
1114
1215import javax .imageio .ImageIO ;
1316import java .awt .*;
1922import java .util .List ;
2023import java .util .Map ;
2124
25+ import static environment .EnvironmentFactory .isChrome ;
26+
2227public class ResponsiveValidator implements Validator {
2328
2429 private static final String X = "x" ;
@@ -87,6 +92,11 @@ public ResponsiveValidator(WebDriver driver) {
8792 this .driver = driver ;
8893 }
8994
95+ @ Override
96+ public ResponsiveValidator init () {
97+ return new ResponsiveValidator (driver );
98+ }
99+
90100 @ Override
91101 public ResponsiveValidator findElement (WebElement element , String readableNameOfElement ) {
92102 rootElement = element ;
@@ -352,16 +362,18 @@ public boolean validate() {
352362 rootDetails .put (HEIGHT , heightRoot );
353363
354364 jsonResults .put ("rootElement" , rootDetails );
365+ jsonResults .put ("elementName" , rootElementReadableName );
355366 jsonResults .put ("screenshot" , rootElementReadableName .replace (" " , "" ) + "-" + screenshot .getName ());
356367 }
357368
358- try (Writer writer = new BufferedWriter (new OutputStreamWriter (new FileOutputStream (TARGET_AUTOMOTION_JSON + rootElementReadableName .replace (" " , "" ) + "-automotion" + System .currentTimeMillis () + ".json" ), StandardCharsets .UTF_8 ))) {
369+ long ms = System .currentTimeMillis ();
370+ try (Writer writer = new BufferedWriter (new OutputStreamWriter (new FileOutputStream (TARGET_AUTOMOTION_JSON + rootElementReadableName .replace (" " , "" ) + "-automotion" + ms + ".json" ), StandardCharsets .UTF_8 ))) {
359371 writer .write (jsonResults .toJSONString ());
360372 } catch (IOException ex ) {
361- LOG .error ("Cannot create json report: " + ex .getMessage ());
373+ LOG .error ("Cannot create html report: " + ex .getMessage ());
362374 }
363375 try {
364- File file = new File (TARGET_AUTOMOTION_JSON + rootElementReadableName .replace (" " , "" ) + "-automotion" + System . currentTimeMillis () + ".json" );
376+ File file = new File (TARGET_AUTOMOTION_JSON + rootElementReadableName .replace (" " , "" ) + "-automotion" + ms + ".json" );
365377 if (file .getParentFile ().mkdirs ()) {
366378 if (file .createNewFile ()) {
367379 BufferedWriter writer = new BufferedWriter (new FileWriter (file ));
@@ -387,7 +399,11 @@ public boolean validate() {
387399
388400 @ Override
389401 public void generateReport () {
390-
402+ try {
403+ new HtmlReportBuilder ().buildReport ();
404+ } catch (IOException | ParseException | InterruptedException e ) {
405+ e .printStackTrace ();
406+ }
391407 }
392408
393409 private void drawScreenshot () {
@@ -408,7 +424,11 @@ private void drawScreenshot() {
408424
409425 g .setColor (Color .MAGENTA );
410426 g .setStroke (new BasicStroke (2 ));
411- g .drawRect ((int ) x , (int ) y , (int ) width , (int ) height );
427+ if (SystemHelper .isRetinaDisplay (g ) && isChrome ()) {
428+ g .drawRect (2 * (int ) x , 2 * (int ) y , 2 * (int ) width , 2 * (int ) height );
429+ } else {
430+ g .drawRect ((int ) x , (int ) y , (int ) width , (int ) height );
431+ }
412432 }
413433 }
414434
@@ -639,13 +659,24 @@ private boolean elementsHasEqualTopBottomOffset(boolean isTop, WebElement elemen
639659 private void drawRoot (Color color ) {
640660 g .setColor (color );
641661 g .setStroke (new BasicStroke (2 ));
642- g .drawRect (xRoot , yRoot , widthRoot , heightRoot );
662+ if (SystemHelper .isRetinaDisplay (g ) && isChrome ()) {
663+ g .drawRect (2 * xRoot , 2 * yRoot , 2 * widthRoot , 2 * heightRoot );
664+ } else {
665+ g .drawRect (xRoot , yRoot , widthRoot , heightRoot );
666+ }
643667 g .setStroke (new BasicStroke (1 ));
644668 g .setColor (Color .ORANGE );
645- g .drawLine (0 , yRoot , pageWidth , yRoot );
646- g .drawLine (0 , yRoot + heightRoot , pageWidth , yRoot + heightRoot );
647- g .drawLine (xRoot , 0 , xRoot , pageHeight );
648- g .drawLine (xRoot + widthRoot , 0 , xRoot + widthRoot , pageHeight );
669+ if (SystemHelper .isRetinaDisplay (g ) && isChrome ()) {
670+ g .drawLine (0 , 2 * yRoot , 2 * pageWidth , 2 * yRoot );
671+ g .drawLine (0 , 2 * (yRoot + heightRoot ), 2 * pageWidth , 2 * (yRoot + heightRoot ));
672+ g .drawLine (2 * xRoot , 0 , 2 * xRoot , 2 * pageHeight );
673+ g .drawLine (2 * (xRoot + widthRoot ), 0 , 2 * (xRoot + widthRoot ), 2 * pageHeight );
674+ } else {
675+ g .drawLine (0 , yRoot , pageWidth , yRoot );
676+ g .drawLine (0 , yRoot + heightRoot , pageWidth , yRoot + heightRoot );
677+ g .drawLine (xRoot , 0 , xRoot , pageHeight );
678+ g .drawLine (xRoot + widthRoot , 0 , xRoot + widthRoot , pageHeight );
679+ }
649680 }
650681
651682 private void putJsonDetailsWithoutElement (String message ) {
0 commit comments