|
31 | 31 | public class ResponsiveUIValidator implements Validator { |
32 | 32 |
|
33 | 33 | private final static Logger LOG = Logger.getLogger(ResponsiveUIValidator.class); |
34 | | - private static boolean withReport = false; |
35 | 34 | private static final int MIN_OFFSET = -10000; |
| 35 | + private static boolean withReport = false; |
36 | 36 | private static long startTime; |
37 | 37 | private static JSONObject jsonResults; |
| 38 | + private static String scenarioName = "Default"; |
38 | 39 | private WebDriver driver; |
39 | 40 | private String rootElementReadableName = "Root Element"; |
40 | 41 | private WebElement rootElement; |
@@ -67,6 +68,12 @@ public ResponsiveUIValidator init() { |
67 | 68 | return new ResponsiveUIValidator(driver); |
68 | 69 | } |
69 | 70 |
|
| 71 | + @Override |
| 72 | + public ResponsiveUIValidator init(String scenarioName) { |
| 73 | + ResponsiveUIValidator.scenarioName = scenarioName; |
| 74 | + return new ResponsiveUIValidator(driver); |
| 75 | + } |
| 76 | + |
70 | 77 | @Override |
71 | 78 | public ResponsiveUIValidator findElement(WebElement element, String readableNameOfElement) { |
72 | 79 | rootElement = element; |
@@ -426,6 +433,7 @@ public boolean validate() { |
426 | 433 | rootDetails.put(WIDTH, widthRoot); |
427 | 434 | rootDetails.put(HEIGHT, heightRoot); |
428 | 435 |
|
| 436 | + jsonResults.put(SCENARIO, scenarioName); |
429 | 437 | jsonResults.put(ROOT_ELEMENT, rootDetails); |
430 | 438 | jsonResults.put(TIME_EXECUTION, String.valueOf(System.currentTimeMillis() - startTime) + " milliseconds"); |
431 | 439 | jsonResults.put(ELEMENT_NAME, rootElementReadableName); |
@@ -476,10 +484,12 @@ public void generateReport() { |
476 | 484 |
|
477 | 485 | @Override |
478 | 486 | public void generateReport(String name) { |
479 | | - try { |
480 | | - new HtmlReportBuilder().buildReport(name); |
481 | | - } catch (IOException | ParseException | InterruptedException e) { |
482 | | - e.printStackTrace(); |
| 487 | + if (withReport && (boolean) jsonResults.get(ERROR_KEY)) { |
| 488 | + try { |
| 489 | + new HtmlReportBuilder().buildReport(name); |
| 490 | + } catch (IOException | ParseException | InterruptedException e) { |
| 491 | + e.printStackTrace(); |
| 492 | + } |
483 | 493 | } |
484 | 494 | } |
485 | 495 |
|
@@ -726,21 +736,32 @@ private void validateSameSize(List<WebElement> elements) { |
726 | 736 | int h2 = el2.getSize().getHeight(); |
727 | 737 | int w2 = el2.getSize().getWidth(); |
728 | 738 | if (h1 != h2 || w1 != w2) { |
729 | | - putJsonDetailsWithoutElement("Elements in a gird have different size."); |
| 739 | + putJsonDetailsWithElement("Elements in a grid have different size.", el1); |
730 | 740 | } |
731 | 741 | } |
732 | 742 | } |
733 | 743 | } |
734 | 744 | } |
735 | 745 |
|
736 | 746 | private void validateInsideOfContainer(WebElement element, String readableContainerName) { |
737 | | - float xContainer = element.getLocation().getX(); |
738 | | - float yContainer = element.getLocation().getY(); |
739 | | - float widthContainer = element.getSize().getWidth(); |
740 | | - float heightContainer = element.getSize().getHeight(); |
741 | | - |
742 | | - if (xRoot < xContainer || yRoot < yContainer || (xRoot + widthRoot) > (xContainer + widthContainer) || (yRoot + heightRoot) > (yContainer + heightContainer)) { |
743 | | - putJsonDetailsWithElement(String.format("Element '%s' is not inside of '%s'", rootElementReadableName, readableContainerName), element); |
| 747 | + float xContainer = element.getLocation().x; |
| 748 | + float yContainer = element.getLocation().y; |
| 749 | + float widthContainer = element.getSize().width; |
| 750 | + float heightContainer = element.getSize().height; |
| 751 | + if (rootElements == null || rootElements.isEmpty()) { |
| 752 | + if (xRoot < xContainer || yRoot < yContainer || (xRoot + widthRoot) > (xContainer + widthContainer) || (yRoot + heightRoot) > (yContainer + heightContainer)) { |
| 753 | + putJsonDetailsWithElement(String.format("Element '%s' is not inside of '%s'", rootElementReadableName, readableContainerName), element); |
| 754 | + } |
| 755 | + }else{ |
| 756 | + for (WebElement el: rootElements){ |
| 757 | + float xRoot = el.getLocation().x; |
| 758 | + float yRoot = el.getLocation().y; |
| 759 | + float widthRoot = el.getSize().width; |
| 760 | + float heightRoot = el.getSize().height; |
| 761 | + if (xRoot < xContainer || yRoot < yContainer || (xRoot + widthRoot) > (xContainer + widthContainer) || (yRoot + heightRoot) > (yContainer + heightContainer)) { |
| 762 | + putJsonDetailsWithElement(String.format("Element is not inside of '%s'", readableContainerName), element); |
| 763 | + } |
| 764 | + } |
744 | 765 | } |
745 | 766 | } |
746 | 767 |
|
@@ -880,7 +901,8 @@ private void drawRoot(Color color) { |
880 | 901 | g.drawRect(xRoot, yRoot, widthRoot, heightRoot); |
881 | 902 | } |
882 | 903 |
|
883 | | - g.setStroke(new BasicStroke(1)); |
| 904 | + Stroke dashed = new BasicStroke(2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[]{9}, 0); |
| 905 | + g.setStroke(dashed); |
884 | 906 | g.setColor(Color.ORANGE); |
885 | 907 | if (drawLeftOffsetLine) { |
886 | 908 | if (SystemHelper.isRetinaDisplay(g) && isChrome()) { |
|
0 commit comments