Protractor test reporting

Using the Mocha test framework with Protractor? Follow the instructions below to report results.

Installation

npm install mocha-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 to mocha in the config:

framework: 'mocha'

2. mochaOpts

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

mochaOpts: {
  reporter: 'mocha-tesults-reporter',
  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'
  }
}

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

3. afterLaunch function

Protractor's afterLaunch function must be added to the conf.js and set to resolve a promise in order to allow asynchronous operations in the mocha-tesults-reporter 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:

exports.config = {
  framework: 'mocha',
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: ['todo-spec.js', 'todo-spec2.js'],
  mochaOpts: {
    reporter: 'mocha-tesults-reporter',
    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) {});
  }
};

Back to Mocha

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

Consolidating multiple test results submissions into one test run

If you execute multiple test runs in parallel or serially for the same build or release and results are submitted to Tesults within each run, separately, you will find that 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. Click 'Results Consolidation By Build' from the Configure Project menu to enable and disable consolidation by target. Enabling consolidation will mean that multiple test runs submitted with the same build name will be consolidated into a single test run.

Dynamically created test cases should have static names

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. This way you will you 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