config :
- Версия клиента Appium: 9.3.0
- Версия сервера Appium: 2.12.1
- Версия плагина изображений: images@3.0.21
Версия jdk: jdk-21.0.5.11-openj9
Код: Выделить всё
public boolean isImagePresent(String baseImagePath, String secondImagePath) {
try {
// Load the base image as a byte array
byte[] baseImage = Files.readAllBytes(Paths.get(baseImagePath));
byte[] secondImage = Files.readAllBytes(Paths.get(secondImagePath));
// Generate diff image path automatically based on baseline image path
String diffImagePath = baseImagePath.replace(".png", "_present_diff.png");
// Perform feature-based image comparison
FeaturesMatchingResult result = driver.matchImagesFeatures(
baseImage ,
secondImage,
new FeaturesMatchingOptions()
.withDetectorName(FeatureDetector.ORB) // Use SIFT detector
.withGoodMatchesFactor(40) // Adjust match threshold
.withMatchFunc(MatchingFunction.BRUTE_FORCE_HAMMING) // Matching function
.withEnabledVisualization() // Enable visualization
);
System.out.println("result : " + result);
// Assertions
if (result.getCount() > 0) {
Files.write(Paths.get(diffImagePath), result.getVisualization());
System.out.println("Visualization saved at: " + diffImagePath);
System.out.println("Match found! Good matches: " + result.getCount());
return true;
} else {
System.out.println("No match found.");
return false;
}
}catch (Exception e) {
e.printStackTrace();
return false; // Return false if an exception occurs
}
}
Код: Выделить всё
result : io.appium.java_client.imagecomparison.FeaturesMatchingResult@87dfcecc
No match found.
Пример визуализации
Я уже использовал другие методы, такие как «findImageOccurrence» и «getImagesSimilarity», работают правильно, но метод «matchImagesFeatures» у меня не работает.
Я специально хочу использовать «matchImagesFeatures», потому что он более гибкий и может масштабировать и вращать изображения.
Подробнее здесь: https://stackoverflow.com/questions/792 ... oesnt-work
Мобильная версия