Testim Documentation

Welcome to the Testim documentation. You'll find comprehensive guides to help you get started quickly, example code snippets, and tips for being more productive. You will also find details about advanced features that allow you to customize Testim to fit your environment or special testing conditions. Don't worry, we'll support you if you get stuck. Let's jump right in!

Guides    Changelog

Validate download

Validate that the download content is as expected

The download validation allows you to validate that the download content of various file types are as expected. You can check several parameters such as image type and dimensions in an image file, number of rows and content of a csv file, and number of slides and content in a MS PowerPoint document.

CSV file validation

You can use the Download Validation step to perform advanced validations of CSV files such as number of rows and content.

Example code:

const csvStr = fileBuffer.toString("utf8");
return csv({
  noheader: true,
  output: "csv"
})
  .fromString(csvStr)
  .then(csvRow => {
    if (csvRow.length !== parseInt(expectedNumOfRows)) {
      return Promise.reject(
        new Error(`Number of rows doesn't match ${csvRow.length}`)
      );
    }
    if (csvRow[0][0] !== expectedText) {
      return Promise.reject(
        new Error(`Failed to find expected text ${csvRow[0][0]}`)
      );
    }
  });

Parameters - Packages and JavaScript used in this example:

1.name: csv, type: Package, value: [[email protected]]
2.name: expectedNumOfRows, type: JavaScript, value: '2'
3.name: expectedText, type: JavaScript, value: 'dfdf'

see screenshot:

Image file validation

You can use the Download Validation step to perform advanced validations of image files such as type and dimensions.

Example code:

var dimensions = sizeOf(fileBuffer);
var {width, height, type} = dimensions;
console.log("Image dimensions", JSON.stringify(dimensions));

return width === parseInt(expectedWidth) &&
       height === parseInt(expectedHeight) &&
       type === expectedImageType &&
       fileName.includes(expectedName);

Parameters - Packages and JavaScript used in this example:

  1. name: sizeOf, type: Package, value: [email protected]
  2. name: expectedName, type: JavaScript, value: 'babybot'
  3. name: expectedImageType, type: JavaScript, value: 'jpg'
  4. name: expectedWidth, type: JavaScript, value: '260'
  5. name: expectedHeight, type: JavaScript, value: '260'

see screenshot:

MS Excel file validation

You can use the Download Validation step to perform advanced validations of Excel files such as number of sheets and content.

Example code:

const { SheetNames, Sheets } = XLSX.read(fileBuffer);

if (SheetNames.length !== parseInt(expectedNumOfSheets)) {
  throw new Error(`Number of ssheets doesn't match ${SheetNames.length}`);
}

const sheet = Sheets[SheetNames[0]];
const sheetAsJson = XLSX.utils.make_json(sheet);
if (sheetAsJson.length !== 4 || sheetAsJson[0].Name !== "Rajeev Singh") {
  throw new Error(`Failed to validate sheet 1`);
}
console.log("sheet", JSON.stringify(sheetAsJson));

Parameters - Packages and JavaScript used in this example:

1.name: XLSX, type: Package, value: [email protected]
2.name: expectedNumOfSheets, type: JavaScript, value: '2'

see screenshot:

MS PowerPoint validation

You can use the Download Validation step to perform advanced validations of PowerPoint files such as number of slides and content.

Example code:

var zip = new JSZip(fileBuffer);
var doc = new Docxtemplater();
doc.loadZip(zip);
const slides = Object.keys(doc.zip.files).filter(
  fileName =>
    _.startsWith(fileName, "ppt/slides/") && _.endsWith(fileName, ".xml")
);
console.log("Num of slides:", slides.length);

if (slides.length !== parseInt(excpectedNumOfSlides)) {
  return false;
}

expectedText = JSON.parse(expectedText);

expectedText.forEach(item => {
  const { slideIndex, text } = item;
  const slideText = doc.getFullText(slides[slideIndex]);
  if (!slideText.includes(text)) {
    throw new Error(`Failed to find ${text} in slide index: ${slideIndex}`);
  }
});

Parameters - Packages and JavaScript used in this example:

1.name: Docxtemplater, type: Package, value: [email protected]
2.name: jszip, type: Package, value: [email protected]*
3.name: expectedText, type: JavaScript, value: '[{"slideIndex":0,"text":"Sample PowerPoint File"},{"slideIndex":1,"text":"This is a Sample Slide"}]'
4.name: _, type: Package, value: [email protected]
5.name: excpectedNumOfSlides, type: JavaScript, value: '2'

see screenshot:

MS Word file validation

You can use the Download Validation step to perform advanced validations of Word files such as content.

Example code:

var zip = new JSZip(fileBuffer);
var doc = new Docxtemplater();

doc.loadZip(zip);
var docxText = doc.getFullText();
console.log("text:", docxText);

return docxText.includes(expectedText);
  1. name: Docxtemplater, type: Package, value: [email protected]
  2. name: JSZip, type: Package, value: [email protected]*
  3. name: expectedText, type: JavaScript, value: 'DOCX test file'
    see screenshot:

PDF file validation

You can use the Download Validation step to perform advanced validations of PDF files such as number of lines and content.

Example code:

return pdf(fileBuffer).then((data) => {
  const {numpages, text} = data;
  // number of pages
  console.log("numpages", numpages);
  // PDF text
  console.log("text", text);
  if(numpages !== parseInt(expectedNumOfPages)) {
    return Promise.reject(new Error(`Invalid number of pages: ${numpages}`));
  }
  if(!text.includes(expectedText)) {
    return Promise.reject(new Error(`Invalid pdf text: ${text}`));
  }
});

Parameters - Packages and JavaScript used in this example:

  1. name: pdf, type: Package, value: [email protected]
  2. name: expectedNumOfPages, type: JavaScript, value: '2'
  3. name: expectedText, type: JavaScript, value: 'A Simple PDF File'

Chrome browser requirements

This feature is supported in Chrome version 67 and above.
It requires a change to your Chrome browser settings:

  1. Open Chrome, go to Settings -> Advanced -> Privacy and security -> Content settings -> PDF documents (you should also be able to copy this direct link and paste it to a Chrome window: chrome://settings/content/pdfDocuments
  2. Enable the setting:

Updated about a month ago

Validate download


Validate that the download content is as expected

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.