= Visual Testing using Pre-build Command
  • Docs »
  • Visual Testing using Pre-build Command

Performing Visual Testing using Pre-build Command

Steps to get imageID:

Step 1 - Import javaconnector, you can refer to this link to import

Note - Uploaded image should be in .png format

Step 2 - Use the below mentioned function to get the ImageID of the uploaded image

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

:mobile:visual:imageDiff :

Eg.

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);

2. To get all the text present in an image

:mobile:ocr: text

Eg.

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

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

:mobile:ocr:textExists

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

4. Command to find the “coordinates” of a word

:mobile:ocr:coordinate

Eg.

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