Skip to content

Commit 2274f82

Browse files
committed
Implement VisualConfiguration
1 parent e1039a4 commit 2274f82

File tree

2 files changed

+92
-0
lines changed

2 files changed

+92
-0
lines changed

src/main/java/aquality/selenium/core/configurations/IVisualConfiguration.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,34 @@ public interface IVisualConfiguration {
99
* @return image format.
1010
*/
1111
String getImageFormat();
12+
13+
/**
14+
* Gets maximum length of full file name with path for image comparison.
15+
* @return maximum symbols count in file path.
16+
*/
17+
int getMaxFullFileNameLength();
18+
19+
/**
20+
* Gets default threshold used for image comparison.
21+
* @return The default threshold value.
22+
*/
23+
float getDefaultThreshold();
24+
25+
/**
26+
* Gets width of the image resized for comparison.
27+
* @return comparison width.
28+
*/
29+
int getComparisonWidth();
30+
31+
/**
32+
* Gets height of the image resized for comparison.
33+
* @return comparison height.
34+
*/
35+
int getComparisonHeight();
36+
37+
/**
38+
* Gets path used to save and load page dumps.
39+
* @return path to dumps.
40+
*/
41+
String getPathToDumps();
1242
}

src/main/java/aquality/selenium/core/configurations/VisualConfiguration.java

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package aquality.selenium.core.configurations;
22

3+
import aquality.selenium.core.logging.Logger;
34
import aquality.selenium.core.utilities.ISettingsFile;
45
import com.google.inject.Inject;
56

67
import javax.imageio.ImageIO;
8+
import java.io.File;
9+
import java.io.IOException;
710
import java.util.Arrays;
811

912
/**
@@ -12,6 +15,12 @@
1215
*/
1316
public class VisualConfiguration implements IVisualConfiguration {
1417
private String imageFormat;
18+
private Integer maxFullFileNameLength;
19+
private Float defaultThreshold;
20+
private Integer comparisonWidth;
21+
private Integer comparisonHeight;
22+
private String pathToDumps;
23+
1524
private final ISettingsFile settingsFile;
1625

1726
/**
@@ -37,4 +46,57 @@ public String getImageFormat() {
3746
}
3847
return imageFormat;
3948
}
49+
50+
@Override
51+
public int getMaxFullFileNameLength() {
52+
if (maxFullFileNameLength == null) {
53+
maxFullFileNameLength = Integer.valueOf(
54+
settingsFile.getValueOrDefault("/visualization/maxFullFileNameLength", 255).toString());
55+
}
56+
return maxFullFileNameLength;
57+
}
58+
59+
@Override
60+
public float getDefaultThreshold() {
61+
if (defaultThreshold == null) {
62+
defaultThreshold = Float.valueOf(
63+
settingsFile.getValueOrDefault("/visualization/defaultThreshold", 0.012f).toString());
64+
}
65+
return defaultThreshold;
66+
}
67+
68+
@Override
69+
public int getComparisonWidth() {
70+
if (comparisonWidth == null) {
71+
comparisonWidth = Integer.valueOf(
72+
settingsFile.getValueOrDefault("/visualization/comparisonWidth", 16).toString());
73+
}
74+
return comparisonWidth;
75+
}
76+
77+
@Override
78+
public int getComparisonHeight() {
79+
if (comparisonHeight == null) {
80+
comparisonHeight = Integer.valueOf(
81+
settingsFile.getValueOrDefault("/visualization/comparisonHeight", 16).toString());
82+
}
83+
return comparisonHeight;
84+
}
85+
86+
@Override
87+
public String getPathToDumps() {
88+
if (pathToDumps == null) {
89+
pathToDumps = settingsFile.getValueOrDefault(".visualization.pathToDumps", "./src/test/resources/VisualDumps/").toString();
90+
if (pathToDumps.startsWith(".")) {
91+
try {
92+
pathToDumps = new File(pathToDumps).getCanonicalPath();
93+
} catch (IOException e) {
94+
String errorMessage = "Failed to resolve path to dumps: " + e.getMessage();
95+
Logger.getInstance().fatal(errorMessage, e);
96+
throw new IllegalArgumentException(errorMessage, e);
97+
}
98+
}
99+
}
100+
return pathToDumps;
101+
}
40102
}

0 commit comments

Comments
 (0)