Best io.appium code snippet using io.appium.java_client.imagecomparison.SimilarityMatchingOptions
DeviceInitTest.java
Source:DeviceInitTest.java
2import com.gaea.gamemaster.publicTool.ExcelTest;3import com.gaea.gamemaster.publicTool.FileManage;4import io.appium.java_client.AppiumDriver;5import io.appium.java_client.android.AndroidDriver;6import io.appium.java_client.imagecomparison.SimilarityMatchingOptions;7import io.appium.java_client.imagecomparison.SimilarityMatchingResult;8import io.appium.java_client.remote.AndroidMobileCapabilityType;9import io.appium.java_client.remote.MobileCapabilityType;10import org.apache.commons.io.FileUtils;11import org.openqa.selenium.OutputType;12import org.openqa.selenium.WebElement;13import org.openqa.selenium.remote.DesiredCapabilities;14import java.io.File;15import java.net.URL;16import java.nio.file.Files;17import java.util.Base64;18import java.util.Scanner;19public class DeviceInitTest {20 private static String[] dveiceMessage;21 public static void main(String[] args) throws Exception {22 AppiumDriver<WebElement> driver = initDriver();23 for (int i = 1; i <= 1000; i++) {24 getScreenImage(driver);25 }26 }27 public static void testImageDiff(AppiumDriver driver) throws Exception {28 SimilarityMatchingOptions opts = new SimilarityMatchingOptions();29 opts.withEnabledVisualization();30 File newBaseline = driver.getScreenshotAs(OutputType.FILE);31 FileUtils.copyFile(newBaseline, new File(getImageXpath("learn1")));32 Thread.sleep(1200);33 File file3 = new File(getImageXpath("learn"));34 File file4 = new File(getImageXpath("learn1"));35 SimilarityMatchingResult res = driver.getImagesSimilarity(file3,file4,opts);36 System.out.println("res.getScore()"+res.getScore());37 double score = 0.998;38 if (res.getScore() > score) {39 res.storeVisualization(new File(getImageXpath("res")));40 }41 }42 public static void testImageFind(){...
Edition098_Visual_Testing_1.java
Source:Edition098_Visual_Testing_1.java
1import io.appium.java_client.MobileBy;2import io.appium.java_client.android.AndroidDriver;3import io.appium.java_client.imagecomparison.SimilarityMatchingOptions;4import io.appium.java_client.imagecomparison.SimilarityMatchingResult;5import java.io.File;6import java.net.URL;7import org.apache.commons.io.FileUtils;8import org.junit.After;9import org.junit.Before;10import org.junit.Test;11import org.openqa.selenium.By;12import org.openqa.selenium.OutputType;13import org.openqa.selenium.WebElement;14import org.openqa.selenium.remote.DesiredCapabilities;15import org.openqa.selenium.support.ui.ExpectedConditions;16import org.openqa.selenium.support.ui.WebDriverWait;17public class Edition098_Visual_Testing_1 {18 private final static String APP = "https://github.com/cloudgrey-io/the-app/releases/download/v1.10.0/TheApp-v1.10.0.apk";19 // need somewhere to store match files; change for a path suitable for your system20 private final static String VALIDATION_PATH = "/Users/jlipps/Desktop/validations";21 private final static String CHECK_HOME = "home_screen";22 private final static String CHECK_LOGIN = "login_screen";23 private final static String BASELINE = "BASELINE_";24 private final static double MATCH_THRESHOLD = 0.99;25 private final static By LOGIN_SCREEN = MobileBy.AccessibilityId("Login Screen");26 private final static By USERNAME_FIELD = MobileBy.AccessibilityId("username");27 private AndroidDriver<WebElement> driver;28 @Before29 public void setUp() throws Exception {30 DesiredCapabilities capabilities = new DesiredCapabilities();31 capabilities.setCapability("platformName", "Android");32 capabilities.setCapability("deviceName", "Android Emulator");33 capabilities.setCapability("automationName", "UiAutomator2");34 capabilities.setCapability("app", APP);35 // make sure we uninstall the app before each test regardless of version36 capabilities.setCapability("uninstallOtherPackages", "io.cloudgrey.the_app");37 URL server = new URL("http://localhost:4723/wd/hub");38 driver = new AndroidDriver<>(server, capabilities);39 }40 @After41 public void tearDown() {42 if (driver != null) {43 driver.quit();44 }45 }46 private WebElement waitForElement(WebDriverWait wait, By selector) {47 WebElement el = wait.until(ExpectedConditions.presenceOfElementLocated(selector));48 try { Thread.sleep(750); } catch (InterruptedException ign) {}49 return el;50 }51 @Test52 public void testAppDesign() throws Exception {53 WebDriverWait wait = new WebDriverWait(driver, 5);54 // wait for an element that's on the home screen55 WebElement loginScreen = waitForElement(wait, LOGIN_SCREEN);56 // now we know the home screen is loaded, so do a visual check57 doVisualCheck(CHECK_HOME);58 // nav to the login screen, and wait for an element that's on the login screen59 loginScreen.click();60 waitForElement(wait, USERNAME_FIELD);61 // perform our second visual check, this time of the login screen62 doVisualCheck(CHECK_LOGIN);63 }64 private void doVisualCheck(String checkName) throws Exception {65 String baselineFilename = VALIDATION_PATH + "/" + BASELINE + checkName + ".png";66 File baselineImg = new File(baselineFilename);67 // If no baseline image exists for this check, we should create a baseline image68 if (!baselineImg.exists()) {69 System.out.println(String.format("No baseline found for '%s' check; capturing baseline instead of checking", checkName));70 File newBaseline = driver.getScreenshotAs(OutputType.FILE);71 FileUtils.copyFile(newBaseline, new File(baselineFilename));72 return;73 }74 // Otherwise, if we found a baseline, get the image similarity from Appium. In getting the similarity,75 // we also turn on visualization so we can see what went wrong if something did.76 SimilarityMatchingOptions opts = new SimilarityMatchingOptions();77 opts.withEnabledVisualization();78 SimilarityMatchingResult res = driver.getImagesSimilarity(baselineImg, driver.getScreenshotAs(OutputType.FILE), opts);79 // If the similarity is not high enough, consider the check to have failed80 if (res.getScore() < MATCH_THRESHOLD) {81 File failViz = new File(VALIDATION_PATH + "/FAIL_" + checkName + ".png");82 res.storeVisualization(failViz);83 throw new Exception(84 String.format("Visual check of '%s' failed; similarity match was only %f, and below the threshold of %f. Visualization written to %s.",85 checkName, res.getScore(), MATCH_THRESHOLD, failViz.getAbsolutePath()));86 }87 // Otherwise, it passed!88 System.out.println(String.format("Visual check of '%s' passed; similarity match was %f",89 checkName, res.getScore()));90 }...
AppUpgradeVisualRegressionTestOpenCV.java
Source:AppUpgradeVisualRegressionTestOpenCV.java
...11import org.openqa.selenium.support.ui.ExpectedConditions;12import org.openqa.selenium.support.ui.WebDriverWait;13import io.appium.java_client.MobileBy;14import io.appium.java_client.android.AndroidDriver;15import io.appium.java_client.imagecomparison.SimilarityMatchingOptions;16import io.appium.java_client.imagecomparison.SimilarityMatchingResult;17public class AppUpgradeVisualRegressionTestOpenCV18{19 public static void main(String[] args) throws Exception20 {21 //Visual Testing via OpenCV22 //Enter data to submit23 Scanner sc=new Scanner(System.in);24 System.out.println("Enter some data into text box in echobox");25 String text=sc.nextLine();26 sc.close();27 //Start appium sever28 Runtime.getRuntime().exec("cmd.exe /c start cmd.exe /k \"appium\"");29 URL u=new URL("http://0.0.0.0:4723/wd/hub");30 //Define desired capabilities related to device and app31 DesiredCapabilities dc=new DesiredCapabilities();32 dc.setCapability(CapabilityType.BROWSER_NAME,"");33 dc.setCapability("deviceName","ce081718334a5b0b05");34 dc.setCapability("platformName","android");35 dc.setCapability("platformVersion","8.0.0");36 dc.setCapability("autoGrantPermissions","true"); //extra 37 dc.setCapability("adbExecTimeout","50000"); //extra in msec 38 dc.setCapability("app","E:\\Automation\\TheApp-v1.9.0.apk");39 dc.setCapability("uninstallOtherPackages","io.cloudgrey.the_app");40 //Launch app in device through appium server41 AndroidDriver driver;42 while(2>1)43 {44 try45 {46 driver=new AndroidDriver(u,dc);47 break;48 }49 catch(Exception ex)50 {51 }52 } 53 Thread.sleep(10000);54 //Create a folder for results55 SimpleDateFormat sf=new SimpleDateFormat("dd-MMM-yyyy-hh-mm-ss");56 Date dt=new Date();57 File resfolder=new File("VTResOn"+sf.format(dt));58 resfolder.mkdir();59 try60 {61 WebDriverWait wait=new WebDriverWait(driver,20);62 wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@text='Echo Box']")));63 //Take screen shot of Home screen in version-164 File hs=driver.getScreenshotAs(OutputType.FILE);65 wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@text='Echo Box']"))).click();66 wait.until(ExpectedConditions.visibilityOfElementLocated(MobileBy.AccessibilityId("messageInput"))).sendKeys(text);67 wait.until(ExpectedConditions.visibilityOfElementLocated(MobileBy.AccessibilityId("messageSaveBtn"))).click();68 wait.until(ExpectedConditions.visibilityOfElementLocated(MobileBy.AccessibilityId(text)));69 wait.until(ExpectedConditions.visibilityOfElementLocated(MobileBy.AccessibilityId("messageInput"))).clear();70 Thread.sleep(2000);71 //Take screenshot of saved message screen in version-172 File ms=driver.getScreenshotAs(OutputType.FILE);73 //Launch upgraded version74 driver.installApp("E:\\Automation\\TheApp-v1.10.0.apk");75 driver.activateApp("io.cloudgrey.the_app");76 wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@text='Echo Box']")));77 Thread.sleep(2000);78 //Test the Home screen in version-2 with version-179 doVisualCheck(driver,"homescreen",hs,resfolder);80 wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@text='Echo Box']"))).click();81 wait.until(ExpectedConditions.visibilityOfElementLocated(MobileBy.AccessibilityId(text)));82 Thread.sleep(2000);83 //Test the saved message screen in version-2 with version-184 doVisualCheck(driver,"msgscreen",ms,resfolder);85 }86 catch(Exception ex)87 {88 System.out.println(ex.getMessage());89 }90 //Close App91 driver.quit();92 //Stop appium server93 Runtime.getRuntime().exec("taskkill /F /IM node.exe");94 Runtime.getRuntime().exec("taskkill /F /IM cmd.exe"); 95 }96 public static void doVisualCheck(AndroidDriver driver,String checkName,File baseImg, File resfolder) throws Exception 97 {98 SimilarityMatchingOptions opts=new SimilarityMatchingOptions();99 opts.withEnabledVisualization();100 File newImg=driver.getScreenshotAs(OutputType.FILE);101 SimilarityMatchingResult res=driver.getImagesSimilarity(baseImg,newImg,opts);102 //If the similarity is not high enough, consider the check to have failed103 if(res.getScore()<1.0) //1.0 means 100%104 {105 File difffile=new File(resfolder.getAbsolutePath()+"/FAIL_"+checkName+".png");106 res.storeVisualization(difffile);107 System.out.println("Visual check of "+checkName+108 " failed; similarity match was only "+res.getScore()+109 ", and below the threshold of 1.0. Visualization written to "+110 difffile.getAbsolutePath());111 }112 else...
OpenCV.java
Source:OpenCV.java
...11import org.openqa.selenium.support.ui.WebDriverWait;12import io.appium.java_client.MobileBy;13import io.appium.java_client.android.Activity;14import io.appium.java_client.android.AndroidDriver;15import io.appium.java_client.imagecomparison.SimilarityMatchingOptions;16import io.appium.java_client.imagecomparison.SimilarityMatchingResult;17public class OpenCV 18{19 public static void main(String[] args) throws Exception20 {21 //visual testing via opencv22 String AppV1="D:\\batch249\\TheAppV1.apk";23 String appUpgrade="D:\\batch249\\TheAppV2.apk";24 String APPKG="io.cloudgrey.the_app";25 String APPACT="com.reactnativenavigation.controllers.NavigationActivity";26 String msg="Hello KALAM sir";27 By msgInput=MobileBy.AccessibilityId("messageInput");28 By echoBox=MobileBy.AccessibilityId("Echo Box");29 By savesmsg=MobileBy.AccessibilityId(msg);30 By savemsgbtn=MobileBy.AccessibilityId("messageSaveBtn");31 //start appium server32 Runtime.getRuntime().exec("cmd.exe /c start cmd.exe /k \"appium\"");33 URL u=new URL("http://0.0.0.0:4723/wd/hub");34 //Define desired capabilities related to device and app35 DesiredCapabilities dc=new DesiredCapabilities();36 dc.setCapability(CapabilityType.BROWSER_NAME,"");37 dc.setCapability("deviceName","emulator-5554");38 dc.setCapability("platformName","android");39 dc.setCapability("platformVersion","8.1.0");40 dc.setCapability("autoGrantPermissions","true");41 dc.setCapability("adbExecTimeout","50000");42 dc.setCapability("app",AppV1);43 dc.setCapability("uninstallOtherPackages","io.cloudgrey.the_app");44 //Launch app in device through appium server by creating driver object45 AndroidDriver driver;46 while(2>1)47 {48 try49 {50 driver=new AndroidDriver(u,dc);51 break;52 }53 catch(Exception ex)54 {55 56 }57 }58 Thread.sleep(10000);59 //create a folder for results60 SimpleDateFormat sf=new SimpleDateFormat("dd-MMM-yyyy-hh-mm-ss");61 Date dt=new Date();62 File resfolder=new File("VTResOn"+sf.format(dt));63 resfolder.mkdir();64 try65 {66 WebDriverWait w=new WebDriverWait(driver,20);67 w.until(ExpectedConditions.presenceOfElementLocated(echoBox));68 //Take screenshot of home screen in version169 File hs=driver.getScreenshotAs(OutputType.FILE);70 w.until(ExpectedConditions.elementToBeClickable(echoBox)).click();71 w.until(ExpectedConditions.presenceOfElementLocated(msgInput)).sendKeys(msg);72 w.until(ExpectedConditions.presenceOfElementLocated(savemsgbtn)).click();73 w.until(ExpectedConditions.presenceOfElementLocated(savesmsg));74 //Take screenshot of saved message screen in version 175 File ms=driver.getScreenshotAs(OutputType.FILE);76 Thread.sleep(10000);77 driver.installApp(appUpgrade);78 Thread.sleep(10000);79 Activity activity=new Activity(APPKG,APPACT);80 driver.startActivity(activity);81 w.until(ExpectedConditions.presenceOfElementLocated(echoBox));82 //Test the Home screen in version2 with version183 doVisualCheck(driver,"homescreen",hs,resfolder);84 w.until(ExpectedConditions.elementToBeClickable(echoBox)).click();85 w.until(ExpectedConditions.presenceOfElementLocated(savesmsg));86 //Test the saved message screen in version2 with version 187 doVisualCheck(driver,"msgscreen",ms,resfolder);88 }89 catch(Exception ex)90 {91 System.out.println(ex.getMessage());92 }93 //close app94 driver.closeApp();95 //stop appium server96 Runtime.getRuntime().exec("taskkill /F /IM node.exe");97 Runtime.getRuntime().exec("taskkill /F /IM cmd.exe");98 }99 public static void doVisualCheck(AndroidDriver driver, String checkName, File baseImg, File resfolder) throws Exception100 {101 SimilarityMatchingOptions opts=new SimilarityMatchingOptions();102 opts.withEnabledVisualization();103 File newImg=driver.getScreenshotAs(OutputType.FILE);104 SimilarityMatchingResult res=driver.getImagesSimilarity(baseImg,newImg);105 //if the similarity is not high enough,consider the check to have failed106 if(res.getScore()<1.0)107 {108 File difffile=new File(resfolder.getAbsolutePath()+"/Fail_"+checkName+".png");109 res.storeVisualization(difffile);110 System.out.println("Visual check of"+checkName+"failed; due to similarity match was only"+res.getScore()+111 ",and below the threshold of 1.0 Visualization written to"+difffile.getAbsolutePath());112 }113 else114 {115 System.out.println(String.format("Visual check of '%s' passed;similarity match was %f",...
VehiclePage.java
Source:VehiclePage.java
2import io.appium.java_client.MobileElement;3import io.appium.java_client.TouchAction;4import io.appium.java_client.android.AndroidDriver;5import io.appium.java_client.android.AndroidElement;6import io.appium.java_client.imagecomparison.SimilarityMatchingOptions;7import io.appium.java_client.imagecomparison.SimilarityMatchingResult;8import io.appium.java_client.pagefactory.AndroidFindBy;9import io.appium.java_client.touch.offset.PointOption;10import org.apache.commons.io.FileUtils;11import org.openqa.selenium.By;12import org.openqa.selenium.OutputType;13import java.io.File;14import java.util.List;15public class VehiclePage extends CommonPage {16 public @AndroidFindBy(id = "com.codecool.holabusz:id/centerTextView")17 MobileElement noStopsText;18 public String noStopsSentence = "There are no stops available in 0 meters";19 public @AndroidFindBy(xpath = "//android.widget.Toast[@text='Permission Denied']")20 MobileElement deniedToast;21 public @AndroidFindBy(id = "com.codecool.holabusz:id/testText")22 MobileElement meterText;23 public @AndroidFindBy(id = "com.codecool.holabusz:id/seekBar")24 MobileElement meterSlider;25 public @AndroidFindBy(xpath = "/hierarchy/android.widget.FrameLayout/" +26 "android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/" +27 "android.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup/" +28 "androidx.recyclerview.widget.RecyclerView/android.view.ViewGroup[1]/android.widget.TextView[1]")29 MobileElement firstVehicleNumber;30 public VehiclePage(AndroidDriver<AndroidElement> androidDriver) {31 super(androidDriver);32 }33 public int getNumberOfVehicles() {34 List<AndroidElement> vehicles = androidDriver.findElements(By.xpath("/hierarchy/android.widget.FrameLayout/" +35 "android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/" +36 "android.view.ViewGroup/android.view.ViewGroup/androidx.recyclerview.widget.RecyclerView/android.view.ViewGroup"));37 if (vehicles.size() < 1) {38 return 0;39 }40 return vehicles.size();41 }42 public void setMeterSlider(double percent) {43 int startX = meterSlider.getLocation().getX();44 int startY = meterSlider.getLocation().getY();45 int endX = meterSlider.getSize().getWidth();46 int moveToXDirectionAt = (int)(endX * percent);47 TouchAction act = new TouchAction(androidDriver);48 act.press(PointOption.point(startX, startY)).moveTo(PointOption.point(moveToXDirectionAt, startY)).release().perform();49 }50 public boolean doVisualCheck(String checkName) throws Exception {51 String baselineFileName = "C:\\Users\\ilove\\IdeaProjects\\holabusTest\\src\\test\\resources\\validationPictures\\"+checkName+".png";52 File baselineImg = new File(baselineFileName);53 System.out.println(baselineFileName);54 if (!baselineImg.exists()){55 System.out.printf("No baseline found for '%s' check capturing baseline!%n",checkName);56 File newBaseline = androidDriver.getScreenshotAs(OutputType.FILE);57 FileUtils.copyFile(newBaseline,new File(baselineFileName));58 return false;59 }60 SimilarityMatchingOptions opts = new SimilarityMatchingOptions();61 opts.withEnabledVisualization();62 SimilarityMatchingResult res = androidDriver.getImagesSimilarity(baselineImg, androidDriver.getScreenshotAs(OutputType.FILE), opts);63 if(res.getScore()<0.99){64 File failViz = new File("C:\\Users\\ilove\\IdeaProjects\\holabusTest\\src\\test\\resources\\failedValidations\\"+checkName+".png");65 res.storeVisualization(failViz);66 return false;67 }68 System.out.println("Visual is passed!");69 return true;70 }71}...
ImagesComparisonTest.java
Source:ImagesComparisonTest.java
...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 }69}...
nativeMobileTests.java
Source:nativeMobileTests.java
1package scenarios;2import bean.DataBean;3import io.appium.java_client.imagecomparison.SimilarityMatchingOptions;4import io.appium.java_client.imagecomparison.SimilarityMatchingResult;5import org.apache.commons.codec.binary.Base64;6import org.openqa.selenium.OutputType;7import org.testng.annotations.Test;8import pageObjects.BudgetPage;9import pageObjects.RegisterPage;10import setup.BaseTest;11import setup.DataProvider;12import static org.assertj.core.api.Assertions.assertThat;13public class nativeMobileTests extends BaseTest {14 /*15 On the decision of bonus task, I chose the solution of comparing screenshots until and after click on button.16 I have found this on the appium documentation (https://appium.io/docs/en/writing-running-appium/image-comparison/)17 But this method required additional npm module as 'opencv4nodejs'. I have installed it but the exception is appearing anyway.18 Could you clarify, this decision is convenient or not?19 */20 @Test(priority = 1, groups = {"native"}, description = "This simple test just click on the Sign In button")21 public void simpleNativeTest() throws IllegalAccessException, NoSuchFieldException, InstantiationException {22 byte[] screenshot1 = Base64.encodeBase64(getDriver().getScreenshotAs(OutputType.BYTES));23 getPo().getWelement("signInBtn").click();24 byte[] screenshot2 = Base64.encodeBase64(getDriver().getScreenshotAs(OutputType.BYTES));25 SimilarityMatchingResult result = getDriver()26 .getImagesSimilarity(screenshot1, screenshot2, new SimilarityMatchingOptions()27 .withEnabledVisualization());28 assertThat(result.getVisualization().length).isGreaterThan(0);29 assertThat(result.getScore()).isGreaterThan(0.0);30 System.out.println("Simplest Android native test done");31 }32 @Test(priority = 2,33 groups = {"native"},34 description = "Register and Login assert",35 dataProviderClass = DataProvider.class,36 dataProvider = "data")37 public void registerAndLoginTest(DataBean data) throws IllegalAccessException, NoSuchFieldException, InstantiationException {38 getPo().getWelement("registerBtn").click();39 RegisterPage registerPage = getPo().getNativeRegisterPage("registerPage");40 registerPage.register(data.getEmail(), data.getUserName(), data.getPassword());...
LiveAllNight.java
Source:LiveAllNight.java
1import io.appium.java_client.MobileElement;2import io.appium.java_client.imagecomparison.SimilarityMatchingOptions;3import io.appium.java_client.imagecomparison.SimilarityMatchingResult;4import org.apache.commons.codec.binary.Base64;5import org.apache.commons.io.FileUtils;6import org.openqa.selenium.OutputType;7import org.testng.Assert;8import org.testng.annotations.Parameters;9import org.testng.annotations.Test;10import utils.BaseTest;11import utils.FactoryClasses.keyCode;12import utils.Log;13import utils.TemplateMatching;14import java.io.File;15import java.io.IOException;16import java.util.List;...
SimilarityMatchingOptions
Using AI Code Generation
1SimilarityMatchingOptions similarityMatchingOptions = new SimilarityMatchingOptions();2similarityMatchingOptions.withEnabled(true);3similarityMatchingOptions.withThreshold(0.7);4similarityMatchingOptions.withOutputAllMatches(true);5similarityMatchingOptions.withOutputMatchedImage(true);6return similarityMatchingOptions;7let similarityMatchingOptions = new SimilarityMatchingOptions();8similarityMatchingOptions.withEnabled(true);9similarityMatchingOptions.withThreshold(0.7);10similarityMatchingOptions.withOutputAllMatches(true);11similarityMatchingOptions.withOutputMatchedImage(true);12return similarityMatchingOptions;13similarity_matching_options = SimilarityMatchingOptions()14similarity_matching_options.with_enabled(True)15similarity_matching_options.with_threshold(0.7)16similarity_matching_options.with_output_all_matches(True)17similarity_matching_options.with_output_matched_image(True)18similarity_matching_options.with_enabled(true)19similarity_matching_options.with_threshold(0.7)20similarity_matching_options.with_output_all_matches(true)21similarity_matching_options.with_output_matched_image(true)22$similarityMatchingOptions = new SimilarityMatchingOptions();23$similarityMatchingOptions->withEnabled(true);24$similarityMatchingOptions->withThreshold(0.7);25$similarityMatchingOptions->withOutputAllMatches(true);26$similarityMatchingOptions->withOutputMatchedImage(true);27return $similarityMatchingOptions;28similarity_matching_options.with_enabled(true)29similarity_matching_options.with_threshold(0.7)30similarity_matching_options.with_output_all_matches(true)31similarity_matching_options.with_output_matched_image(true)
SimilarityMatchingOptions
Using AI Code Generation
1import io.appium.java_client.imagecomparison.SimilarityMatchingOptions;2SimilarityMatchingOptions similarityMatchingOptions = new SimilarityMatchingOptions();3similarityMatchingOptions.withEnabled(true);4similarityMatchingOptions.withThreshold(0.8);5mobileElement.setImageSimilarityMatchingOptions(similarityMatchingOptions);6from appium.webdriver.common.image_comparison import SimilarityMatchingOptions7similarity_matching_options = SimilarityMatchingOptions()8const { SimilarityMatchingOptions } = require('appium/webdriverio');9const similarityMatchingOptions = new SimilarityMatchingOptions();10similarityMatchingOptions.withEnabled(true);11similarityMatchingOptions.withThreshold(0.8);12mobileElement.setImageSimilarityMatchingOptions(similarityMatchingOptions);13use Appium\WebDriver\Remote\ImagesComparison\SimilarityMatchingOptions;14$similarityMatchingOptions = new SimilarityMatchingOptions();15$similarityMatchingOptions->withEnabled(true);16$similarityMatchingOptions->withThreshold(0.8);17$mobileElement->setImageSimilarityMatchingOptions($similarityMatchingOptions);18using OpenQA.Selenium.Appium.ImageComparison;19SimilarityMatchingOptions similarityMatchingOptions = new SimilarityMatchingOptions();20similarityMatchingOptions.Enabled = true;21similarityMatchingOptions.Threshold = 0.8;22mobileElement.ImageSimilarityMatchingOptions = similarityMatchingOptions;
SimilarityMatchingOptions
Using AI Code Generation
1AndroidDriver driver;2SimilarityMatchingOptions similarityMatchingOptions = new SimilarityMatchingOptions();3similarityMatchingOptions.withEnabled(true);4similarityMatchingOptions.withMatchThreshold(0.7);5similarityMatchingOptions.withEnabledVisualization(true);6driver.setSettings(similarityMatchingOptions);7from appium.webdriver.extensions.image_comparison import SimilarityMatchingOptions8similarity_matching_options = SimilarityMatchingOptions()9self.driver.update_settings(similarity_matching_options)10const { SimilarityMatchingOptions } = require('appium-webdriveragent').webdriverimagecomparison;11const similarityMatchingOptions = new SimilarityMatchingOptions();12similarityMatchingOptions.enabled = true;13similarityMatchingOptions.matchThreshold = 0.7;14similarityMatchingOptions.enabledVisualization = true;15await driver.updateSettings(similarityMatchingOptions);16driver.update_settings(similarity_matching_options)17use Facebook\WebDriver\Remote\RemoteWebDriver;18use Facebook\WebDriver\Remote\DesiredCapabilities;19use Facebook\WebDriver\Remote\LocalFileDetector;20use Facebook\WebDriver\WebDriverDimension;
SimilarityMatchingOptions
Using AI Code Generation
1SimilarityMatchingOptions similarityMatchingOptions = new SimilarityMatchingOptions();2similarityMatchingOptions.withEnabled(true);3similarityMatchingOptions.withEnabled(false);4similarityMatchingOptions.withEnabled(true).withThreshold(0.9);5similarity_matching_options = SimilarityMatchingOptions()6const similarityMatchingOptions = new Appium.ImageComparison.SimilarityMatchingOptions();7similarityMatchingOptions.enabled = true;8similarityMatchingOptions.enabled = false;9similarityMatchingOptions.enabled = true;10similarityMatchingOptions.threshold = 0.9;11const similarityMatchingOptions = new Appium.ImageComparison.SimilarityMatchingOptions();12similarityMatchingOptions.enabled = true;13similarityMatchingOptions.enabled = false;14similarityMatchingOptions.enabled = true;15similarityMatchingOptions.threshold = 0.9;16const similarityMatchingOptions = new Appium.ImageComparison.SimilarityMatchingOptions();17similarityMatchingOptions.enabled = true;18similarityMatchingOptions.enabled = false;19similarityMatchingOptions.enabled = true;20similarityMatchingOptions.threshold = 0.9;21const similarityMatchingOptions = new Appium.ImageComparison.SimilarityMatchingOptions();22similarityMatchingOptions.enabled = true;23similarityMatchingOptions.enabled = false;24similarityMatchingOptions.enabled = true;25similarityMatchingOptions.threshold = 0.9;
SimilarityMatchingOptions
Using AI Code Generation
1package com.appium;2import java.io.File;3import java.net.MalformedURLException;4import java.net.URL;5import java.util.concurrent.TimeUnit;6import org.openqa.selenium.OutputType;7import org.openqa.selenium.remote.DesiredCapabilities;8import io.appium.java_client.AppiumDriver;9import io.appium.java_client.imagecomparison.ImageComparisonResult;10import io.appium.java_client.imagecomparison.SimilarityMatchingOptions;11public class Appium_SimilarityMatchingOptions {12 public static void main(String[] args) throws MalformedURLException, InterruptedException {13 DesiredCapabilities cap = new DesiredCapabilities();14 cap.setCapability("deviceName", "Pixel 3 API 28");15 cap.setCapability("platformName", "Android");16 cap.setCapability("platformVersion", "9.0");17 cap.setCapability("app", "C:\\Users\\prade\\Downloads\\Appium\\ApiDemos-debug.apk");18 cap.setCapability("automationName", "UiAutomator2");19 cap.setCapability("noReset", true);
SimilarityMatchingOptions
Using AI Code Generation
1SimilarityMatchingOptions similarityMatchingOptions = new SimilarityMatchingOptions();2similarityMatchingOptions.withEnabled(true).withThreshold(0.8);3ImageComparison imageComparison = new ImageComparison(similarityMatchingOptions);4boolean result = imageComparison.isEqual(base64EncodedImage1, base64EncodedImage2);5System.out.println(result);6boolean resultWithTimeout = imageComparison.isEqual(base64EncodedImage1, base64EncodedImage2, 30);7System.out.println(resultWithTimeout);8imageComparison.setSimilarityThreshold(0.8);9double similarityThreshold = imageComparison.getSimilarityThreshold();10System.out.println(similarityThreshold);11boolean resultWithThreshold = imageComparison.isEqual(base64EncodedImage1, base64EncodedImage2);12System.out.println(resultWithThreshold);13imageComparison.setSimilarityMatchingOptions(similarityMatchingOptions);14SimilarityMatchingOptions similarityMatchingOptions1 = imageComparison.getSimilarityMatchingOptions();15System.out.println(similarityMatchingOptions1);16imageComparison.setSimilarityMatchingOptions(similarityMatchingOptions, 30);17SimilarityMatchingOptions similarityMatchingOptions2 = imageComparison.getSimilarityMatchingOptions();18System.out.println(similarityMatchingOptions2);19imageComparison.setSimilarityMatchingOptions(similarityMatchingOptions, 30, 1);20SimilarityMatchingOptions similarityMatchingOptions3 = imageComparison.getSimilarityMatchingOptions();21System.out.println(similarityMatchingOptions3);
SimilarityMatchingOptions
Using AI Code Generation
1import org.openqa.selenium.WebElement;2import org.openqa.selenium.By;3import org.openqa.selenium.remote.DesiredCapabilities;4import io.appium.java_client.imagecomparison.SimilarityMatchingOptions;5import java.net.URL;6import io.appium.java_client.AppiumDriver;7import io.appium.java_client.MobileElement;8import io.appium.java_client.android.AndroidDriver;9import java.net.MalformedURLException;10import java.util.concurrent.TimeUnit;11public class SimilarityMatching {12 public static void main(String[] args) throws MalformedURLException {13 DesiredCapabilities caps = new DesiredCapabilities();14 caps.setCapability("deviceName", "<device name>");15 caps.setCapability("platformName", "Android");16 caps.setCapability("platformVersion", "<platform version>");17 caps.setCapability("appPackage", "<app package>");18 caps.setCapability("appActivity", "<app activity>");19 caps.setCapability("noReset", true);
SimilarityMatchingOptions
Using AI Code Generation
1import io.appium.java_client.imagecomparison.SimilarityMatchingOptions;2import io.appium.java_client.imagecomparison.SimilarityMatchingOptionsBuilder;3public class SimilarityMatchingOptionsClass {4 public static void main(String[] args) {5 File imageFile = new File("C:\\Users\\username\\Downloads\\appium.png");6 SimilarityMatchingOptions similarityMatchingOptions = new SimilarityMatchingOptionsBuilder()7 .withEnabledVisualization()8 .withImage(imageFile)9 .withMaxOverlapping(0.1)10 .withSimilarity(0.9)11 .build();12 List<MatchResult> matchResults = driver.findImageOccurrence(similarityMatchingOptions);13 for (MatchResult matchResult : matchResults) {14 System.out.println("Similarity: " + matchResult.getSimilarity());15 System.out.println("Matched Area: " + matchResult.getMatchedArea());16 }17 }18}19const { SimilarityMatchingOptions } = require('appium-image-comparison');20const { SimilarityMatchingOptionsBuilder } = require('appium-image-comparison');21let similarityMatchingOptions = new SimilarityMatchingOptionsBuilder()22 .withEnabledVisualization()23 .withImage(imageFile)24 .withMaxOverlapping(0.1)25 .withSimilarity(0.9)26 .build();27let matchResults = driver.findImageOccurrence(similarityMatchingOptions);
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!!