How to use findImageOccurrence method of io.appium.java_client.ComparesImages class

Best io.appium code snippet using io.appium.java_client.ComparesImages.findImageOccurrence

pureDrivers.java

Source:pureDrivers.java Github

copy

Full Screen

...1590 "matchImagesFeatures", myClasses, currentDriver.mainDriver.getClass().toString(), myTrueParam );1591 }1592 1593 // ********************************************************************************************************************************************************1594 // AndroidDriver [109] = public default io.appium.java_client.imagecomparison.OccurrenceMatchingResult io.appium.java_client.ComparesImages.findImageOccurrence(java.io.File ,java.io.File ) throws java.io.IOException1595 public io.appium.java_client.imagecomparison.OccurrenceMatchingResult findImageOccurrence( java.io.File image1, java.io.File image2 ) throws java.io.IOException {1596 pureDriverDetails currentDriver = getCurrentDriverDetails();1597 Class<?>[] myClasses = new Class[2];1598 myClasses[ 0 ] = java.io.File.class;1599 myClasses[ 1 ] = java.io.File.class;1600 Object[] myTrueParam = new Object[2];1601 myTrueParam[ 0 ] = (Object)image1;1602 myTrueParam[ 1 ] = (Object)image2;1603 return (io.appium.java_client.imagecomparison.OccurrenceMatchingResult)pureCore.callMethod( currentDriver.mainDriver, currentDriver.mainDriver.getClass(),1604 "findImageOccurrence", myClasses, currentDriver.mainDriver.getClass().toString(), myTrueParam );1605 }1606 1607 // ********************************************************************************************************************************************************1608 // AndroidDriver [110] = public default io.appium.java_client.imagecomparison.OccurrenceMatchingResult io.appium.java_client.ComparesImages.findImageOccurrence(java.io.File, java.io.File, io.appium.java_client.imagecomparison.OccurrenceMatchingOptions ) throws java.io.IOException1609 public io.appium.java_client.imagecomparison.OccurrenceMatchingResult findImageOccurrence( java.io.File image1, java.io.File image2, io.appium.java_client.imagecomparison.OccurrenceMatchingOptions fileOptions ) throws java.io.IOException {1610 pureDriverDetails currentDriver = getCurrentDriverDetails();1611 Class<?>[] myClasses = new Class[2];1612 myClasses[ 0 ] = java.io.File.class;1613 myClasses[ 1 ] = java.io.File.class;1614 myClasses[ 2 ] = io.appium.java_client.imagecomparison.OccurrenceMatchingOptions.class;1615 Object[] myTrueParam = new Object[2];1616 myTrueParam[ 0 ] = (Object)image1;1617 myTrueParam[ 1 ] = (Object)image2;1618 myTrueParam[ 2 ] = (Object)fileOptions;1619 return (io.appium.java_client.imagecomparison.OccurrenceMatchingResult)pureCore.callMethod( currentDriver.mainDriver, currentDriver.mainDriver.getClass(),1620 "findImageOccurrence", myClasses, currentDriver.mainDriver.getClass().toString(), myTrueParam );1621 }1622 1623 // ********************************************************************************************************************************************************1624 // AndroidDriver [111] = public default io.appium.java_client.imagecomparison.OccurrenceMatchingResult io.appium.java_client.ComparesImages.findImageOccurrence(byte[] ,byte[], io.appium.java_client.imagecomparison.OccurrenceMatchingOptions )1625 public io.appium.java_client.imagecomparison.OccurrenceMatchingResult findImageOccurrence( byte[] base64image1, byte[] base64image2, io.appium.java_client.imagecomparison.OccurrenceMatchingOptions fileOptions ){1626 pureDriverDetails currentDriver = getCurrentDriverDetails();1627 Class<?>[] myClasses = new Class[3];1628 myClasses[ 0 ] = byte[].class;1629 myClasses[ 1 ] = byte[].class;1630 myClasses[ 2 ] = io.appium.java_client.imagecomparison.OccurrenceMatchingOptions.class;1631 Object[] myTrueParam = new Object[3];1632 myTrueParam[ 0 ] = (Object)base64image1;1633 myTrueParam[ 1 ] = (Object)base64image2;1634 myTrueParam[ 2 ] = (Object)fileOptions;1635 return (io.appium.java_client.imagecomparison.OccurrenceMatchingResult)pureCore.callMethod( currentDriver.mainDriver, currentDriver.mainDriver.getClass(),1636 "findImageOccurrence", myClasses, currentDriver.mainDriver.getClass().toString(), myTrueParam );1637 }1638 1639 // ********************************************************************************************************************************************************1640 // AndroidDriver [112] = public default io.appium.java_client.imagecomparison.OccurrenceMatchingResult io.appium.java_client.ComparesImages.findImageOccurrence(byte[], byte[] )1641 public io.appium.java_client.imagecomparison.OccurrenceMatchingResult findImageOccurrence( byte[] base64image1, byte[] base64image2 ){1642 pureDriverDetails currentDriver = getCurrentDriverDetails();1643 Class<?>[] myClasses = new Class[2];1644 myClasses[ 0 ] = byte[].class;1645 myClasses[ 1 ] = byte[].class;1646 Object[] myTrueParam = new Object[2];1647 myTrueParam[ 0 ] = (Object)base64image1;1648 myTrueParam[ 1 ] = (Object)base64image2;1649 return (io.appium.java_client.imagecomparison.OccurrenceMatchingResult)pureCore.callMethod( currentDriver.mainDriver, currentDriver.mainDriver.getClass(),1650 "findImageOccurrence", myClasses, currentDriver.mainDriver.getClass().toString(), myTrueParam );1651 }1652 1653 // ********************************************************************************************************************************************************1654 // AndroidDriver [113] = public default io.appium.java_client.imagecomparison.SimilarityMatchingResult io.appium.java_client.ComparesImages.getImagesSimilarity(java.io.File, java.io.File ) throws java.io.IOException1655 1656 // ********************************************************************************************************************************************************1657 // AndroidDriver [114] = public default io.appium.java_client.imagecomparison.SimilarityMatchingResult io.appium.java_client.ComparesImages.getImagesSimilarity(java.io.File, java.io.File, io.appium.java_client.imagecomparison.SimilarityMatchingOptions ) throws java.io.IOException1658 1659 // ********************************************************************************************************************************************************1660 // AndroidDriver [115] = public default io.appium.java_client.imagecomparison.SimilarityMatchingResult io.appium.java_client.ComparesImages.getImagesSimilarity(byte[], byte[], io.appium.java_client.imagecomparison.SimilarityMatchingOptions )1661 1662 // ********************************************************************************************************************************************************1663 // AndroidDriver [116] = public default io.appium.java_client.imagecomparison.SimilarityMatchingResult io.appium.java_client.ComparesImages.getImagesSimilarity(byte[], byte[] )1664 ...

Full Screen

Full Screen

ComparesImages.java

Source:ComparesImages.java Github

copy

Full Screen

...94 * @param fullImage base64-encoded representation of the full image95 * @param partialImage base64-encoded representation of the partial image96 * @return The matching result.97 */98 default OccurrenceMatchingResult findImageOccurrence(byte[] fullImage, byte[] partialImage) {99 return findImageOccurrence(fullImage, partialImage, null);100 }101 /**102 * Performs images matching by template to find possible occurrence of the partial image103 * in the full image. Read104 * https://docs.opencv.org/2.4/doc/tutorials/imgproc/histograms/template_matching/template_matching.html105 * for more details on this topic.106 *107 * @param fullImage base64-encoded representation of the full image108 * @param partialImage base64-encoded representation of the partial image109 * @param options comparison options110 * @return The matching result. The configuration of fields in the result depends on comparison options.111 */112 default OccurrenceMatchingResult findImageOccurrence(byte[] fullImage, byte[] partialImage,113 @Nullable OccurrenceMatchingOptions options) {114 Object response = CommandExecutionHelper.execute(this,115 compareImagesCommand(ComparisonMode.MATCH_TEMPLATE, fullImage, partialImage, options));116 //noinspection unchecked117 return new OccurrenceMatchingResult((Map<String, Object>) response);118 }119 /**120 * Performs images matching by template to find possible occurrence of the partial image121 * in the full image with default options. Read122 * https://docs.opencv.org/2.4/doc/tutorials/imgproc/histograms/template_matching/template_matching.html123 * for more details on this topic.124 *125 * @param fullImage The location of the full image126 * @param partialImage The location of the partial image127 * @return The matching result. The configuration of fields in the result depends on comparison options.128 */129 default OccurrenceMatchingResult findImageOccurrence(File fullImage, File partialImage) throws IOException {130 return findImageOccurrence(fullImage, partialImage, null);131 }132 /**133 * Performs images matching by template to find possible occurrence of the partial image134 * in the full image. Read135 * https://docs.opencv.org/2.4/doc/tutorials/imgproc/histograms/template_matching/template_matching.html136 * for more details on this topic.137 *138 * @param fullImage The location of the full image139 * @param partialImage The location of the partial image140 * @param options comparison options141 * @return The matching result. The configuration of fields in the result depends on comparison options.142 */143 default OccurrenceMatchingResult findImageOccurrence(File fullImage, File partialImage,144 @Nullable OccurrenceMatchingOptions options)145 throws IOException {146 return findImageOccurrence(Base64.encodeBase64(FileUtils.readFileToByteArray(fullImage)),147 Base64.encodeBase64(FileUtils.readFileToByteArray(partialImage)), options);148 }149 /**150 * Performs images matching to calculate the similarity score between them151 * with default options. The flow there is similar to the one used in152 * {@link #findImageOccurrence(byte[], byte[], OccurrenceMatchingOptions)},153 * but it is mandatory that both images are of equal size.154 *155 * @param base64image1 base64-encoded representation of the first image156 * @param base64Image2 base64-encoded representation of the second image157 * @return Matching result. The configuration of fields in the result depends on comparison options.158 */159 default SimilarityMatchingResult getImagesSimilarity(byte[] base64image1, byte[] base64Image2) {160 return getImagesSimilarity(base64image1, base64Image2, null);161 }162 /**163 * Performs images matching to calculate the similarity score between them.164 * The flow there is similar to the one used in165 * {@link #findImageOccurrence(byte[], byte[], OccurrenceMatchingOptions)},166 * but it is mandatory that both images are of equal size.167 *168 * @param base64image1 base64-encoded representation of the first image169 * @param base64Image2 base64-encoded representation of the second image170 * @param options comparison options171 * @return Matching result. The configuration of fields in the result depends on comparison options.172 */173 default SimilarityMatchingResult getImagesSimilarity(byte[] base64image1, byte[] base64Image2,174 @Nullable SimilarityMatchingOptions options) {175 Object response = CommandExecutionHelper.execute(this,176 compareImagesCommand(ComparisonMode.GET_SIMILARITY, base64image1, base64Image2, options));177 //noinspection unchecked178 return new SimilarityMatchingResult((Map<String, Object>) response);179 }180 /**181 * Performs images matching to calculate the similarity score between them182 * with default options. The flow there is similar to the one used in183 * {@link #findImageOccurrence(byte[], byte[], OccurrenceMatchingOptions)},184 * but it is mandatory that both images are of equal size.185 *186 * @param image1 The location of the full image187 * @param image2 The location of the partial image188 * @return Matching result. The configuration of fields in the result depends on comparison options.189 */190 default SimilarityMatchingResult getImagesSimilarity(File image1, File image2) throws IOException {191 return getImagesSimilarity(image1, image2, null);192 }193 /**194 * Performs images matching to calculate the similarity score between them.195 * The flow there is similar to the one used in196 * {@link #findImageOccurrence(byte[], byte[], OccurrenceMatchingOptions)},197 * but it is mandatory that both images are of equal size.198 *199 * @param image1 The location of the full image200 * @param image2 The location of the partial image201 * @param options comparison options202 * @return Matching result. The configuration of fields in the result depends on comparison options.203 */204 default SimilarityMatchingResult getImagesSimilarity(File image1, File image2,205 @Nullable SimilarityMatchingOptions options)206 throws IOException {207 return getImagesSimilarity(Base64.encodeBase64(FileUtils.readFileToByteArray(image1)),208 Base64.encodeBase64(FileUtils.readFileToByteArray(image2)), options);209 }210}...

Full Screen

Full Screen

findImageOccurrence

Using AI Code Generation

copy

Full Screen

1package appium;2import org.openqa.selenium.By;3import org.openqa.selenium.WebElement;4import org.openqa.selenium.remote.DesiredCapabilities;5import org.testng.annotations.AfterTest;6import org.testng.annotations.BeforeTest;7import org.testng.annotations.Test;8import io.appium.java_client.AppiumDriver;9import io.appium.java_client.MobileElement;10import io.appium.java_client.android.AndroidDriver;11import io.appium.java_client.android.AndroidElement;12import io.appium.java_client.android.nativekey.AndroidKey;13import io.appium.java_client.android.nativekey.KeyEvent;14import io.appium.java_client.remote.MobileCapabilityType;15import io.appium.java_client.service.local.AppiumDriverLocalService;16import io.appium.java_client.service.local.AppiumServiceBuilder;17import io.appium.java_client.service.local.flags.GeneralServerFlag;18import java.io.File;19import java.net.MalformedURLException;20import java.net.URL;21import java.util.List;22import java.util.concurrent.TimeUnit;23public class FindImageOccurence {24AppiumDriver<MobileElement> driver;25public void setup() throws MalformedURLException {26AppiumDriverLocalService service = AppiumDriverLocalService.buildService(new AppiumServiceBuilder().usingDriverExecutable(new File("C:/Program Files (x86)/Appium/node.exe")).withAppiumJS(new File("C:/Program Files (x86)/Appium/node_modules/appium/bin/appium.js")).withIPAddress("

Full Screen

Full Screen

findImageOccurrence

Using AI Code Generation

copy

Full Screen

1import java.io.File;2import java.util.List;3import org.openqa.selenium.WebElement;4import org.testng.Assert;5import org.testng.annotations.Test;6import io.appium.java_client.AppiumDriver;7import io.appium.java_client.MobileElement;8import io.appium.java_client.android.AndroidDriver;9import io.appium.java_client.ios.IOSDriver;10import io.appium.java_client.remote.MobileCapabilityType;11import io.appium.java_client.service.local.AppiumDriverLocalService;12import io.appium.java_client.service.local.AppiumServiceBuilder;13import io.appium.java_client.service.local.flags.GeneralServerFlag;14import io.appium.java_client.service.local.flags.ServerArgument;15import io.appium.java_client.service.local.flags.ServerFlag;16import io.appium.java_client.service.local.flags.ServerArgument;17import io.appium.java_client.service.local.flags.ServerFlag;18public class FindImageOccurrence {19 public void findImageOccurrence() throws Exception {

Full Screen

Full Screen

findImageOccurrence

Using AI Code Generation

copy

Full Screen

1package appium;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.AppiumDriver;8import io.appium.java_client.MobileElement;9import io.appium.java_client.android.AndroidDriver;10import io.appium.java_client.android.AndroidElement;11import io.appium.java_client.ios.IOSDriver;12import io.appium.java_client.ios.IOSElement;13public class findImageOccurrence {14 public static AppiumDriver<MobileElement> driver;15 public static void main(String[] args) throws MalformedURLException {16 DesiredCapabilities caps = new DesiredCapabilities();17 caps.setCapability("deviceName", "Pixel 4 API 30");18 caps.setCapability("platformName", "Android");19 caps.setCapability("platformVersion", "11.0");20 caps.setCapability("skipUnlock", "true");21 caps.setCapability("appPackage", "com.android.chrome");22 caps.setCapability("appActivity", "com.google.android.apps.chrome.Main");23 caps.setCapability("noReset", "true");

Full Screen

Full Screen

findImageOccurrence

Using AI Code Generation

copy

Full Screen

1import io.appium.java_client.ComparesImages;2import io.appium.java_client.MobileElement;3import org.openqa.selenium.By;4import org.openqa.selenium.WebElement;5import java.io.File;6import java.util.List;7import java.util.Map;8import java.util.concurrent.TimeUnit;9import java.util.stream.Collectors;10public class FindImageOccurrence extends BaseTest {11 public void findImageOccurrenceTest() throws Exception {12 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);13 WebElement searchBox = driver.findElement(By.id("search_box"));14 searchBox.click();15 WebElement searchInput = driver.findElement(By.id("search_input_text"));16 searchInput.sendKeys("Appium");17 driver.findElement(By.id("search_input_text")).click();18 WebElement searchResult = driver.findElement(By.id("page_list_item_title"));19 searchResult.click();20 WebElement imageView = driver.findElement(By.id("page_image"));21 File image = new File("appium.png");22 List<MobileElement> results = ((ComparesImages) driver).findImageOccurrence(imageView, image);23 Map<String, MobileElement> elements = results.stream().collect(Collectors.toMap(MobileElement::getText, e -> e));24 Assert.assertTrue(elements.get("Appium").isDisplayed());25 }26}27import io.appium.java_client.ComparesImages;28import io.appium.java_client.MobileElement;29import io.appium.java_client.android.AndroidDriver;30import io.appium.java_client.android.AndroidElement;31import org.junit.Test;32import org.openqa.selenium.By;33import org.openqa.selenium.WebElement;34import java.io.File;35import java.util.List;36import java.util.Map;37import java.util.concurrent.TimeUnit;38import java.util.stream.Collectors;39public class AndroidDriverTest extends BaseAndroidTest {40 public void findImageOccurrenceTest() throws Exception {41 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);42 WebElement searchBox = driver.findElement(By.id("search_box"));43 searchBox.click();44 WebElement searchInput = driver.findElement(By.id("search_input_text"));45 searchInput.sendKeys("Appium");46 driver.findElement(By.id("search_input_text")).click();47 WebElement searchResult = driver.findElement(By.id("page_list_item_title"));48 searchResult.click();

Full Screen

Full Screen

findImageOccurrence

Using AI Code Generation

copy

Full Screen

1package appium.java;2import java.io.File;3import java.io.IOException;4import java.net.URL;5import java.util.List;6import org.openqa.selenium.remote.DesiredCapabilities;7import io.appium.java_client.MobileElement;8import io.appium.java_client.android.AndroidDriver;9import io.appium.java_client.android.AndroidElement;10import io.appium.java_client.android.compatability.AndroidMobileCommandHelper;11import io.appium.java_client.android.compatability.MobileCommand;12import io.appium.java_client.android.compatability.MobileCommandHelper;13import io.appium.java_client.android.compatability.MobileCommandType;14import io.appium.java_client.android.compatability.MobileCommandHelper.MobileCommandHelperAndroid;15import io.appium.java_client.android.compatability.MobileCommandType.MobileCommandTypeAndroid;16import io.appium.java_client.android.compatability.MobileCommandType.MobileCommandTypeIOS;17import io.appium.java_client.android.compatability.MobileCommandHelper.MobileCommandHelperIOS;18import io.appium.java_client.android.compatability.MobileCommandHelper.MobileCommandHelperIOS;19import io.appium.java_client.android.compatability.MobileCommandHelper.MobileCommandHelperIOS;20public class AppiumJava {21public static void main(String[] args) throws IOException {22DesiredCapabilities caps = new DesiredCapabilities();23caps.setCapability("deviceName", "Pixel 2 API 26");24caps.setCapability("platformName", "Android");25caps.setCapability("platformVersion", "8.0");26caps.setCapability("appPackage", "com.android.settings");27caps.setCapability("appActivity", ".Settings");28caps.setCapability("noReset", "true");

Full Screen

Full Screen

findImageOccurrence

Using AI Code Generation

copy

Full Screen

1package appium;2import java.io.File;3import java.net.MalformedURLException;4import java.net.URL;5import java.util.List;6import org.openqa.selenium.remote.DesiredCapabilities;7import io.appium.java_client.AppiumDriver;8import io.appium.java_client.MobileElement;9import io.appium.java_client.android.AndroidDriver;10import io.appium.java_client.android.AndroidElement;11import io.appium.java_client.android.nativekey.AndroidKey;12import io.appium.java_client.android.nativekey.KeyEvent;13public class findImageOccurrence {14 public static AppiumDriver<MobileElement> driver;15 public static void main(String[] args) throws MalformedURLException, InterruptedException {16 DesiredCapabilities cap = new DesiredCapabilities();17 cap.setCapability("deviceName", "Android Emulator");18 cap.setCapability("udid", "emulator-5554");19 cap.setCapability("platformName", "Android");20 cap.setCapability("platformVersion", "11");21 cap.setCapability("appPackage", "com.android.chrome");22 cap.setCapability("appActivity", "com.google.android.apps.chrome.Main");23 cap.setCapability("noReset", "true");

Full Screen

Full Screen

findImageOccurrence

Using AI Code Generation

copy

Full Screen

1File file = new File("/Users/username/Downloads/IMG_0090.PNG");2File file1 = new File("/Users/username/Downloads/IMG_0090.PNG");3Dimension dimension = new Dimension(100, 100);4List<Match> matchList = driver.findImageOccurrence(file, file1, dimension);5System.out.println(matchList.size());6dimension = (100, 100)7match_list = driver.find_image_occurrence(file, file1, dimension)8print(len(match_list))9dimension = (100, 100)10match_list = driver.findImageOccurrence(file, file1, dimension)11console.log(match_list.length)12match_list = driver.find_image_occurrence(file, file1, dimension)13match_list = driver.findImageOccurrence(file, file1, dimension)14console.log(match_list.length)15string file = "/Users/username/Downloads/IMG_0090.PNG";16string file1 = "/Users/username/Downloads/IMG_0090.PNG";17Dimension dimension = new Dimension(100, 100);18List<Match> matchList = driver.FindImageOccurrence(file

Full Screen

Full Screen

findImageOccurrence

Using AI Code Generation

copy

Full Screen

1import java.util.List;2import java.awt.Point;3import io.appium.java_client.ComparesImages;4ComparesImages compare = (ComparesImages) driver;5List<Point> list = compare.findImageOccurrence("C:\\Users\\username\\Desktop\\image.png", 0.9);6System.out.println(list);7driver = AppiumDriver()8list = driver.find_image_occurrence("C:\\Users\\username\\Desktop\\image.png", 0.9)9print(list)10list = driver.find_image_occurrence("C:\\Users\\username\\Desktop\\image.png", 0.9)

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run io.appium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful