Visual Testing Using Pre-Build Commands

Prev Next

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

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

  1. To compare and find the difference between two images
mobile:visual:imageDiff :
Plain text

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);
Plain text
  1. To get all the text present in an image
:mobile:ocr: text
Plain text

Eg.

Map< String, Object> params = new HashMap<>();
System.out.println(driver.executeScript("mobile:ocr:text",params));
Plain text
  1. Command to verify if any word exists or not in an image
:mobile:ocr:textExists
Plain text
Map< String, Object> params = new HashMap<>();
params.put("imageId", baseImageId);
params.put("word", "cleartrip");
System.out.println(driver.executeScript("mobile:ocr:textExists",params));
Plain text
  1. Command to find the “coordinates” of a word
:mobile:ocr:coordinate
Plain text

Eg.

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