< All Topics

Imagium can be integrated with Cypress.io using its out of box methods provided. Now visual testing with Cypress can be done with just snap of a finger and with utmost precision.

For more details on Imagium API’s check here

Documentation on cypress can be seen here

In the below sample code, change the parameters and file path according to your needs

var base43Image;

const path = require("path");

var testNameImagium = "Cypress Integration";
var projectKeyImagium = '7991bf3d-060d-481d-9da4-4b885373f58b';
var uidEndPointImagium = '';
var validateEndPointImagium = '';
var testUID;
var baseImage;
var step;
var pload = {"StepName": step, "TestRunID": testUID, "ImageBase64":  baseImage};

describe('My First Test', () => {
    it('Visit Google', () => {

      //Generate 'Test Run ID'
      //Use the same 'Test Run ID' for multiple steps in the same test case
    cy.request('POST',uidEndPointImagium,{"TestName": testNameImagium, "ProjectKey": projectKeyImagium }).then((resp) => {

      //Update the validate payload with test ID
     pload.TestRunID = resp.body;

    //Navigate to a URL

    //Generate a random file Name
    var imageName = "Image"+getRandomFileName();

    //Take screenshot and store at a particular location

    //Read the screenshot taken above and convert it into base64 image
      //Change the path according to your needs
    cy.readFile('./cypress/screenshots/examples/sample_spec.js/Imagium/'+imageName+".png", 'base64').then((b64) => {
      //Update validate paylod with base 64 image
      pload.ImageBase64 = b64;

    //Update the validate paylod with Step Name 
    pload.StepName = "Step1";

    //send request to validate the image
    cy.request('POST',validateEndPointImagium, pload).then((resp) => {

  //Function to generate a Random file name
  function getRandomFileName() {
    var timestamp = new Date().toISOString().replace(/[-:.]/g,"");  
    var random = ("" + Math.random()).substring(2, 8); 
    var random_number = timestamp+random;  
    return random_number;

Previous 7. Integration with Microsoft Playwright
Next 9. Integration with Python & Selenium
Table of Contents