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

Last updated: Mar 11, 2019 16:59

Table of Contents

Download

Download Reporting SDK client for your programming languages and framework

DigitalZoom Reporting Authoring

The following code changes are required to include reporting in your test:

The below snippets are a standalone script that does not use any execution testing framework.

Mandatory

Create the Reporting client

Add the following require statement to the test script:

const Reporting = require('perfecto-reporting');

Create an instance of the reporting client

Create an instance of the ReportiumClient used to log test start/step/end events:

function setupReportingClient(webdriver) {
  // Setup Perfecto reporting client
  const perfectoExecutionContext = new Reporting.Perfecto.PerfectoExecutionContext({
    webdriver
  });
  return new Reporting.Perfecto.PerfectoReportingClient(perfectoExecutionContext);
}

Special Note for users of admc/wd for Node.js: When creating the reporting client instance use the following code -

function setupReportingClient(webdriver) {
   const perfectoExecutionContext = new Reporting.Perfecto.PerfectoExecutionContext({
      webdriver: {
         executeScript: (command, params) => webdriver.execute(command, [params]),
         getCapabilities: webdriver.getCapabilities
      }
    });
   return new Reporting.Perfecto.PerfectoReportingClient(perfectoExecutionContext);
}

Optional changes (but highly recommended)

Adding reporting Tags

Add Tags are used as a freestyle text that is used for filtering in the Reporting app.
For example: tags: ['optional tag 1', 'optional tag 2'] 

Adding CI Job Information

Job information is used to add your test runs to the CI Dashboard. Use the Reporting.Model.Job method, supplying the Job Name, Job Number, and Branch Name, when creating the Reporting-client instance.

function setupReportingClient(webdriver) {
  // Setup Perfecto reporting client
  const perfectoExecutionContext = new Reporting.Perfecto.PerfectoExecutionContext({
    webdriver,
	// Job method accepts a JSON list with three optional properties
	job: new Reporting.Model.Job({
		jobName: "Job name" , 
		buildNumber: 1234, 
		branch: "Branch name"
		}), // optional
    project: new Reporting.Model.Project("Project name" , "v0.1"), // optional
    tags: ['optional tag 1', 'optional tag 2'] // optional
  });
  return Reporting.Perfecto.PerfectoReportingClient(perfectoExecutionContext);
}

Adding Custom Fields

Create new CustomField instances and add them to your test runs, either to the PerfectoExecutionContext when setting up the ReportingClient or to the specific TestContext instance as part of the testStart() invocation, as shown below.

Custom fields in PerfectoExecutionContext
function setupReportingClient(webdriver) {
  // Setup Perfecto reporting client
  const perfectoExecutionContext = new Reporting.Perfecto.PerfectoExecutionContext({
    webdriver,
...
    customFields: [new Reporting.Model.CustomField('testIndex', '1')] // optional custom fields
  });
  return Reporting.Perfecto.PerfectoReportingClient(perfectoExecutionContext);
}

Starting a new test

reportingClient.testStart('Start test: testSearch', new Reporting.Perfecto.PerfectoTestContext(
  ['additionalTag'],          // optional tags for execution context tags
  [new Reporting.Model.CustomField('testIndex', '1')] // optional custom fields that will be added and override duplicated fields from execution context custom fields
)

Note: The PerfectoTestContext is a structure that adds context-sensitive information to the test started by this command. This is optional, and can be used to add tags and custom fields that will later be used by DigitalZoom when showing the test reports.

Adding test steps

Separate your test into actions using test steps.

...//selenium code
reportingClient.stepStart('Do this');
...//selenium code
reportingClient.stepEnd(); // the message parameter is optional

Stopping the test

...//selenium code
reportingClient.stepStart('Do that');
    // More Selenium code...
reportingClient.stepEnd(); // the message parameter is optional
    reportingClient.testStop({
      status: Reporting.Constants.results.passed
    });
  } catch (err) {
    reportingClient.testStop({
      status: Reporting.Constants.results.failed,
      message: JSON.stringify(err)
    });
  }
}

Adding assertions to the Execution Report

At various points within a test execution, the script may perform verification of different test conditions. The result of these verification may be added to the Test Report by using the reportingAssertion() method of the ReportiumClient instance. When using this method, the script includes two parameters:

  • A message string - that will be used to label the assertion.
  • A Boolean - indicates the result of the verification operation.
// Step3: Validate the text 'images' appears in the URL
reportingClient.stepStart('Step3: Validate the text "images" appears in the URL');
const currentUrl = driver.getCurrentUrl();	
reportingClient.reportiumAssert('Assert url', currentUrl == expectedUrl);
reportingClient.stepEnd('Step 3: Finished');

Getting the report URL

//retrieve the report URL
reportingClient.getReportUrl()
        .then((url) => {
          console.log(`Report url ${url}`);
        });

GitHub Samples

Protractor

Protractor-Cucumber

Protractor-Jasmine

Protractor-Mocha

WebdriverIO

NightwatchJS

Browse Perfecto GitHub repo for complete JavaScript Reporting samples

Protractor guide

Click here for a getting started with Protractor guide