2424public class ByImage extends By {
2525 private static boolean wasLibraryLoaded = false ;
2626 private final Mat template ;
27+ private final String description ;
2728
2829 private static void loadLibrary () {
2930 if (!wasLibraryLoaded ) {
@@ -40,24 +41,43 @@ private static void loadLibrary() {
4041 */
4142 public ByImage (File file ) {
4243 loadLibrary ();
44+ description = file .getName ();
4345 this .template = Imgcodecs .imread (file .getAbsolutePath (), Imgcodecs .IMREAD_UNCHANGED );
4446 }
4547
4648 /**
47- * Constructor accepting image file .
49+ * Constructor accepting image bytes .
4850 *
4951 * @param bytes image bytes to locate element by.
5052 */
5153 public ByImage (byte [] bytes ) {
5254 loadLibrary ();
55+ description = String .format ("bytes[%d]" , bytes .length );
5356 this .template = Imgcodecs .imdecode (new MatOfByte (bytes ), Imgcodecs .IMREAD_UNCHANGED );
5457 }
5558
5659 @ Override
5760 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 ());
5962 }
6063
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+
6181 @ Override
6282 public List <WebElement > findElements (SearchContext context ) {
6383 Mat source = getScreenshot (context );
0 commit comments