Best io.appium code snippet using io.appium.java_client.imagecomparison.OccurrenceMatchingResult
ComparesImages.java
Source:ComparesImages.java
...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 */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....
TestMobileApp.java
Source:TestMobileApp.java
1package jp.shiftinc.automation.trial;2import io.appium.java_client.AppiumDriver;3import io.appium.java_client.MobileElement;4import io.appium.java_client.imagecomparison.OccurrenceMatchingOptions;5import io.appium.java_client.imagecomparison.OccurrenceMatchingResult;6import io.appium.java_client.ios.IOSStartScreenRecordingOptions;7import io.appium.java_client.screenrecording.CanRecordScreen;8import io.qameta.allure.Allure;9import io.qameta.allure.Attachment;10import io.qameta.allure.Feature;11import io.qameta.allure.Step;12import org.junit.jupiter.api.AfterEach;13import org.junit.jupiter.api.BeforeAll;14import org.junit.jupiter.api.TestInstance;15import org.junit.jupiter.params.ParameterizedTest;16import org.junit.jupiter.params.provider.Arguments;17import org.junit.jupiter.params.provider.MethodSource;18import org.openqa.selenium.OutputType;19import org.openqa.selenium.WebElement;20import javax.imageio.ImageIO;21import java.awt.image.BufferedImage;22import java.io.ByteArrayInputStream;23import java.io.ByteArrayOutputStream;24import java.io.File;25import java.io.IOException;26import java.nio.file.Files;27import java.nio.file.Paths;28import java.util.Base64;29import java.util.concurrent.TimeUnit;30import java.util.stream.Stream;31import static org.junit.jupiter.api.Assertions.assertNotNull;32import static org.junit.jupiter.params.provider.Arguments.arguments;33@SuppressWarnings({"SameParameterValue", "FieldCanBeLocal"})34@Feature("Appiumã¤ã¡ã¼ã¸ã»ã¬ã¯ã¿ãã¹ã")35@TestInstance(TestInstance.Lifecycle.PER_CLASS)36class TestMobileApp {37 private AppiumDriver driver;38 private OSBase osInfo;39 @BeforeAll40 void setupClass() {41 }42 @Step("{osName}ï¼ã¤ã¡ã¼ã¸ã»ã¬ã¯ã¿ã§ãã°ã¤ã³")43 @ParameterizedTest44 @MethodSource("osMartix")45 void imageSelectorTest(String osName) throws IOException, InterruptedException {46 setup(osName);47 // ã¤ã¡ã¼ã¸ã»ã¬ã¯ã¿48 WebElement loginElm = driver.findElementByImage(getReferenceImageB64("racine_sut_login.png"));49 // visualization50 String imageResult = loginElm.getAttribute("visual");51 // Allureã«ã¢ã¿ãã(ãµã¼ãã¹é¢æ°çµç±ï¼52 addAttachment(Base64.getDecoder().decode(imageResult), "image-selector");53 loginElm.click();54 Thread.sleep(20000);55 //addAttachment(driver.getScreenshotAs(OutputType.BYTES),"img1");56 // ãã³ãã¬ã¼ããããã³ã°57 OccurrenceMatchingResult result = templateMatch("original_template.png");58 // Allureã«ã¢ã¿ãã(ãµã¼ãã¹é¢æ°çµç±ï¼59 addAttachment(Base64.getDecoder().decode(result.getVisualization()), "template-matched-result");60 assertNotNull(result.getRect());61 }62 Stream<Arguments> osMartix() {63 return Stream.of(64 arguments("ios"),65 arguments("android")66 );67 }68 @AfterEach69 void tearDown() throws IOException {70 if (driver != null) {71 String base64Video = ((CanRecordScreen) driver).stopRecordingScreen();72 String path = String.format("./build/test_%s.mp4",osInfo.osName());73 Files.write(Paths.get(path), Base64.getDecoder().decode(base64Video));74 attachVideo(path);75 driver.closeApp();76 }77 }78 private void setup(String os) {79 osInfo = os.equals("ios")? new IOSBase():new AndroidBase();80 driver = osInfo.driver();81 driver.launchApp();82 driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);83 if (os.equals("ios")) {84 ((IOSBase)osInfo).iosDriver.startRecordingScreen(85 new IOSStartScreenRecordingOptions()86 .withVideoType("libx264")87 .withVideoScale("320:640")88 .withVideoQuality(IOSStartScreenRecordingOptions.VideoQuality.MEDIUM)89 );90 } else {91 ((AndroidBase)osInfo).androidDriver.startRecordingScreen();92 }93 MobileElement loginId = (MobileElement) driver.findElement(osInfo.loginId());94 MobileElement loginPwd = (MobileElement) driver.findElement(osInfo.loginPwd());95 loginId.sendKeys("demo");96 loginPwd.click();97 loginPwd.sendKeys("demo");98 }99 private String getReferenceImageB64(String imageName) throws IOException {100 BufferedImage image = ImageIO.read(new File(osInfo.resourceDir() + imageName));101 ByteArrayOutputStream os = new ByteArrayOutputStream();102 ImageIO.write(image, "png", os);103 return Base64.getEncoder().encodeToString(os.toByteArray());104 }105 private OccurrenceMatchingResult templateMatch(String template) throws IOException {106 return driver107 .findImageOccurrence(108 driver.getScreenshotAs(OutputType.FILE),109 new File(osInfo.resourceDir() + template),110 new OccurrenceMatchingOptions()111 .withThreshold(0.6)112 .withEnabledVisualization());113 }114 private static void addAttachment(byte[] byteArray, String imageName) {115 Allure.addAttachment(imageName, "image/png", new ByteArrayInputStream(byteArray), "png");116 }117 @SuppressWarnings("UnusedReturnValue")118 @Attachment(value = "video",type="video/mp4",fileExtension = "mp4")119 private byte[] attachVideo(String path) throws IOException {...
ImagesComparisonTest.java
Source:ImagesComparisonTest.java
...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 @Test52 public void verifyOccurrencesSearch() {53 byte[] screenshot = Base64.encodeBase64(driver.getScreenshotAs(OutputType.BYTES));54 OccurrenceMatchingResult result = driver55 .findImageOccurrence(screenshot, screenshot, new OccurrenceMatchingOptions()56 .withEnabledVisualization());57 assertThat(result.getVisualization().length, is(greaterThan(0)));58 assertNotNull(result.getRect());59 }60 @Test61 public void verifySimilarityCalculation() {62 byte[] screenshot = Base64.encodeBase64(driver.getScreenshotAs(OutputType.BYTES));63 SimilarityMatchingResult result = driver64 .getImagesSimilarity(screenshot, screenshot, new SimilarityMatchingOptions()65 .withEnabledVisualization());66 assertThat(result.getVisualization().length, is(greaterThan(0)));67 assertThat(result.getScore(), is(greaterThan(0.0)));68 }...
RecordingTest.java
Source:RecordingTest.java
...3import io.appium.java_client.HasSettings;4import io.appium.java_client.Setting;5import io.appium.java_client.android.AndroidDriver;6import io.appium.java_client.imagecomparison.OccurrenceMatchingOptions;7import io.appium.java_client.imagecomparison.OccurrenceMatchingResult;8import io.appium.java_client.ios.IOSDriver;9import org.apache.commons.io.FileUtils;10import org.openqa.selenium.OutputType;11import org.testng.annotations.Test;12import java.io.File;13import java.io.IOException;14import java.nio.file.Paths;15import java.util.Base64;16public class RecordingTest extends BaseTest {17 @Test18 public void iOSScreenRecordTest() throws IOException {19 ((IOSDriver)driver).startRecordingScreen();20 String s = ((IOSDriver) driver).stopRecordingScreen();21 byte[] decode = Base64.getDecoder().decode(s);22 FileUtils.writeByteArrayToFile(new File(23 System.getProperty("user.dir")24 +"/sample.mp4"),25 decode);26 }27 @Test28 public void androidScreenRecordTest() throws IOException, InterruptedException {29 ((AndroidDriver)driver).startRecordingScreen();30 Thread.sleep(10000);31 String s = ((AndroidDriver) driver).stopRecordingScreen();32 byte[] decode = Base64.getDecoder().decode(s);33 FileUtils.writeByteArrayToFile(new File(System.getProperty("user.dir")+"/sample.mp4"),34 decode);35 }36 @Test37 public void testApp() throws IOException {38 //((HasSettings)driver).setSetting(Setting.IMAGE_MATCH_THRESHOLD, "4.0");39 ((AndroidDriver) driver).sendSMS("555-555-5555", "Your message here!");40 ((HasSettings)driver).setSetting(Setting.FIX_IMAGE_TEMPLATE_SIZE, "true");41 ((HasSettings)driver).setSetting(Setting.IMAGE_ELEMENT_TAP_STRATEGY, "touchActions");42 File file = new File("/Users/saikrisv/Desktop/login.png");43 File refImgFile = Paths.get(file.toURI()).toFile();44 File screenshotAs = driver.getScreenshotAs(OutputType.FILE);45 OccurrenceMatchingResult result = driver46 .findImageOccurrence(screenshotAs, new File("/Users/saikrisv/Desktop/login.png") ,47 new OccurrenceMatchingOptions()48 .withEnabledVisualization());49 System.out.println(result.getRect());50 //driver.findElementByImage(s).click();51 }52}...
VisulizationTest.java
Source:VisulizationTest.java
1package testcases;2import io.appium.java_client.android.AndroidDriver;3import io.appium.java_client.imagecomparison.OccurrenceMatchingOptions;4import io.appium.java_client.imagecomparison.OccurrenceMatchingResult;5import org.apache.commons.codec.binary.Base64;6import org.openqa.selenium.OutputType;7import org.testng.Assert;8import org.testng.annotations.BeforeTest;9import org.testng.annotations.Test;10import utils.ImageUtils;11import java.io.IOException;12import java.net.URISyntaxException;13import java.net.URL;14/**15 * Year: 2018-1916 *17 * @author Prat3ik on 17/01/1918 * @project Image Comparision Appium19 */20public class VisulizationTest extends BaseTest{21 @BeforeTest22 @Override23 public void setUpPage() throws IOException {24 androidDriver = new AndroidDriver(new URL(APPIUM_SERVER_URL), getDesiredCapabilitiesForAndroid());25 }26 @Test27 public void testVisulization() throws IOException, URISyntaxException {28 byte[] fullImage = Base64.encodeBase64(ImageUtils.getBase64ByteFormatOfImage("abstractFullImage.jpg"));29 byte[] partialImage = Base64.encodeBase64(ImageUtils.getBase64ByteFormatOfImage("abstractPartialImage.png"));30 OccurrenceMatchingResult imageOccurrence = androidDriver.findImageOccurrence(fullImage, partialImage, new OccurrenceMatchingOptions()31 .withThreshold(0.1).withEnabledVisualization());32 System.out.println(imageOccurrence.getRect().getDimension());33 System.out.println("X:"+imageOccurrence.getRect().getX());34 System.out.println("Y:"+imageOccurrence.getRect().getY());35 System.out.println("Height:"+imageOccurrence.getRect().getHeight());36 System.out.println("Width:"+imageOccurrence.getRect().getWidth());37 System.out.println(imageOccurrence.getVisualization().length);38 Assert.assertTrue(imageOccurrence.getVisualization().length > 0 , "Partial image is not present!");39 }40}...
ImageButtonTest.java
Source:ImageButtonTest.java
1package testcases;2import io.appium.java_client.android.AndroidDriver;3import io.appium.java_client.imagecomparison.OccurrenceMatchingOptions;4import io.appium.java_client.imagecomparison.OccurrenceMatchingResult;5import io.appium.java_client.imagecomparison.SimilarityMatchingResult;6import org.apache.commons.codec.binary.Base64;7import org.openqa.selenium.By;8import org.openqa.selenium.OutputType;9import org.openqa.selenium.WebElement;10import org.testng.Assert;11import org.testng.annotations.BeforeTest;12import org.testng.annotations.Test;13import utils.ImageUtils;14import java.awt.*;15import java.io.File;16import java.io.IOException;17import java.net.URISyntaxException;18import java.net.URL;...
OccurrenceMatchingResult
Using AI Code Generation
1package appium.java;2import java.net.MalformedURLException;3import java.net.URL;4import java.util.List;5import org.openqa.selenium.By;6import org.openqa.selenium.Dimension;7import org.openqa.selenium.remote.DesiredCapabilities;8import io.appium.java_client.MobileBy;9import io.appium.java_client.MobileElement;10import io.appium.java_client.android.AndroidDriver;11import io.appium.java_client.imagecomparison.OccurrenceMatchingOptions;12import io.appium.java_client.imagecomparison.OccurrenceMatchingResult;13public class OccurrenceMatching {14 public static void main(String[] args) throws MalformedURLException {15 DesiredCapabilities cap = new DesiredCapabilities();16 cap.setCapability("deviceName", "Redmi");17 cap.setCapability("platformName", "Android");18 cap.setCapability("appPackage", "com.miui.calculator");19 cap.setCapability("appActivity", "com.miui.calculator.cal.CalculatorActivity");20 cap.setCapability("noReset", true);21 cap.setCapability("fullReset", false);
OccurrenceMatchingResult
Using AI Code Generation
1import io.appium.java_client.imagecomparison.OccurrenceMatchingResult;2import org.openqa.selenium.WebElement;3import io.appium.java_client.imagecomparison.ImageComparison;4import io.appium.java_client.imagecomparison.ImageElement;5import io.appium.java_client.imagecomparison.OccurrenceMatchingOptions;6import io.appium.java_client.imagecomparison.ImageElement;7import io.appium.java_client.imagecomparison.ImageComparison;8import io.appium.java_client.imagecomparison.OccurrenceMatchingOptions;9import io.appium.java_client.imagecomparison.OccurrenceMatchingResult;10import io.appium.java_client.imagecomparison.ImageElement;11import io.appium.java_client.imagecomparison.ImageComparison;12import io.appium.java_client.imagecomparison.OccurrenceMatchingOptions;13import io.appium.java_client.imagecomparison.OccurrenceMatchingResult;14import io.appium.java_client.imagecomparison.ImageElement;15import io.appium.java_client.imagecomparison.ImageComparison;16import io.appium.java_client.imagecomparison.OccurrenceMatchingOptions;17import io.appium.java_client.imagecomparison.OccurrenceMatchingResult;18import io.appium.java_client
OccurrenceMatchingResult
Using AI Code Generation
1import io.appium.java_client.imagecomparison.OccurrenceMatchingResult;2import org.openqa.selenium.WebElement;3public class OccurrenceMatchingResultExample {4 public static void main(String[] args) throws Exception {5 OccurrenceMatchingResult occurrenceMatchingResult = new OccurrenceMatchingResult(0.5, 0.5, 0.5, 0.5);6 WebElement element = occurrenceMatchingResult.getElement();7 double score = occurrenceMatchingResult.getScore();8 double x = occurrenceMatchingResult.getX();9 double y = occurrenceMatchingResult.getY();10 double width = occurrenceMatchingResult.getWidth();11 double height = occurrenceMatchingResult.getHeight();12 }13}14const OccurrenceMatchingResult = require('io.appium.java_client.imagecomparison.OccurrenceMatchingResult');15let occurrenceMatchingResult = new OccurrenceMatchingResult(0.5, 0.5, 0.5, 0.5);16let element = occurrenceMatchingResult.getElement();17let score = occurrenceMatchingResult.getScore();18let x = occurrenceMatchingResult.getX();19let y = occurrenceMatchingResult.getY();20let width = occurrenceMatchingResult.getWidth();21let height = occurrenceMatchingResult.getHeight();22Method Description double getScore() Returns the score of the element that is matched to the image. double getX() Returns the x coordinate of the element that is matched to
OccurrenceMatchingResult
Using AI Code Generation
1import io.appium.java_client.imagecomparison.OccurrenceMatchingResult;2import io.appium.java_client.imagecomparison.OccurrenceMatchingOptions;3import java.io.File;4import java.io.IOException;5import java.util.List;6import java.util.Map;7import java.util.concurrent.TimeUnit;8import org.openqa.selenium.By;9import org.openqa.selenium.WebElement;10import org.openqa.selenium.remote.DesiredCapabilities;11import io.appium.java_client.AppiumDriver;12import io.appium.java_client.MobileElement;13import io.appium.java_client.android.AndroidDriver;14import io.appium.java_client.android.AndroidElement;15public class OccurrenceMatchingResult {16 public static void main(String[] args) throws IOException {17 File appDir = new File("src");18 File app = new File(appDir, "ApiDemos-debug.apk");19 DesiredCapabilities capabilities = new DesiredCapabilities();20 capabilities.setCapability("deviceName", "Android Emulator");21 capabilities.setCapability("app", app.getAbsolutePath());22 capabilities.setCapability("appPackage", "io.appium.android.apis");23 capabilities.setCapability("appActivity", ".view.TextFields");
OccurrenceMatchingResult
Using AI Code Generation
1package appium.java;2import java.io.File;3import java.net.MalformedURLException;4import java.net.URL;5import java.util.concurrent.TimeUnit;6import org.openqa.selenium.By;7import org.openqa.selenium.remote.DesiredCapabilities;8import io.appium.java_client.AppiumDriver;9import io.appium.java_client.MobileElement;10import io.appium.java_client.android.AndroidDriver;11import io.appium.java_client.imagecomparison.OccurrenceMatchingOptions;12import io.appium.java_client.imagecomparison.OccurrenceMatchingResult;13public class ImageComparison {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 2 API 28");18 caps.setCapability("platformName", "Android");19 caps.setCapability("platformVersion", "9");20 caps.setCapability("appPackage", "com.android.calculator2");21 caps.setCapability("appActivity", "com.android.calculator2.Calculator");22 caps.setCapability("noReset", true);
OccurrenceMatchingResult
Using AI Code Generation
1public static void main(String[] args) throws IOException {2 File img1 = new File("C:\\Users\\Admin\\Desktop\\appium\\images\\img1.png");3 File img2 = new File("C:\\Users\\Admin\\Desktop\\appium\\images\\img2.png");4 BufferedImage image1 = ImageIO.read(img1);5 BufferedImage image2 = ImageIO.read(img2);6 String imageString1 = encodeToString(image1, "png");7 String imageString2 = encodeToString(image2, "png");8 OccurrenceMatchingResult result = new OccurrenceMatchingResult();9 result.matchOccurrence(imageString2, imageString1);10 System.out.println(result.getResult());11}12public static void main(String[] args) throws IOException {13 File img1 = new File("C:\\Users\\Admin\\Desktop\\appium\\images\\img1.png");14 File img2 = new File("C:\\Users\\Admin\\Desktop\\appium\\images\\img2.png");15 BufferedImage image1 = ImageIO.read(img1);16 BufferedImage image2 = ImageIO.read(img2);17 String imageString1 = encodeToString(image1, "png");18 String imageString2 = encodeToString(image2, "png");19 ImageComparison comparison = new ImageComparison();20 comparison.matchTemplate(imageString2, imageString1);21 System.out.println(comparison.getResult());22}
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!!