24
24
public class ByImage extends By {
25
25
private static boolean wasLibraryLoaded = false ;
26
26
private final Mat template ;
27
+ private final String description ;
27
28
28
29
private static void loadLibrary () {
29
30
if (!wasLibraryLoaded ) {
@@ -40,24 +41,43 @@ private static void loadLibrary() {
40
41
*/
41
42
public ByImage (File file ) {
42
43
loadLibrary ();
44
+ description = file .getName ();
43
45
this .template = Imgcodecs .imread (file .getAbsolutePath (), Imgcodecs .IMREAD_UNCHANGED );
44
46
}
45
47
46
48
/**
47
- * Constructor accepting image file .
49
+ * Constructor accepting image bytes .
48
50
*
49
51
* @param bytes image bytes to locate element by.
50
52
*/
51
53
public ByImage (byte [] bytes ) {
52
54
loadLibrary ();
55
+ description = String .format ("bytes[%d]" , bytes .length );
53
56
this .template = Imgcodecs .imdecode (new MatOfByte (bytes ), Imgcodecs .IMREAD_UNCHANGED );
54
57
}
55
58
56
59
@ Override
57
60
public String toString () {
58
- return "ByImage: " + new Dimension ( template .width (), template .height ());
61
+ return String . format ( "ByImage: %s, size: (width:%d, height:%d)" , description , template .width (), template .height ());
59
62
}
60
63
64
+ @ Override
65
+ public boolean equals (Object o ) {
66
+ if (!(o instanceof ByImage )) {
67
+ return false ;
68
+ }
69
+
70
+ ByImage that = (ByImage ) o ;
71
+
72
+ return this .template .equals (that .template );
73
+ }
74
+
75
+ @ Override
76
+ public int hashCode () {
77
+ return template .hashCode ();
78
+ }
79
+
80
+
61
81
@ Override
62
82
public List <WebElement > findElements (SearchContext context ) {
63
83
Mat source = getScreenshot (context );
0 commit comments