Page tree
Skip to end of metadata
Go to start of metadata

Last updated: Feb 13, 2019 05:55

by Prasant Sutaria

Perfecto's Digital Zoom API has option to download test execution summary report in the form of PDF. Please visit this page for more details 

Step-by-step guide

  1. In your NodeJS based framework, please add the following function:

    Download PDF
    function downloadPDF(baseUrl,securityToken,jobName,jobNumber){
    
        deferred = protractor.promise.defer();
    
        stream = fs.createWriteStream("./report.pdf");
        var options = {
            "hostname":baseUrl,
            "port":443,
            "path":"/export/api/v1/test-executions/pdf?jobName%5B0%5D=" + jobName + "&jobNumber%5B0%5D=" + jobNumber,
            "headers":{
                "PERFECTO_AUTHORIZATION":securityToken
            }
        };
        
        https.get(options, function(response,cb) {
    
            response.pipe(stream);
    
            stream.on('finish', function () {
                stream.close(cb);
                deferred.fulfill('Download completed');
            });
    
          }).on('error', function(e) {
            deferred.reject(e + ' for downloading report ');
          });
    
          return deferred.promise;
      }
  2. Call the above function after the test execution is complete. 

    To check whether the test execution is complete or not one can call test results API and check following properties:

    Conditions
    a. responseJSON.resources.length > 0
    b. responseJSON.metadata.processingStatus == "PROCESSING_COMPLETE"

Example Usage of Above method:

A command line base JS tool to download Test Summary result in PDF format:

Command Line tool
const readline = require('readline');
var fs = require('fs');
const https= require('https');

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

// Reading Input from User
rl.question('Please provide Cloud Url without protocol: ', (answer) => {
  var cloudUrl;
  var securityToken;
  var jobName;
  var jobNumber;
  
  cloudUrl = answer;

  if(cloudUrl==""){
  	console.log("Cloud Url can't be Empty!!");
  	rl.close();
  	process.exit(1);
  }

  rl.question('Please provide Cloud Security Token: ', (answer) => {
	  securityToken = answer;
	  if(securityToken==""){
	  	console.log("Security token can't be Empty!!");
	  	rl.close();
	  	process.exit(1);
	  }
	  rl.question('Please provide Job Name: ', (answer) => {
		  jobName = answer;
		  if(jobName==""){
		  	console.log("Job Name can't be Empty!!");
		  	rl.close();
		  	process.exit(1);
		  }
		  rl.question('Please provide Job Number: ', (answer) => {
			  jobNumber = answer;
			  if(jobNumber==""){
			  	console.log("Job Number can't be Empty!!");
			  }else{
			  	downloadPDF(cloudUrl,securityToken,jobName,jobNumber);
			  }
			  
			  rl.close();
		  });
	  });	  
	});
});

// Download pdf using Reportium API
function downloadPDF(baseUrl,securityToken,jobName,jobNumber){

    stream = fs.createWriteStream("./report.pdf");

    var options = {
        "hostname":baseUrl,
        "port":443,
        "path":"/export/api/v1/test-executions/pdf?jobName%5B0%5D=" + jobName + "&jobNumber%5B0%5D=" + jobNumber,
        "url":baseUrl,
        "headers":{
            "PERFECTO_AUTHORIZATION":securityToken
        }
    };
        
    https.get(options, function(response,cb) {
        response.pipe(stream);
        stream.on('finish', function () {
            stream.close(cb);
            console.log("Download Completed. Please check current folder to find result.pdf");
        });
      }).on('error', function(e) {
        console.log("Error Occured - " + e);
      });
  }

How to use above code?

  1. Create a new file as cli_report_summary.js
  2. Copy above code and paste it in cli_report_summary.js
  3. Open a terminal and navigate to folder in which cli_report_summary.js file is saved

Run following command:

Command to run cli tool
node cli_report_summary.js

5. The tool will prompt for required parameter:

6. After providing all the required information, the tool will generate the summary pdf in the correct directory of the script.

Other ways to download summary result:

1. Using Postman: Download Executions Report using REST API call

2. Using Curl command - Curl Command Samples

Related articles