Visual Testing Using API
  • 29 Mar 2023
  • 3 Minutes to read
  • Dark
    Light

Visual Testing Using API

  • Dark
    Light

Article Summary

Performing Visual Testing through API

  1. Authorization - This API enables users to authenticate. On successful authentication, the user will get a token.
curl -u "email:apiKey"< Cloud_URL>/api/access

Parameters -

  • email-your email id
  • accessKey-your access key (you will get it from Account Settings->API)

Response -

{"result":{"token":"yz8jn9********whbfgj","code":200}}
  1. Get Device
    request POST < Cloud_URL>/api/devices
curl -H "Content-Type: application/json" -d '{ "token":"authToken","duration":10, "platform":"platform", "available_now":"true"}'

Parameter Description

  • token: Authtoken (you can get this from the authenticate response)
  • duration: Duration in minutes (How many minutes you want the device for).
  • platform: Which platform devices (Android or iOS) you want to view.
  • available_now true or false.: True means display the available devices and false means display all devices (including busy and available).

Response -

{
"result": {
"token": "yz8jn9********whbfgj",
"code": 200,
"models": [
{
"index": 1,
"full_name": "Apple_iPadPro3rdGen_Ios_14.6.0_3f939",
"id": 780,
"alias_name": "3f939",
"model": "iPadPro3rdGen",
"display_name": "iPad Pro 3rd Gen",
"platform": "ios",
"version": "14.6.0",
"cpu": "Octa Core",
"bucket": 4,
"manufacturer": "Apple",
"mobile_number": "",
"dpi": "xxxhdpi",
"url": "https://device.pcloudy.com/device_images/small/iPad_Pro_3rdgen.png",
"ram": 6144,
"resolution": "2048x2732",
"display_area": 12.9,
"available": true
}
]
}
}
  1. Book Device
    request POST <Cloud_URL>/api/book_device
curl -H 'ContentType:application/json' -d '{"token":"authToken","duration":minutes, "id":device_id}'

Parameter Description

  • token: Authtoken (You will get this from the authenticate response)
  • duration: Duration in minutes (How many minutes do you want to book the device for?).
  • id: Device id (You will get this from the get devices api response).

Response -

{"result":{"token":"yz8jn9k********mwhbfgj","code":200,"rid":2320557}}
  1. Upload image
    request POST <Cloud_URL>/api/v2/visual/upload-image

    header 'token: ******************'

    form 'file=@"/file_path”

    Parameter Description

    • token: Authtoken (You will get this from the authenticate response)
    • Image(.png file)(Image that you wish to test)

Response -

{
"requestId": "566315c0-6827-485f-9667-255c356db66d",
"statusCode": 200,
"status": "success",
"message": "image.png uploaded successfully",
"data": {
"fileId": "5566fb19-0a23-420c-8d5c-851771152594",
"filename": "image.png"
}
}
  1. Get all text of the uploaded image: This api is used to get all the text present in the uploaded image
    request POST <Cloud_URL>/api/v2/ocr/text

    body '{"imageId":"b23e03ce-1cf2-41ab-9e0c- b8e91b8ed384","rid":2320539}'

    Parameter Description

    • token: Authtoken (You will get this from the authenticate response)
    • ImageID:(You will get this from the Upload image response.ie fileId)
    • Rid:(You will get this using book device api)

Response -

{
"requestId": "1bb75b3e-a7e9-4e82-9d5a-1a18044a65d5",
"statusCode": 200,
"status": "success",
"message": "OK",
"data": "No Service\n6:23 pmn\nAA\nfacebook.com\nfacebook\nMobile number or email address\nPassword\nLog In\nForgotten password?\nor\nCreate New Account\nEnglish (UK)\n93\nHRTST\nf\nAbout Help More\nMeta 2022"
}
  1. To verify a word is present in the image-This API enables the user to check if the word is there or not in the image

request POST <Cloud_URL>/api/v2//ocr/text-exists

--header 'token: 75c4g6**********smkpbhdyy'
--body '
{
"imageId":"5566fb19-0a23-420c-8d5c-851771152594",
"word":"amazon",
"rid":2320383
}'

Parameter Description

  • token: Authtoken (You will get this from the authenticate response)
  • ImageID:(You will get this from the Upload image response.ie fileId)
  • Rid:(You will get this using book device api)
  • word( Enter the word that you wish to verify)

Response -

{
"requestId": "862e515c-9caa-4bd4-8448-b80be834650b",
"statusCode": 200,
"status": "success",
"message": "OK",
"data": false
}
  1. To get the coordinates of a particular word

Note: There should not be space between the words.

request POST <Cloud_URL>/api/v2//ocr/text-coordinate

---header 'token: 75c4g6*********kpbhdyy'
--data-raw '{"imageId":"97256bf5-f3dc-4098-8a65-808b2d7c874c","word": "FACEBOOK", "rid": 2320389} '

Parameter Description

  • token: Authtoken (You will get this from the authenticate response)
  • ImageID:(You will get this from the Upload image response.ie fileId)
  • Rid:(You will get this using book device api)
  • word( Enter the word that you wish to verify)

Response -

{
"requestId": "862e515c-9caa-4bd4-8448-b80be834650b",
"statusCode": 200,
"status": "success",
"message": "OK",
"data": [
{
"WordText": "FACEBOOK",
"Left": 259,
"Top": 909,
"Height": 33,
"Width": 217
}
]
}

Note: if the user gives any word that is not there then they will get an empty response

{
"requestId": "7a1f7ab1-fb6f-4e23-92a2-d87dd244df2c",
"statusCode": 200,
"status": "success",
"message": "OK",
"data": []
}
  1. Compare two images - This API is used to compare two images and find the difference between the two images
    request POST <Cloud_URL>/api/v2/visual/imagecompare
--header 'token: 75c4g6r3********kpbhdyy'
----body '{
"firstImageId":"7f8c1426-48b0-467e-a05c-f9af917a09c8",
"secondImageId":"0e6a80da-8b34-4855-9208-961c647680d5",
"rid":2320383
}'

Parameter Description

  • token: Authtoken (You will get this from the authenticate response)
  • First ImageID:(You will get this from the Upload image response.ie fileId)
  • Second ImageID:(You will get this from the Upload image response.ie fileId)
  • Rid:(You will get this using book device api)

Response -

{
"requestId": "276fa242-4d92-4e0f-a5da-ccb308a230e1",
"statusCode": 200,
"status": "success",
"message": "OK",
"data": < base64>

Note: User needs to convert base64 to png. Differences will be highlighted


Was this article helpful?