Skip to main content
🏠Documentation|Visual Testing Using Pre Build Commands

Last updated on : 21 Jan 2025

Visual Testing Using Pre-Build Commands

Performing Visual Testing using Pre-build Command

Steps to get imageID:

  1. Import javaconnector, you can refer to this link to import
note

Uploaded image should be in .png format

  1. Use the below mentioned function to get the ImageID of the uploaded image
Json


Connector con = new Connector("CLOUD_URL");
//To get the Access key - Login to pCloudy platform->Go to Profile and click on Settings->Copy the access key
String authToken = con.authenticateUser("EMAIL_ID", "API_KEY");
File fileToBeUploaded = new File("LOCAL_IMAGE_PATH");
String baseImageId = con.getImageId(authToken, fileToBeUploaded);
String secondImageId = con.getImageId(authToken, fileToBeUploaded);

Using the above function user will get the ImageID of the Base image and second image (that is used for visual analysis)

Let's see how to use Pre-build commands for visual analysis

  1. To compare and find the difference between two images
Json


mobile:visual:imageDiff :

Eg.

Json


Map< String, Object> params = new HashMap<>();
//Declare Image ID of Base image
params.put("baseImageId", imageId);
//declare Image ID of second image
params.put("secondImageId", secondImageId);
//Find the difference between two image
String base64=(String) driver.executeScript("mobile:visual:imageDiff",params);
//Enter path
File imgFile = new File("C:\Users\Admin\OneDrive\Desktop\diff.png");
BufferedImage img = ImageIO.read(new ByteArrayInputStream(org.apache.commons.codec.binary.Base64.decodeBase64(base64)));
ImageIO.write(img, "png", imgFile);


  1. To get all the text present in an image
Json


:mobile:ocr: text


Eg.

Json


Map< String, Object> params = new HashMap<>();
System.out.println(driver.executeScript("mobile:ocr:text",params));


  1. Command to verify if any word exists or not in an image
Json


:mobile:ocr:textExists

Json


Map< String, Object> params = new HashMap<>();
params.put("imageId", baseImageId);
params.put("word", "cleartrip");
System.out.println(driver.executeScript("mobile:ocr:textExists",params));


  1. Command to find the “coordinates” of a word
Json


:mobile:ocr:coordinate

Eg.

Json


Map< String, Object> params = new HashMap<>();
params.put("imageId", baseImageId);
params.put("word", "cleartrip");
System.out.println(driver.executeScript("mobile:ocr:coordinate ",params));


Did this page help you?