GithubHelp home page GithubHelp logo

jpaolini / wdio-reportportal-reporter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from borisosipov/wdio-reportportal-reporter

0.0 1.0 0.0 546 KB

A WebdriverIO plugin. Report results to Report Portal.

License: MIT License

TypeScript 100.00%

wdio-reportportal-reporter's Introduction

WDIO Report Portal Reporter

Greenkeeper badge Build Status npm npm

A WebdriverIO v5 reporter plugin to report results to Report Portal(http://reportportal.io/). For v4 version see this branch For Report Portal v4 use 5.X.X releases

Installation

The easiest way is to keep wdio-reportportal-reporter and wdio-reportportal-service as a devDependency in your package.json.

{
  "devDependencies": {
    "wdio-reportportal-reporter": "6.0.0",
    "wdio-reportportal-service": "6.0.0"
  }
}

Instructions on how to install WebdriverIO can be found here.

Configuration

Configure the output directory in your wdio.conf.js file:

const reportportal = require('wdio-reportportal-reporter');
const RpService = require("wdio-reportportal-service");

const conf = {
  reportPortalClientConfig: { // report portal settings
    token: '00000000-0000-0000-0000-00000000000',
    endpoint: 'https://reportportal-url/api/v1',
    launch: 'launch_name',
    project: 'project_name',
    mode: 'DEFAULT',
    debug: false,
    description: "Launch description text",
    attributes: [{key:"tag", value: "foo"}],
    headers: {"foo": "bar"} // optional headers for internal http client
  },
  reportSeleniumCommands: false, // add selenium commands to log
  seleniumCommandsLogLevel: 'debug', // log level for selenium commands
  autoAttachScreenshots: false, // automatically add screenshots
  screenshotsLogLevel: 'info', // log level for screenshots
  parseTagsFromTestTitle: false, // parse strings like `@foo` from titles and add to Report Portal
  cucumberNestedSteps: false, // report cucumber steps as Report Portal steps
  autoAttachCucumberFeatureToScenario: false // requires cucumberNestedSteps to be true for use
};

exports.config = {
  // ...
  services: [[RpService, {}]],
  reporters: [[reportportal, conf]],
  // ...
};

Complete guide with a project sample demonstrating integration of WebdriverIO with Report Portal

See readme in wdio-rp-integration-demoC

Additional API

Api methods can be accessed using:

const reporter = require('wdio-reportportal-reporter')

Methods description

  • reporter.sendLog(level, message) – send log to current suite\test item.
    • level (string) - log level. Values ['trace', 'debug', 'info', 'warn', 'error'].
    • message (String)– log message content.
  • reporter.sendFile(level, name, content, [type]) – send file to current suite\test item.
    • level (string) - log level. Values ['trace', 'debug', 'info', 'warn', 'error'].
    • name (string)– file name.
    • content (String) – attachment content
    • type (String, optional) – attachment MIME-type, image/png by default
  • reporter.sendLogToTest(test, level, message) - send log to specific test.
    • test (object) - test object from afterTest\afterStep wdio hook
    • level (string) - log level. Values ['trace', 'debug', 'info', 'warn', 'error'].
    • message (String)– log message content.
  • reporter.sendFileToTest(test, level, name, content, [type]) – send file to to specific test.
    • test (object) - test object from afterTest\afterStep wdio hook
    • level (string) - log level. Values ['trace', 'debug', 'info', 'warn', 'error'].
    • name (string)– file name.
    • content (String) – attachment content
    • type (string, optional) – attachment MIME-type, image/png by default

Pay attention: sendLog\sendFile sends log to current running test item. It means if you send log without active test(e.g from hooks or on suite level) it will not be reported Report Portal UI.

Methods sendLogToTest\sendFileToTest are useful when you need to send screenshots or logs to the failed test item from wdio afterTest hook.

Mocha example:

const reportportal = require('wdio-reportportal-reporter');
const path = require('path');
const fs = require('fs');

exports.config = {
...
  afterTest(test) {
    if (test.passed === false) {
      const filename = "screnshot.png";
      const outputFile = path.join(__dirname, filename);
      browser.saveScreenshot(outputFile);
      reportportal.sendFileToTest(test, 'info', filename, fs.readFileSync(outputFile));
    }
  }
...

WDIO Cucumber "5.14.3+" Example:

const reportportal = require('wdio-reportportal-reporter');

exports.config = {
...
   afterStep: function (uri, feature, { error, result, duration, passed }, stepData, context) {
     if (!passed) {
        let failureObject = {};
        failureObject.type = 'afterStep';
        failureObject.error = error;
        failureObject.title = `${stepData.step.keyword}${stepData.step.text}`;
        const screenShot = global.browser.takeScreenshot();
        let attachment = Buffer.from(screenShot, 'base64');
        reportportal.sendFileToTest(failureObject, 'error', "screnshot.png", attachment);
    }
  }
...
}

Getting link to Report Portal UI launch page

const RpService = require("wdio-reportportal-service");
...
    onComplete: async function (_, config) {
        const link = await RpService.getLaunchUrl(config);
        console.log(`Report portal link ${link}`)
    }
...

or more complicated way

const RpService = require("wdio-reportportal-service");
...
    onComplete: async function (_, config) {
        const protocol = 'http:';
        const hostname = 'example.com';
        const port = ':8080'; // or empty string for default 80/443 ports
        const link = await RpService.getLaunchUrlByParams(protocol, hostname, port, config);
        console.log(`Report portal link ${link}`)
    }
...

Reporting test to existing launch

If you want report test to existing active launch you may pass it to reporter by environment variable REPORT_PORTAL_LAUNCH_ID You are responsible for finishing launch as well as starting such launch.

$ export REPORT_PORTAL_LAUNCH_ID=SomeLaunchId
$ npm run wdio

License

This project is licensed under the MIT License - see the LICENSE.md file for details

wdio-reportportal-reporter's People

Contributors

borisosipov avatar caiogondim avatar dependabot[bot] avatar greenkeeper[bot] avatar jpaolini avatar tamil777selvan avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.