Best io.appium code snippet using io.appium.java_client.imagecomparison.FeaturesMatchingResult
ComparesImages.java
Source:ComparesImages.java
...16package io.appium.java_client;17import static io.appium.java_client.MobileCommand.compareImagesCommand;18import io.appium.java_client.imagecomparison.ComparisonMode;19import io.appium.java_client.imagecomparison.FeaturesMatchingOptions;20import io.appium.java_client.imagecomparison.FeaturesMatchingResult;21import io.appium.java_client.imagecomparison.OccurrenceMatchingOptions;22import io.appium.java_client.imagecomparison.OccurrenceMatchingResult;23import io.appium.java_client.imagecomparison.SimilarityMatchingOptions;24import io.appium.java_client.imagecomparison.SimilarityMatchingResult;25import org.apache.commons.codec.binary.Base64;26import org.apache.commons.io.FileUtils;27import java.io.File;28import java.io.IOException;29import java.util.Map;30import javax.annotation.Nullable;31public interface ComparesImages extends ExecutesMethod {32 /**33 * Performs images matching by features with default options. Read34 * https://docs.opencv.org/3.0-beta/doc/py_tutorials/py_feature2d/py_matcher/py_matcher.html35 * for more details on this topic.36 *37 * @param base64image1 base64-encoded representation of the first image38 * @param base64Image2 base64-encoded representation of the second image39 * @return The matching result.40 */41 default FeaturesMatchingResult matchImagesFeatures(byte[] base64image1, byte[] base64Image2) {42 return matchImagesFeatures(base64image1, base64Image2, null);43 }44 /**45 * Performs images matching by features. Read46 * https://docs.opencv.org/3.0-beta/doc/py_tutorials/py_feature2d/py_matcher/py_matcher.html47 * for more details on this topic.48 *49 * @param base64image1 base64-encoded representation of the first image50 * @param base64Image2 base64-encoded representation of the second image51 * @param options comparison options52 * @return The matching result. The configuration of fields in the result depends on comparison options.53 */54 default FeaturesMatchingResult matchImagesFeatures(byte[] base64image1, byte[] base64Image2,55 @Nullable FeaturesMatchingOptions options) {56 Object response = CommandExecutionHelper.execute(this,57 compareImagesCommand(ComparisonMode.MATCH_FEATURES, base64image1, base64Image2, options));58 //noinspection unchecked59 return new FeaturesMatchingResult((Map<String, Object>) response);60 }61 /**62 * Performs images matching by features with default options. Read63 * https://docs.opencv.org/3.0-beta/doc/py_tutorials/py_feature2d/py_matcher/py_matcher.html64 * for more details on this topic.65 *66 * @param image1 The location of the first image67 * @param image2 The location of the second image68 * @return The matching result.69 */70 default FeaturesMatchingResult matchImagesFeatures(File image1, File image2) throws IOException {71 return matchImagesFeatures(image1, image2, null);72 }73 /**74 * Performs images matching by features. Read75 * https://docs.opencv.org/3.0-beta/doc/py_tutorials/py_feature2d/py_matcher/py_matcher.html76 * for more details on this topic.77 *78 * @param image1 The location of the first image79 * @param image2 The location of the second image80 * @param options comparison options81 * @return The matching result. The configuration of fields in the result depends on comparison options.82 */83 default FeaturesMatchingResult matchImagesFeatures(File image1, File image2,84 @Nullable FeaturesMatchingOptions options) throws IOException {85 return matchImagesFeatures(Base64.encodeBase64(FileUtils.readFileToByteArray(image1)),86 Base64.encodeBase64(FileUtils.readFileToByteArray(image2)), options);87 }88 /**89 * Performs images matching by template to find possible occurrence of the partial image90 * in the full image with default options. Read91 * https://docs.opencv.org/2.4/doc/tutorials/imgproc/histograms/template_matching/template_matching.html92 * for more details on this topic.93 *94 * @param fullImage base64-encoded representation of the full image95 * @param partialImage base64-encoded representation of the partial image96 * @return The matching result.97 */...
FeaturesMatchingResult.java
Source:FeaturesMatchingResult.java
...18import org.openqa.selenium.Rectangle;19import java.util.List;20import java.util.Map;21import java.util.stream.Collectors;22public class FeaturesMatchingResult extends ComparisonResult {23 private static final String COUNT = "count";24 private static final String TOTAL_COUNT = "totalCount";25 private static final String POINTS1 = "points1";26 private static final String RECT1 = "rect1";27 private static final String POINTS2 = "points2";28 private static final String RECT2 = "rect2";29 public FeaturesMatchingResult(Map<String, Object> input) {30 super(input);31 }32 /**33 * Returns a count of matched edges on both images.34 *35 * @return The count of matched edges on both images.36 * The more matching edges there are no both images the more similar they are.37 */38 public int getCount() {39 verifyPropertyPresence(COUNT);40 return ((Long) getCommandResult().get(COUNT)).intValue();41 }42 /**43 * Returns a count of matched edges on both images....
ImagesComparisonTest.java
Source:ImagesComparisonTest.java
...20import static org.junit.Assert.assertNotNull;21import static org.junit.Assert.assertThat;22import io.appium.java_client.imagecomparison.FeatureDetector;23import io.appium.java_client.imagecomparison.FeaturesMatchingOptions;24import io.appium.java_client.imagecomparison.FeaturesMatchingResult;25import io.appium.java_client.imagecomparison.MatchingFunction;26import io.appium.java_client.imagecomparison.OccurrenceMatchingOptions;27import io.appium.java_client.imagecomparison.OccurrenceMatchingResult;28import io.appium.java_client.imagecomparison.SimilarityMatchingOptions;29import io.appium.java_client.imagecomparison.SimilarityMatchingResult;30import org.apache.commons.codec.binary.Base64;31import org.junit.Test;32import org.openqa.selenium.OutputType;33public class ImagesComparisonTest extends AppIOSTest {34 @Test35 public void verifyFeaturesMatching() {36 byte[] screenshot = Base64.encodeBase64(driver.getScreenshotAs(OutputType.BYTES));37 FeaturesMatchingResult result = driver38 .matchImagesFeatures(screenshot, screenshot, new FeaturesMatchingOptions()39 .withDetectorName(FeatureDetector.ORB)40 .withGoodMatchesFactor(40)41 .withMatchFunc(MatchingFunction.BRUTE_FORCE_HAMMING)42 .withEnabledVisualization());43 assertThat(result.getVisualization().length, is(greaterThan(0)));44 assertThat(result.getCount(), is(greaterThan(0)));45 assertThat(result.getTotalCount(), is(greaterThan(0)));46 assertFalse(result.getPoints1().isEmpty());47 assertNotNull(result.getRect1());48 assertFalse(result.getPoints2().isEmpty());49 assertNotNull(result.getRect2());50 }51 @Test...
HomePage.java
Source:HomePage.java
...9import io.appium.java_client.AppiumDriver;10import io.appium.java_client.MobileElement;11import io.appium.java_client.imagecomparison.FeatureDetector;12import io.appium.java_client.imagecomparison.FeaturesMatchingOptions;13import io.appium.java_client.imagecomparison.FeaturesMatchingResult;14import io.appium.java_client.imagecomparison.MatchingFunction;15import io.appium.java_client.pagefactory.AndroidFindBy;16import util.ReuseClass;17import util.TakeScreenShotForYou;1819public class HomePage extends BasePage {202122 ReuseClass reuseClass;2324 @AndroidFindBy(accessibility ="Skip")25 private MobileElement skipButton;2627 @AndroidFindBy(className="android.widget.ImageView")28 private MobileElement imageContent;29 30 @AndroidFindBy(id="android:id/content")31 private MobileElement imageContent1;32 3334 @AndroidFindBy(accessibility ="Login")35 private MobileElement loginButton;3637 public HomePage(AppiumDriver<MobileElement> driver) { 38 super(driver);39 }404142 public LoginPage PerformSkip() {4344 try { 45 reuseClass = new ReuseClass();46 if(reuseClass.elementPresent(imageContent, driver)) {47 48 //TakeScreenshot49 //TakeScreenShotForYou.takeScreenshot(driver);50 51 //improve Assert for Comparing image by taking screenshot with current image52 byte[] screenShot= Base64.encodeBase64(driver.getScreenshotAs(OutputType.BYTES));53 String fullpath = new File("src/test/resources/ScreenShots/homePage.jpg").getAbsolutePath();54 55 FeaturesMatchingResult result = driver56 .matchImagesFeatures(screenShot, fullpath.getBytes(), new FeaturesMatchingOptions()57 .withDetectorName(FeatureDetector.ORB)58 .withGoodMatchesFactor(40)59 .withMatchFunc(MatchingFunction.BRUTE_FORCE_HAMMING)60 .withEnabledVisualization());61 Assert.assertEquals(result.getVisualization().length, result.getVisualization().length>0);62 Assert.assertEquals(result.getCount(), result.getCount()>0);63 Assert.assertEquals(result.getTotalCount(), result.getTotalCount()>0);64 Assert.assertFalse(result.getPoints1().isEmpty());65 Assert.assertNotNull(result.getRect1());66 Assert.assertFalse(result.getPoints2().isEmpty());67 Assert.assertNotNull(result.getRect2());68 69 LoginPage loginPage = new LoginPage(driver);
...
ValidUserLoginTest.java
Source:ValidUserLoginTest.java
...10import org.testng.Assert;11import components.BaseClass;12import io.appium.java_client.imagecomparison.FeatureDetector;13import io.appium.java_client.imagecomparison.FeaturesMatchingOptions;14import io.appium.java_client.imagecomparison.FeaturesMatchingResult;15import io.appium.java_client.imagecomparison.MatchingFunction;16import pages.HomePage;17import pages.LoginPage;18import pages.MyProfilePage;1920public class ValidUserLoginTest extends BaseClass {2122 @Test(priority=1)23 public void ValidUserLogin() {2425 try {2627 HomePage homePage = new HomePage(driver); 28 homePage.PerformSkip();
...
InvalidUserLoginTest.java
Source:InvalidUserLoginTest.java
...1213import components.BaseClass;14import io.appium.java_client.imagecomparison.FeatureDetector;15import io.appium.java_client.imagecomparison.FeaturesMatchingOptions;16import io.appium.java_client.imagecomparison.FeaturesMatchingResult;17import io.appium.java_client.imagecomparison.MatchingFunction;18import pages.LoginPage;19import pages.HomePage;2021public class InvalidUserLoginTest extends BaseClass{22 23 @Test24 public void InvalidUserLogin() {25 try {26 27 HomePage homePage = new HomePage(driver);28 homePage.PerformSkip(); 29 30 LoginPage loginPage = new LoginPage(driver);
...
FeaturesMatchingResult
Using AI Code Generation
1package com.appium.tests;2import java.net.MalformedURLException;3import java.net.URL;4import org.openqa.selenium.By;5import org.openqa.selenium.WebElement;6import org.openqa.selenium.remote.DesiredCapabilities;7import io.appium.java_client.android.AndroidDriver;8import io.appium.java_client.imagecomparison.FeaturesMatchingResult;9import io.appium.java_client.imagecomparison.OccurrenceMatchingOptions;10import io.appium.java_client.imagecomparison.OccurrenceMatchingResult;11public class ImageComparison {12 public static void main(String[] args) throws MalformedURLException, InterruptedException {13 DesiredCapabilities caps = new DesiredCapabilities();14 caps.setCapability("deviceName", "Nexus 6 API 28");15 caps.setCapability("platformName", "Android");16 caps.setCapability("automationName", "UiAutomator2");17 caps.setCapability("appPackage", "com.android.calculator2");18 caps.setCapability("appActivity", "com.android.calculator2.Calculator");19 caps.setCapability("noReset", true);
FeaturesMatchingResult
Using AI Code Generation
1package com.appium.tests;2import java.io.File;3import java.net.MalformedURLException;4import java.net.URL;5import java.util.concurrent.TimeUnit;6import org.openqa.selenium.remote.DesiredCapabilities;7import io.appium.java_client.android.AndroidDriver;8import io.appium.java_client.imagecomparison.FeaturesMatchingResult;9import io.appium.java_client.imagecomparison.ImageComparisonFeature;10import io.appium.java_client.imagecomparison.ImageComparisonMode;11public class ImageComparison {12 public static void main(String[] args) throws MalformedURLException, InterruptedException {13 DesiredCapabilities cap = new DesiredCapabilities();14 cap.setCapability("deviceName", "Android");15 cap.setCapability("platformName", "Android");16 cap.setCapability("platformVersion", "7.0");17 cap.setCapability("appPackage", "com.android.settings");18 cap.setCapability("appActivity", "com.android.settings.Settings");19 cap.setCapability("noReset", true);
FeaturesMatchingResult
Using AI Code Generation
1import io.appium.java_client.imagecomparison.FeaturesMatchingResult;2import io.appium.java_client.imagecomparison.FeatureMatchingAlgorithm;3import io.appium.java_client.imagecomparison.ImageComparison;4import io.appium.java_client.imagecomparison.ImageComparisonFeature;5import io.appium.java_client.imagecomparison.ImageComparisonMode;6import io.appium.java_client.imagecomparison.ImageMatchingOptions;7import io.appium.java_client.imagecomparison.MatchResult;8import io.appium.java_client.imagecomparison.OccurrenceMatchingOptions;9import io.appium.java_client.imagecomparison.OccurrenceMatchingResult;10import io.appium.java_client.imagecomparison.VisualLocatorSettings;11import io.appium.java_client.imagecomparison.VisualLocatorStrategy;12import io.appium.java_client.imagecomparison.OccurrenceMatchingOptions;13import io.appium.java_client.imagecomparison.OccurrenceMatchingResult;14import io.appium.java_client.imagecomparison.VisualLocatorSettings;15import io.appium.java_client.imagecomparison.VisualLocatorStrategy;16import io.appium.java_client.imagecomparison.OccurrenceMatchingOptions;17import io.appium.java_client.imagecomparison.OccurrenceMatchingResult;18import io.appium.java_client.imagecomparison.VisualLocatorSettings;19import io.appium.java_client.imagecomparison.VisualLocatorStrategy;20import io.appium.java_client.imagecomparison.OccurrenceMatchingOptions;21import io.appium.java_client.imagecomparison.OccurrenceMatchingResult;22import io.appium.java_client.imagecomparison.VisualLocatorSettings;23import io.appium.java_client.imagecomparison.VisualLocatorStrategy;24import io.appium.java_client.imagecomparison.OccurrenceMatchingOptions;25import io.appium.java_client.imagecomparison.OccurrenceMatchingResult;26import io.appium.java_client.imagecomparison.VisualLocatorSettings;27import io.appium.java_client.imagecomparison.VisualLocatorStrategy;28import io.appium.java_client.imagecomparison.OccurrenceMatchingOptions;29import io.appium.java_client.imagecomparison.OccurrenceMatchingResult;30import io.appium.java_client.imagecomparison.VisualLocatorSettings;31import io.appium.java_client.imagecomparison.VisualLocatorStrategy;32import io.appium.java_client.imagecomparison.OccurrenceMatchingOptions;33import io.appium.java_client.imagecomparison.OccurrenceMatchingResult;34import io.appium.java_client.imagecomparison.VisualLocatorSettings;35import io.appium.java_client.imagecomparison.VisualLocatorStrategy;36import io.appium.java_client.imagecomparison.OccurrenceMatchingOptions;37import io.appium.java_client.imagecomparison.OccurrenceMatchingResult;38import io.appium.java_client.imagecomparison.VisualLocatorSettings;39import io.appium.java_client.imagecomparison.VisualLocatorStrategy;
FeaturesMatchingResult
Using AI Code Generation
1File file1 = new File("C:\\Users\\Downloads\\image1.png");2 File file2 = new File("C:\\Users\\Downloads\\image2.png");3 FeaturesMatchingResult featuresMatchingResult = driver.getImagesSimilarity(file1, file2);4 System.out.println(featuresMatchingResult.getSimilarity());5File file1 = new File("C:\\Users\\Downloads\\image1.png");6 File file2 = new File("C:\\Users\\Downloads\\image2.png");7 FeaturesMatchingResults featuresMatchingResults = driver.getImagesSimilarity(file1, file2);8 System.out.println(featuresMatchingResults.getSimilarity());9File file1 = new File("C:\\Users\\Downloads\\image1.png");10 File file2 = new File("C:\\Users\\Downloads\\image2.png");11 ImageComparisonResult imageComparisonResult = driver.getImagesSimilarity(file1, file2);12 System.out.println(imageComparisonResult.getSimilarity());13File file1 = new File("C:\\Users\\Downloads\\image1.png");14 File file2 = new File("C:\\Users\\Downloads\\image2.png");15 ImageComparisonResults imageComparisonResults = driver.getImagesSimilarity(file1, file2);16 System.out.println(imageComparisonResults.getSimilarity());17File file1 = new File("C:\\Users\\Downloads\\image1.png");18 File file2 = new File("C:\\Users\\Downloads\\image2.png");19 ImageElement imageElement = driver.getImagesSimilarity(file1, file2);20 System.out.println(imageElement.getSimilarity());21File file1 = new File("C:\\Users\\Downloads\\image1.png");22 File file2 = new File("C:\\Users\\Downloads\\image2.png");23 ImageMatchingResult imageMatchingResult = driver.getImagesSimilarity(file1, file
FeaturesMatchingResult
Using AI Code Generation
1import io.appium.java_client.imagecomparison.FeaturesMatchingResult;2import io.appium.java_client.imagecomparison.OccurrenceMatchingOptions;3import io.appium.java_client.imagecomparison.OccurrenceMatchingResult;4import io.appium.java_client.imagecomparison.OccurrenceMatchingResults;5import io.appium.java_client.imagecomparison.TemplateImage;6import io.appium.java_client.imagecomparison.TemplateMatchingOptions;7import io.appium.java_client.imagecomparison.TemplateMatchingResult;8import io.appium.java_client.imagecomparison.TemplateMatchingResults;9import io.appium.java_client.imagecomparison.OccurrenceMatchingOptions.OccurrenceFingerprint;10import io.appium.java_client.imagecomparison.OccurrenceMatchingOptions.OccurrenceOrdering;11import io.appium.java_client.imagecomparison.OccurrenceMatchingOptions.OccurrencePoint;12import io.appium.java_client.imagecomparison.OccurrenceMatchingOptions.OccurrenceRotation;13import io.appium.java_client.imagecomparison.OccurrenceMatchingOptions.OccurrenceScale;14import io.appium.java_client.imagecomparison.OccurrenceMatchingOptions.OccurrenceThreshold;15import io.appium.java_client.imagecomparison.TemplateMatchingOptions.TemplateFingerprint;16import io.appium.java_client.imagecomparison.TemplateMatchingOptions.TemplateMatchingMode;17import io.appium.java_client.imagecomparison.TemplateMatchingOptions.TemplateOrdering;18import io.appium.java_client.imagecomparison.TemplateMatchingOptions.TemplatePoint;19import io.appium.java_client.imagecomparison.TemplateMatchingOptions.TemplateRotation;20import io.appium.java_client.imagecomparison.TemplateMatchingOptions.TemplateScale;21import io.appium.java_client.imagecomparison.TemplateMatchingOptions.TemplateThreshold;22import io.appium.java_client.imagecomparison.TemplateMatchingResults.TemplateMatchingResult;23import org.openqa.selenium.By;24import org.openqa.selenium.Dimension;25import org.openqa.selenium.WebElement;26import org.openqa.selenium.remote.DesiredCapabilities;27import org.testng.Assert;28import org.testng.annotations.AfterTest;29import org.testng.annotations.BeforeTest;30import org.testng.annotations.Test;31import io.appium.java_client.MobileElement;32import io.appium.java_client.android.AndroidDriver;33import io.appium.java_client.android.AndroidElement;34import io.appium.java_client.android.AndroidKeyCode;35import io.appium.java_client.android.connection.ConnectionState;36import io.appium.java_client.android.connection.ConnectionStateBuilder;37import io.appium.java_client.android.nativekey.AndroidKey;38import io.appium.java_client.android.nativekey.KeyEvent;39import io.appium.java_client.android.nativekey.Presses
FeaturesMatchingResult
Using AI Code Generation
1MobileElement element = driver.findElementByAccessibilityId("test-Compare");2driver.context("NATIVE_APP");3File file = new File("C:\\Users\\test\\Desktop\\test.png");4FeaturesMatchingResult result = ((FindsByImage) driver).findElementByImage(file);5System.out.println(result.getScore());6MobileElement element = driver.findElementByAccessibilityId("test-Compare");7driver.context("NATIVE_APP");8File file = new File("C:\\Users\\test\\Desktop\\test.png");9ImageComparisonHelper helper = new ImageComparisonHelper(driver);10FeaturesMatchingResult result = helper.getFeatureMatchingResult(element, file);11System.out.println(result.getScore());12MobileElement element = driver.findElementByAccessibilityId("test-Compare");13driver.context("NATIVE_APP");14File file = new File("C:\\Users\\test\\Desktop\\test.png");15VisualTestHelper helper = new VisualTestHelper(driver);16FeaturesMatchingResult result = helper.getFeatureMatchingResult(element, file);17System.out.println(result.getScore());18MobileElement element = driver.findElementByAccessibilityId("test-Compare");19driver.context("NATIVE_APP");20File file = new File("C:\\Users\\test\\Desktop\\test.png");21ImageElement imageElement = new ImageElement(element, file);22ImageComparisonHelper helper = new ImageComparisonHelper(driver);23FeaturesMatchingResult result = helper.getFeatureMatchingResult(imageElement);24System.out.println(result.getScore());25MobileElement element = driver.findElementByAccessibilityId("test-Compare");26driver.context("NATIVE_APP");27File file = new File("C:\\Users\\test\\Desktop\\test.png");28ImageElement imageElement = new ImageElement(element, file);29VisualTestHelper helper = new VisualTestHelper(driver);30FeaturesMatchingResult result = helper.getFeatureMatchingResult(imageElement);31System.out.println(result.getScore());32MobileElement element = driver.findElementByAccessibilityId("
FeaturesMatchingResult
Using AI Code Generation
1import io.appium.java_client.imagecomparison.FeaturesMatchingResult;2public class Appium {3 public static void main(String[] args) throws Exception {4 FeaturesMatchingResult featuresMatchingResult = imageComparison.getBestMatchingFeatures();5 System.out.println(featuresMatchingResult.getMatchPercentage());6 System.out.println(featuresMatchingResult.getMatchedFeatures());7 }8}9from appium.webdriver.common.image_comparison import FeaturesMatchingResult10def test_features_matching_result():11 features_matching_result = self.driver.get_best_matching_features()12 print(features_matching_result.match_percentage)13 print(features_matching_result.matched_features)14const {FeaturesMatchingResult} = require('appium-support');15async function testFeaturesMatchingResult() {16 let featuresMatchingResult = await driver.getBestMatchingFeatures();17 console.log(featuresMatchingResult.matchPercentage);18 console.log(featuresMatchingResult.matchedFeatures);19}20use Appium\Appium\WebDriver\Remote\RemoteImageComparison;21use Appium\Appium\WebDriver\Remote\RemoteWebDriver;22{23 public function testFeaturesMatchingResult()24 {
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!