Skip to main content

Automated Screenshot API For Cross Browser Testing


Automated Screenshot API will help you capture full-page screenshots of any URL by invoking an API call to LambdaTest cloud servers. You can ensure cross browser compatibility of your website stays in check by performing bulk screenshot testing regularly. You can do that without logging into LambdaTest, by executing a JSON file in your preferred API development environment such as Postman.

This document will help you leverage LambdaTest Automated Screenshot. You would learn how to:

  • Fetch all OS + Browser combinations.
  • Fetch all Screen Resolutions.
  • Fetch Screenshots of an already performed test session.
  • Start a Screenshot Test Session
    1. Test your locally hosted web pages.
    2. Test web pages with basic authentication.
    3. Test web pages with a Callback URL.
  • Stop a Screenshot test.

Prerequisites


  • LambdaTest Authentication Credentials Ensure that you have your LambdaTest authentication credentials, i.e., your LambdaTest username, access key, and HubURL. You need to set them up as your environment variables. You can retrieve them from your LambdaTest automation dashboard by clicking on the key icon near the help button.

  • For Linux/Mac:

$ export LT_USERNAME= {YOUR_LAMBDATEST_USERNAME}

$ export LT_ACCESS_KEY= {YOUR_LAMBDATEST_ACCESS_KEY}

  • For Windows:

$ set LT_USERNAME= {YOUR_LAMBDATEST_USERNAME}

$ set LT_ACCESS_KEY= {YOUR_LAMBDATEST_ACCESS_KEY}

Fetch All OS + Browser Combinations


The below GET request will help you extract a list of all the combinations for (OS + Browser) offered by LambdaTest. You can download these combinations as a JSON file.

Requested URL:

https://api.lambdatest.com/screenshots/v1/os-browsers

Client URL would be as followed:

curl -X GET "https://api.lambdatest.com/screenshots/v1/os-browsers"
-H "accept: application/json" -H "Authorization: Basic 123456789abcdefghijklmno="

As you execute, you will find the Server response presented below.

{
"windows 10": {
"chrome": [
"74",
"73"
],
"firefox": [
"66",
"65"
],
"opera": [
"55",
"54"
]
},
"macos mojave": {
"chrome": [
"74",
"73"
],
"firefox": [
"66",
"65"
],
"opera": [
"55",
"54"
]
}
}

Fetch Every Screen Resolutions


To get a list of all the available screen resolutions provided by LambdaTest for you to perform cross browser testing, you would need to execute the below GET request. The GET request will help you extract the respective response from our cloud servers in a JSON format.

Requested URL:

https://api.lambdatest.com/screenshots/v1/resolutions

Client URL would be as followed:

curl -X GET "https://api.lambdatest.com/screenshots/v1/resolutions"
-H "accept: application/json" -H "Authorization: Basic 123456789abcdefghijklmno="

As you execute, you will find the Server response presented below.

{
"mac_res": [
"1024x768",
"1280x1024"
],
"win_res": [
"1024x768",
"1280x1024"
]
}

Fetch Details Of An Executed Test Session


In case you wish to fetch all the details from an already executed screenshot test session. These details will help you analyze the results of your screenshot test session at LambdaTest. You would get the below details:

  • Test Details:
    • Test ID
    • Test status
    • Defer time
    • Tested URL
    • Callback URL(if any)
  • Screenshot Details:
    • Operating System
    • Browser
    • Browser Version
    • Status
    • Screenshot URL
    • Thumbnail URL
    • Activity ID
    • Resolution

Requested URL:

https://api.lambdatest.com/screenshots/v1/Test ID

Note: Test ID is a mandatory field for making use of this GET request. This would fetch details in JSON format for all bulk screenshots captured in a test session specified by you.

Client URL would be:

curl -X GET "https://api.lambdatest.com/screenshots/v1/TES11111111111111111111111111"
-H "accept: application/json" -H "Authorization: Basic 123456789abcdefghijklmno="

Example Value:

  {
"test_id": "TES11111111111111111111111111",
"defer_time": 5,
"test_status": "completed",
"url": "https://www.lambdatest.com",
"callback_url": "https://www.example.com",
"screenshots": [
{
"os": "windows 10",
"browser": "chrome",
"browser_version": "74",
"status": "completed",
"screenshot_url": "https://s3.amazonaws.com/s3-screenshots/prod/ACT100968331562237283340194/screenshot/win-cr-74.0.png",
"thumbnail_url": "https://s3.amazonaws.com/s3-screenshots/prod/ACT100968331562237283340194/screenshot/win-cr-74.0.png",
"activity_id": "ACT100968331562237283340194",
"resolution": "1024x768"
}
]
}

Run A Screenshot Test


To start a screenshot test using the API, you would need to trigger the below POST request.

https://api.lambdatest.com/screenshots/v1

Client URL would be as followed:

curl -X POST "https://api.lambdatest.com/screenshots/v1" -H "accept: application/json" 
-H "Authorization: Basic 123456789abcdefghijklmno=" -H "Content-Type: application/json" -d "
{\"url\":\"https://www.lambdatest.com\",\"defer_time\":5,\"email\":true,\"mac_res\":\"1024x768\",
\"win_res\":\"1366X768\",\"configs\":{\"windows 10\":{\"chrome\":[\"74\"],\"firefox\":[\"66\"],
\"opera\":[\"58\"],\"ie\":[\"11\"]},\"macos mojave\":{\"chrome\":[\"74\"]}}}"

Example value:

{
"url": "https://www.lambdatest.com",
"defer_time": 5,
"email": true,
"mac_res": "1024x768",
"win_res": "1366X768",
"configs": {
"windows 10": {
"chrome": [
"74"
],
"firefox": [
"66"
],
"opera": [
"58"
],
"ie": [
"11"
]
},
"macos mojave": {
"chrome": [
"74"
]
}
}
}

Screenshot Testing For Locally Hosted Web Applications


To perform a screenshot test on your locally hosted web applications, you would need to declare the below parameter in your request before specifying the configurations:

"tunnel": true

Example Value:

{
"url": "https://www.lambdatest.com",
"defer_time": 5,
"email": true,
"tunnel": true,
"mac_res": "1024x768",
"win_res": "1366X768",
"configs": {
"windows 10": {
"chrome": [
"74",
"73"
]
}
}
}

Screenshot Test With Basic Authentication


Similarly, to perform a screenshot test on a web application with basic authentication, you would need to declare the below parameter in your request before specifying the configurations.

"url": "https://www.basic-auth.com",
"username": "username",
"password": "password",

Example:

{
"url": "https://www.basic-auth.com",
"defer_time": 5,
"email": true,
"mac_res": "1024x768",
"win_res": "1366X768",
"username": "username",
"password": "password",
"configs": {
"windows 10": {
"chrome": [
"74",
"73"
]


}
}
}

Route Test Details To Your Colleagues Through A Callback URL


By specifying a Callback URL, you can route your test details to a specific IP or a specific URL. This would help you to share your test results with your colleagues or to keep them on a specific URL, so you could come back and assess these results when you have time. To invoke a Callback URL, you would need to declare the below parameter in your request before specifying the configurations.

"callbackurl": "https://www.example.com",

Example Value:

{
"url": "https://www.lambdatest.com",
"defer_time": 5,
"email": true,
"mac_res": "1024x768",
"win_res": "1366X768",
"callbackurl": "https://www.example.com",
"configs": {
"windows 10": {
"chrome": [
"74",
"73"
]
}
}
}

Stop A Screenshot Test


In case you wish to stop a screenshot test, you can do so with the help of a PUT request. Test ID is again mandatory over here as you need to convey which particular screenshot test you would want to be aborted.

Requested URL:

https://api.lambdatest.com/screenshots/v1/stop/TES11111111111111111111
Client URL: curl -X PUT "https://api.lambdatest.com/screenshots/v1/stop/TES100962431563281759448763"
-H "accept: application/json" -H "Authorization: Basic 123456789abcdefghijklmno="

Note: This will terminate only a running test session. Providing a TestID of an already completed test session will provide you with a 404 error as the server response.