Protractor test reporting

If you are using either the Mocha or Jasmine test framework with Protractor, follow the instructions below to report results.

Installation

Mocha

npm install mocha-tesults-reporter --save

Jasmine

npm install jasmine-tesults-reporter --save

Configuration

Your Protractor conf.js file must contain the three properties below to have results upload to Tesults:

1. Framework

Set framework you are using

Mocha

framework: 'mocha'

Jasmine

framework: 'jasmine'

2. Reporter configuration

Mocha

Require the mocha-tesults-reporter in your conf.js

const tesultsReporter = require("mocha-tesults-reporter")

Have reporter in mochaOpts in the config set to reference the mocha-tesults-reporter:

mochaOpts: {
  reporter: tesultsReporter,
  reporterOptions: {
    'tesults-target': 'token',
    'tesults-config': '/path/tesults-config.js',
    'tesults-files': '/path-to-files/files',
    'tesults-build-name': '1.0.0',
    'tesults-build-description': 'build description',
    'tesults-build-reason': 'build failure reason (if failed)',
    'tesults-build-result': 'pass'
  }
}

View the Mocha reporter documentation for details on the optional tesults-config, tesults-files and tesults-build-* arguments.

The reporterOptions sets args for the mocha-tesults-reporter. The reporterOptions is optional because you can alternatively pass the args through the command line to Protractor. Doing this in the conf.js is convenient for values that do not change.

The alternative method of passing mocha-tesults-reporter args, without reporterOptions in mochaOpts using protractor command line:

protractor conf.js --disableChecks --reporter-option tesults-target=token
--reporter-option tesults-files=/path-files

Jasmine

Register the jasmine-tesults-reporter with Jasmine (this is required if using Jasmine).

onPrepare: function(){
  const tesultsReporter = require('jasmine-tesults-reporter');
  jasmine.getEnv().addReporter(tesultsReporter);
}

You would then run the tests by passing the tesults-target arg (see the Jasmine docs for more details)

protractor conf.js --  tesults-target=token

3. The afterLaunch function

Mocha and Jasmine

Protractor's afterLaunch function must be added to the conf.js and set to resolve a promise in order to allow asynchronous operations in reporters to complete before Protractor exits. Upload will not occur without this function being present in the conf.js.

afterLaunch: function (exitCode) {
  return new Promise(function (resolve) {});
}

Putting this altogether, a conf.js would resemble:

Mocha

const tesultsReporter = require("mocha-tesults-reporter")

exports.config = {
  framework: 'mocha',
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: ['todo-spec.js', 'todo-spec2.js'],
  mochaOpts: {
    reporter: tesultsReporter,
    slow: 3000,
    reporterOptions: {
      'tesults-target': 'token',
      'tesults-config': '/path/config.js',
      'tesults-files': '/path-to-files/files',
      'tesults-build-name': '1.0.0',
      'tesults-build-description': 'build description',
      'tesults-build-reason': 'build failure reason (if failed)',
      'tesults-build-result': 'pass'
    }
  },
  afterLaunch: function (exitCode) {
    return new Promise(function (resolve) {});
  }
};

Jasmine

exports.config = {
  framework: 'jasmine',
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: ['todo-spec.js', 'todo-spec2.js'],
  onPrepare: function(){
    const tesultsReporter = require('jasmine-tesults-reporter');
    jasmine.getEnv().addReporter(tesultsReporter);
  }
  afterLaunch: function (exitCode) {
    return new Promise(function (resolve) {});
  }
};

Back to Mocha or Jasmine

This completes Protractor specific configuration. Now continue viewing the Tesults Mocha or Tesults Jasmine documentation to complete setup.

Result Interpretation

Result interpretation is not currently supported by this integration. If you are interested in support please contact help@tesults.com.

Go to the Configuration menu.

Configuration menu

Select Build Consolidation.

When executing multiple test runs in parallel or serially for the same build or release, results are submitted to Tesults separately and multiple test runs are generated on Tesults. This is because the default behavior on Tesults is to treat each results submission as a separate test run.

This behavior can be changed from the configuration menu.

Build Consolidation

Click 'Build Consolidation' from the Configuration menu to enable and disable consolidation for a project or by target.

When build consolidation is enabled multiple test runs submitted at different times, with the same build name, will be consolidated into a single test run by Tesults automatically.

This is useful for test frameworks that run batches of test cases in parallel. If you do not have a build name to use for consolidation, consider using a timestamp set at the time the test run starts.

Build Replacement

When build consolidation is enabled, an additional option, build replacement can optionally be enabled too. Just as with build consolidation, when multiple test runs are submitted with the same build name the results are consolidated, but with replacement enabled, if there are test cases with the same suite and name received multiple times, the last received test case replaces an existing test case with the same suite and name. This may be useful to enable in situations where test cases are re-run frequently and you do not want new test cases to be appended and instead want them to replace older test cases. This option is generally best left disabled, unless test cases are often re-run for the same build and you are only interested in the latest result for the run.

Dynamically created test cases

If you dynamically create test cases, such as test cases with variable values, we recommend that the test suite and test case names themselves be static. Provide the variable data information in the test case description or other custom fields but try to keep the test suite and test name static. If you change your test suite or test name on every test run you will not benefit from a range of features Tesults has to offer including test case failure assignment and historical results analysis. You need not make your tests any less dynamic, variable values can still be reported within test case details.

Proxy servers

Does your corporate/office network run behind a proxy server? Contact us and we will supply you with a custom API Library for this case. Without this results will fail to upload to Tesults.

Have questions or need help? Contact us