DEV Community

GoScreen Api
GoScreen Api

Posted on

Exploring the Visual Diff Feature of GoScreenAPI

In the ever-evolving world of web development, ensuring consistency and accuracy in web design is paramount. As teams strive to deliver flawless user experiences, tools that streamline testing and comparison processes become indispensable. GoScreenAPI's Visual Diff feature stands out as an essential tool for developers and QA engineers alike, allowing for quick and precise comparisons of webpage screenshots.

In this article, we will take a deep dive into how to utilize the Visual Diff feature of GoScreenAPI, including a step-by-step guide with code snippets to help you integrate this functionality into your workflow effortlessly.

What is Visual Diff?

The Visual Diff feature allows you to compare two screenshots of a webpage side-by-side, highlighting the differences between them. This is particularly useful when checking for changes after updates, debugging design inconsistencies, or performing regression testing.

Getting Started with GoScreenAPI

Before we jump into the Visual Diff feature, ensure you have access to the GoScreenAPI. You can sign up for an account at GoScreenAPI and obtain your API key.

Basic Setup

Here's how to set up your project to use the GoScreenAPI Visual Diff feature:

  1. Install Dependencies: For demonstration purposes, we’ll use axios for making HTTP requests.
npm install axios
Enter fullscreen mode Exit fullscreen mode
  1. API Request: The following code snippet demonstrates how to capture two screenshots of a webpage and then create a visual diff between them.

Capturing Screenshots

const axios = require('axios');

async function captureScreenshots(url) {
    const options = {
        method: 'POST',
        url: 'https://api.goscreenapi.com/screenshot',
        headers: {
            'Authorization': `Bearer YOUR_API_KEY`,
            'Content-Type': 'application/json'
        },
        data: {
            url: url,
            output: 'url' // Specify output format as URL
        }
    };

    const response = await axios(options);
    return response.data.url;
}
Enter fullscreen mode Exit fullscreen mode

Creating a Visual Diff

Once you have two screenshots, you can create a visual diff by calling the Visual Diff API endpoint:


javascript
async function createVisualDiff(url1, url2) {
    const options = {
        method: 'POST',
        url: 'https://api.goscreenapi.com/visual-diff',
        headers: {
            '
Enter fullscreen mode Exit fullscreen mode

Top comments (0)