-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathImageBase64FindStrategy.java
More file actions
74 lines (61 loc) · 2.73 KB
/
ImageBase64FindStrategy.java
File metadata and controls
74 lines (61 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package solutions.bellatrix.web.findstrategies;
import lombok.Getter;
import org.openqa.selenium.By;
import org.openqa.selenium.SearchContext;
import org.openqa.selenium.WebElement;
import solutions.bellatrix.core.configuration.ConfigurationService;
import solutions.bellatrix.core.utilities.Log;
import solutions.bellatrix.core.utilities.SingletonFactory;
import solutions.bellatrix.plugins.opencv.Base64Encodable;
import solutions.bellatrix.plugins.opencv.OpenCvService;
import solutions.bellatrix.plugins.opencv.OpenCvServiceSettings;
import solutions.bellatrix.web.services.JavaScriptService;
import java.util.List;
@Getter
public class ImageBase64FindStrategy extends FindStrategy {
private final Base64Encodable encodedImage;
private final boolean shouldGrayScale;
private final double precisionThreshold;
public ImageBase64FindStrategy(Base64Encodable encodedImage) {
super(encodedImage.getBase64Image());
this.encodedImage = encodedImage;
var serviceSettings = ConfigurationService.get(OpenCvServiceSettings.class);
if (serviceSettings == null) {
serviceSettings = new OpenCvServiceSettings();
}
this.shouldGrayScale = serviceSettings.isShouldGrayscale();
this.precisionThreshold = serviceSettings.getDefaultMatchThreshold();
}
public ImageBase64FindStrategy(Base64Encodable encodedImage, boolean shouldGrayScale, double precisionThreshold) {
super(encodedImage.getBase64Image());
this.shouldGrayScale = shouldGrayScale;
this.precisionThreshold = precisionThreshold;
this.encodedImage = encodedImage;
}
@Override
public By convert() {
return new ByImageBase64(encodedImage);
}
@Override
public String toString() {
return String.format("image base 64: %s", encodedImage.getImageName());
}
public static class ByImageBase64 extends By {
private final Base64Encodable base64EncodedImage;
public ByImageBase64(Base64Encodable base64EncodedImage) {
this.base64EncodedImage = base64EncodedImage;
}
public static By byImageBase64(Base64Encodable encodedImage) {
return new ByImageBase64(encodedImage);
}
@Override
public List<WebElement> findElements(SearchContext context) {
var location = OpenCvService.getLocation(base64EncodedImage);
Log.info("Coordinates located: %s", location.toString());
return SingletonFactory.getInstance(JavaScriptService.class).<List<WebElement>>genericExecute("return document.elementsFromPoint(%s, %s);".formatted(location.x, location.y));
}
public String toString() {
return "By.imageBase64: " + this.base64EncodedImage;
}
}
}