DEV Community

GoScreen Api
GoScreen Api

Posted on

Unlocking the Power of Visual Diff with GoScreenAPI

In the fast-paced world of software development, maintaining visual consistency across applications is crucial. Whether you’re performing regular UI testing or ensuring that design updates align with your expectations, visual discrepancies can lead to user dissatisfaction. Enter GoScreenAPI, a powerful screenshot API that offers advanced features, including a standout capability: Visual Diff. In this article, we will explore how to effectively utilize the Visual Diff feature of GoScreenAPI to automate your visual testing process.

What is Visual Diff?

Visual Diff is a feature that allows developers to compare two images and highlight the differences between them. This is incredibly useful for identifying unintended changes in the UI after updates or bug fixes. By automating visual regression testing, GoScreenAPI streamlines the workflow, saving valuable time and reducing the risk of human error.

Getting Started with Visual Diff

To use the Visual Diff feature, you first need to set up your GoScreenAPI account and obtain your API key. Once you have that, you can start making API calls to compare screenshots.

Step 1: Take Screenshots

Start by taking screenshots of the baseline (original) and the new version of your application. This can be done using GoScreenAPI’s screenshot capabilities. Here is an example of how to take a screenshot using a simple HTTP request:

curl -X POST "https://api.goscreenapi.com/screenshot" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
  "url": "https://example.com",
  "full_page": false,
  "viewport": "1280x800"
}'
Enter fullscreen mode Exit fullscreen mode

Step 2: Compare Screenshots

Once you have your screenshots, you can use the Visual Diff endpoint to compare the two images. Here’s a sample request for performing a visual diff:

curl -X POST "https://api.goscreenapi.com/visual_diff" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
  "baseline_image": "BASELINE_IMAGE_URL",
  "new_image": "NEW_IMAGE_URL"
}'
Enter fullscreen mode Exit fullscreen mode

Step 3: Review the Results

The response will include a URL to the diff image that visually highlights the differences between the two screenshots. You can then review this image to identify any changes that need addressing.


json
{
Enter fullscreen mode Exit fullscreen mode

Top comments (0)