Skip to content

Commit 01bb9c0

Browse files
committed
[1.4.1] - fixed HTML reporting
1 parent 6b3a9a9 commit 01bb9c0

File tree

5 files changed

+69
-42
lines changed

5 files changed

+69
-42
lines changed

src/main/java/util/general/HtmlReportBuilder.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ private void writeReport(String reportName) throws InterruptedException, IOExcep
4444

4545
long ms = System.currentTimeMillis();
4646

47-
try (Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(TARGET_AUTOMOTION + reportName.replace(" ", "") + ms + ".html"), StandardCharsets.UTF_8))) {
47+
try (Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(TARGET_AUTOMOTION + reportName.replace(" ", "_") + "-" + ms + ".html"), StandardCharsets.UTF_8))) {
4848
writer.write(html.toHtmlString());
4949
} catch (IOException ex) {
5050
LOG.error("Cannot create html report: " + ex.getMessage());
@@ -91,10 +91,14 @@ private Html buildHtml() throws IOException, ParseException {
9191
JSONObject jsonObject = (JSONObject) obj;
9292
JSONArray details = (JSONArray) jsonObject.get(DETAILS);
9393
new H1(this,
94-
new Style("color: rgb(0,139,139); margin-top: 50px;")) {{
95-
new NoTag(this, "Element: \"" + jsonObject.get(ELEMENT_NAME) + "\"");
94+
new Style("color: rgb(47,79,79); margin-top: 50px;")) {{
95+
new NoTag(this, "Scenario: \"" + jsonObject.get(SCENARIO) + "\"");
9696
}};
9797
new H2(this,
98+
new Style("color: rgb(0,139,139);")) {{
99+
new NoTag(this, "Element: \"" + jsonObject.get(ELEMENT_NAME) + "\"");
100+
}};
101+
new H3(this,
98102
new Style("color: rgb(255,69,0)")) {{
99103
new NoTag(this, "Failures:");
100104
}};

src/main/java/util/validator/Constants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class Constants {
1313
public static final String SCREENSHOT = "screenshot";
1414
public static final String ELEMENT_NAME = "elementName";
1515
public static final String ROOT_ELEMENT = "rootElement";
16+
public static final String SCENARIO = "scenario";
1617
public static final String TIME_EXECUTION = "timeExecution";
1718
public static final String TARGET_AUTOMOTION_JSON = "target/automotion/json/";
1819
public static final String TARGET_AUTOMOTION_IMG = "target/automotion/img/";

src/main/java/util/validator/ResponsiveUIValidator.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@
3131
public class ResponsiveUIValidator implements Validator {
3232

3333
private final static Logger LOG = Logger.getLogger(ResponsiveUIValidator.class);
34-
private static boolean withReport = false;
3534
private static final int MIN_OFFSET = -10000;
35+
private static boolean withReport = false;
3636
private static long startTime;
3737
private static JSONObject jsonResults;
38+
private static String scenarioName = "Default";
3839
private WebDriver driver;
3940
private String rootElementReadableName = "Root Element";
4041
private WebElement rootElement;
@@ -67,6 +68,12 @@ public ResponsiveUIValidator init() {
6768
return new ResponsiveUIValidator(driver);
6869
}
6970

71+
@Override
72+
public ResponsiveUIValidator init(String scenarioName) {
73+
ResponsiveUIValidator.scenarioName = scenarioName;
74+
return new ResponsiveUIValidator(driver);
75+
}
76+
7077
@Override
7178
public ResponsiveUIValidator findElement(WebElement element, String readableNameOfElement) {
7279
rootElement = element;
@@ -426,6 +433,7 @@ public boolean validate() {
426433
rootDetails.put(WIDTH, widthRoot);
427434
rootDetails.put(HEIGHT, heightRoot);
428435

436+
jsonResults.put(SCENARIO, scenarioName);
429437
jsonResults.put(ROOT_ELEMENT, rootDetails);
430438
jsonResults.put(TIME_EXECUTION, String.valueOf(System.currentTimeMillis() - startTime) + " milliseconds");
431439
jsonResults.put(ELEMENT_NAME, rootElementReadableName);
@@ -476,10 +484,12 @@ public void generateReport() {
476484

477485
@Override
478486
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+
}
483493
}
484494
}
485495

@@ -880,7 +890,8 @@ private void drawRoot(Color color) {
880890
g.drawRect(xRoot, yRoot, widthRoot, heightRoot);
881891
}
882892

883-
g.setStroke(new BasicStroke(1));
893+
Stroke dashed = new BasicStroke(2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[]{9}, 0);
894+
g.setStroke(dashed);
884895
g.setColor(Color.ORANGE);
885896
if (drawLeftOffsetLine) {
886897
if (SystemHelper.isRetinaDisplay(g) && isChrome()) {

src/main/java/util/validator/Validator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
interface Validator {
88
ResponsiveUIValidator init();
99

10+
ResponsiveUIValidator init(String scenarioName);
11+
1012
ResponsiveUIValidator findElement(WebElement element, String readableNameOfElement);
1113

1214
ResponsiveUIValidator findElements(List<WebElement> elements);
Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import org.junit.After;
12
import org.junit.Assert;
23
import org.junit.Ignore;
34
import org.junit.Test;
@@ -11,13 +12,15 @@
1112
@Ignore
1213
public class ResponsiveValidatorTest {
1314

15+
private static WebDriver driver;
16+
1417
@Test
1518
public void testThatResponsiveValidatorWorks() {
1619
System.setProperty("IS_LOCAL", "TRUE");
1720
System.setProperty("BROWSER", "Firefox");
1821

1922
WebDriverFactory driverFactory = new WebDriverFactory();
20-
WebDriver driver = driverFactory.getDriver();
23+
driver = driverFactory.getDriver();
2124
driver.manage().window().maximize();
2225

2326
driver.get("https://www.facey.top");
@@ -26,47 +29,53 @@ public void testThatResponsiveValidatorWorks() {
2629

2730
ResponsiveUIValidator responsiveValidator = new ResponsiveUIValidator(driver);
2831

29-
boolean res1 = responsiveValidator.init()
32+
boolean res1 = responsiveValidator.init("Grid validation")
3033
.findElements(page.images())
31-
.alignedAsGrid(1, 4)
34+
.alignedAsGrid(1, 3)
3235
.areNotOverlappedWithEachOther()
3336
.withSameSize()
3437
.drawMap()
3538
.validate();
3639

37-
// responsiveValidator.init()
38-
// .findElement(page.newPhotos(), "New Photos")
39-
// .changeMetricsUnitsTo(PERCENT)
40-
// .widthBetween(30, 40)
41-
// .heightBetween(5, 8)
42-
// .changeMetricsUnitsTo(PX)
43-
// .minOffset(2, 30, 50, 30)
44-
// .maxOffset(5, 40, 70, 40)
45-
// .notOverlapWith(page.header(), "Header")
46-
// .notOverlapWith(page.myPhotos(), "My Photos")
47-
// .notOverlapWith(page.topPhotos(), "Top Photos")
48-
// .sameOffsetRightAs(page.logo(), "Logo")
49-
// .withTopElement(page.header())
50-
// .drawMap()
51-
// .validate();
52-
//
53-
// responsiveValidator.init()
54-
// .findElement(page.newPhotos(), "New Photos")
55-
// .widthBetween(300, 400)
56-
// .heightBetween(20, 50)
57-
// .minOffset(10, 500, 500, 600)
58-
// .maxOffset(200, 2000, 2000, 1000)
59-
// .notOverlapWith(page.header(), "Header")
60-
// .notOverlapWith(page.myPhotos(), "My Photos")
61-
// .notOverlapWith(page.topPhotos(), "Top Photos")
62-
// .sameOffsetRightAs(page.logo(), "Logo")
63-
// .drawMap()
64-
// .validate();
40+
responsiveValidator.init()
41+
.findElement(page.newPhotos(), "New Photos")
42+
.changeMetricsUnitsTo(PERCENT)
43+
.widthBetween(30, 40)
44+
.heightBetween(5, 8)
45+
.changeMetricsUnitsTo(PX)
46+
.minOffset(2, 30, 50, 30)
47+
.maxOffset(5, 40, 70, 40)
48+
.notOverlapWith(page.header(), "Header")
49+
.notOverlapWith(page.myPhotos(), "My Photos")
50+
.notOverlapWith(page.topPhotos(), "Top Photos")
51+
.sameOffsetRightAs(page.logo(), "Logo")
52+
.withTopElement(page.header())
53+
.drawMap()
54+
.validate();
6555

66-
responsiveValidator.generateReport("Base_Page");
56+
responsiveValidator.init()
57+
.findElement(page.newPhotos(), "New Photos")
58+
.widthBetween(300, 400)
59+
.heightBetween(20, 50)
60+
.minOffset(10, 500, 500, 600)
61+
.maxOffset(200, 2000, 2000, 1000)
62+
.notOverlapWith(page.header(), "Header")
63+
.notOverlapWith(page.myPhotos(), "My Photos")
64+
.notOverlapWith(page.topPhotos(), "Top Photos")
65+
.sameOffsetRightAs(page.logo(), "Logo")
66+
.drawMap()
67+
.validate();
6768

68-
driver.quit();
69+
responsiveValidator.generateReport("Base_Page");
6970

7071
Assert.assertTrue("Validation is failed", res1);
7172
}
73+
74+
@After
75+
public void tearDown(){
76+
if (driver != null){
77+
driver.quit();
78+
}
79+
}
80+
7281
}

0 commit comments

Comments
 (0)