wdio-reportportal-reporter
Advanced tools
Comparing version 7.4.2 to 7.5.0
@@ -7,3 +7,4 @@ export declare enum EVENTS { | ||
RP_TEST_RETRY = "rp:testRetry", | ||
RP_TEST_ATTRIBUTES = "rp:testAttributes" | ||
RP_TEST_ATTRIBUTES = "rp:testAttributes", | ||
RP_SUITE_ATTRIBUTES = "rp:SuiteAttributes" | ||
} | ||
@@ -10,0 +11,0 @@ export declare enum STATUS { |
@@ -12,2 +12,3 @@ "use strict"; | ||
EVENTS["RP_TEST_ATTRIBUTES"] = "rp:testAttributes"; | ||
EVENTS["RP_SUITE_ATTRIBUTES"] = "rp:SuiteAttributes"; | ||
})(EVENTS = exports.EVENTS || (exports.EVENTS = {})); | ||
@@ -14,0 +15,0 @@ var STATUS; |
@@ -13,3 +13,5 @@ import Reporter from "@wdio/reporter"; | ||
static finishTestManually(test: any): void; | ||
private static getValidatedAttribute; | ||
static addAttribute(attribute: Attribute): void; | ||
static addAttributeToSuite(attribute: Attribute): void; | ||
private static reporterName; | ||
@@ -30,2 +32,3 @@ private launchId; | ||
private currentTestAttributes; | ||
private currentSuiteAttributes; | ||
constructor(options: any); | ||
@@ -47,2 +50,3 @@ onSuiteStart(suite: any): void; | ||
private addAttribute; | ||
private addAttributeToSuite; | ||
private finishTestManually; | ||
@@ -49,0 +53,0 @@ private sendLog; |
@@ -28,2 +28,3 @@ "use strict"; | ||
this.currentTestAttributes = []; | ||
this.currentSuiteAttributes = []; | ||
this.reporterOptions = Object.assign(new ReporterOptions_1.default(), options); | ||
@@ -56,3 +57,3 @@ this.registerListeners(); | ||
} | ||
static addAttribute(attribute) { | ||
static getValidatedAttribute(attribute) { | ||
if (!attribute) { | ||
@@ -77,4 +78,10 @@ throw new Error("Attribute should be an object"); | ||
} | ||
(0, utils_1.sendToReporter)(constants_1.EVENTS.RP_TEST_ATTRIBUTES, Object.assign({}, clonedAttribute)); | ||
return clonedAttribute; | ||
} | ||
static addAttribute(attribute) { | ||
(0, utils_1.sendToReporter)(constants_1.EVENTS.RP_TEST_ATTRIBUTES, Object.assign({}, this.getValidatedAttribute(attribute))); | ||
} | ||
static addAttributeToSuite(attribute) { | ||
(0, utils_1.sendToReporter)(constants_1.EVENTS.RP_SUITE_ATTRIBUTES, Object.assign({}, this.getValidatedAttribute(attribute))); | ||
} | ||
onSuiteStart(suite) { | ||
@@ -143,3 +150,3 @@ log.debug(`Start suite ${suite.title} ${suite.uid}`); | ||
const suiteItem = this.storage.getCurrentSuite(); | ||
const finishSuiteObj = suiteStatus === constants_1.STATUS.SKIPPED ? new entities_1.EndTestItem(constants_1.STATUS.SKIPPED, new entities_1.Issue("NOT_ISSUE")) : { status: suiteStatus }; | ||
const finishSuiteObj = suiteStatus === constants_1.STATUS.SKIPPED ? new entities_1.EndTestItem(constants_1.STATUS.SKIPPED, new entities_1.Issue("NOT_ISSUE")) : { status: suiteStatus, attributes: this.currentSuiteAttributes }; | ||
const { promise } = this.client.finishTestItem(suiteItem.id, finishSuiteObj); | ||
@@ -325,2 +332,5 @@ (0, utils_1.promiseErrorHandler)(promise); | ||
} | ||
addAttributeToSuite(attribute) { | ||
this.currentSuiteAttributes.push(attribute); | ||
} | ||
finishTestManually(event) { | ||
@@ -415,2 +425,3 @@ const testItem = this.storage.getCurrentTest(); | ||
process.on(constants_1.EVENTS.RP_TEST_ATTRIBUTES, this.addAttribute.bind(this)); | ||
process.on(constants_1.EVENTS.RP_SUITE_ATTRIBUTES, this.addAttributeToSuite.bind(this)); | ||
} | ||
@@ -417,0 +428,0 @@ now() { |
import {WDIO_TEST_STATUS, CUCUMBER_TYPE, STATUS} from "../constants"; | ||
import {suiteEndEvent, suiteStartEvent} from "./fixtures/events"; | ||
import {singleAttribute} from "./fixtures/attributes" | ||
import {getDefaultOptions, RPClientMock} from "./reportportal-client.mock"; | ||
@@ -24,3 +25,7 @@ | ||
id, | ||
{status: STATUS.PASSED}, | ||
{ | ||
status: STATUS.PASSED, | ||
attributes: [] | ||
}, | ||
); | ||
@@ -30,2 +35,22 @@ }); | ||
test("should set given attributes to endSuite", () => { | ||
const {id} = reporter.storage.getCurrentSuite(); | ||
reporter.addAttributeToSuite(singleAttribute) | ||
reporter.onSuiteEnd(suiteEndEvent()); | ||
expect(reporter.client.finishTestItem).toBeCalledTimes(1); | ||
expect(reporter.client.finishTestItem).toBeCalledWith( | ||
id, | ||
{ | ||
status: STATUS.PASSED, | ||
attributes: [ | ||
singleAttribute | ||
] | ||
}, | ||
); | ||
}) | ||
test("should set status as failing if there are failed tests", () => { | ||
@@ -48,6 +73,33 @@ const {id} = reporter.storage.getCurrentSuite(); | ||
id, | ||
{status: STATUS.FAILED}, | ||
{ | ||
status: STATUS.FAILED, | ||
attributes: [] | ||
}, | ||
); | ||
}); | ||
test("should set status as passed if all tests passed", () => { | ||
const {id} = reporter.storage.getCurrentSuite(); | ||
reporter.onSuiteEnd(Object.assign( | ||
suiteEndEvent(), | ||
{ | ||
tests: [ | ||
{ | ||
state: WDIO_TEST_STATUS.PASSED, | ||
}, | ||
{ | ||
state: WDIO_TEST_STATUS.PASSED, | ||
}, | ||
] | ||
})); | ||
expect(reporter.client.finishTestItem).toBeCalledWith( | ||
id, | ||
{ | ||
status: STATUS.PASSED, | ||
attributes: [] | ||
}, | ||
); | ||
}); | ||
test("should set status as passing for cucumber nested steps", () => { | ||
@@ -72,3 +124,6 @@ Object.assign(reporter.options, {cucumberNestedSteps: true}); | ||
id, | ||
{status: STATUS.PASSED}, | ||
{ | ||
status: STATUS.PASSED, | ||
attributes: [] | ||
}, | ||
); | ||
@@ -96,5 +151,8 @@ }); | ||
id, | ||
{status: STATUS.FAILED}, | ||
{ | ||
status: STATUS.FAILED, | ||
attributes: [] | ||
}, | ||
); | ||
}); | ||
}); |
@@ -8,2 +8,3 @@ export enum EVENTS { | ||
RP_TEST_ATTRIBUTES = "rp:testAttributes", | ||
RP_SUITE_ATTRIBUTES = "rp:SuiteAttributes", | ||
} | ||
@@ -10,0 +11,0 @@ |
@@ -56,3 +56,3 @@ import logger from "@wdio/logger"; | ||
public static addAttribute(attribute: Attribute) { | ||
private static getValidatedAttribute(attribute: Attribute): Attribute { | ||
if (!attribute) { | ||
@@ -76,5 +76,13 @@ throw new Error("Attribute should be an object") | ||
} | ||
sendToReporter(EVENTS.RP_TEST_ATTRIBUTES, {...clonedAttribute}); | ||
return clonedAttribute | ||
} | ||
public static addAttribute(attribute: Attribute) { | ||
sendToReporter(EVENTS.RP_TEST_ATTRIBUTES, {...this.getValidatedAttribute(attribute)}); | ||
} | ||
public static addAttributeToSuite(attribute: Attribute) { | ||
sendToReporter(EVENTS.RP_SUITE_ATTRIBUTES, {...this.getValidatedAttribute(attribute)}); | ||
} | ||
private static reporterName = "reportportal"; | ||
@@ -95,2 +103,3 @@ private launchId: string; | ||
private currentTestAttributes: Attribute[] = []; | ||
private currentSuiteAttributes: Attribute[] = [] | ||
@@ -177,3 +186,4 @@ constructor(options: any) { | ||
const suiteItem = this.storage.getCurrentSuite(); | ||
const finishSuiteObj = suiteStatus === STATUS.SKIPPED ? new EndTestItem(STATUS.SKIPPED, new Issue("NOT_ISSUE")) : {status: suiteStatus}; | ||
const finishSuiteObj = suiteStatus === STATUS.SKIPPED ? new EndTestItem(STATUS.SKIPPED, new Issue("NOT_ISSUE")) : {status: suiteStatus, attributes: this.currentSuiteAttributes}; | ||
const {promise} = this.client.finishTestItem(suiteItem.id, finishSuiteObj); | ||
@@ -374,2 +384,6 @@ promiseErrorHandler(promise); | ||
private addAttributeToSuite(attribute: Attribute){ | ||
this.currentSuiteAttributes.push(attribute) | ||
} | ||
private finishTestManually(event: any) { | ||
@@ -471,2 +485,3 @@ const testItem = this.storage.getCurrentTest(); | ||
process.on(EVENTS.RP_TEST_ATTRIBUTES, this.addAttribute.bind(this)); | ||
process.on(EVENTS.RP_SUITE_ATTRIBUTES, this.addAttributeToSuite.bind(this)); | ||
} | ||
@@ -473,0 +488,0 @@ |
@@ -104,2 +104,3 @@ // @ts-ignore | ||
export const parseTags = (text: string): string[] => ("" + text).match(TAGS_PATTERN) || []; | ||
@@ -106,0 +107,0 @@ |
{ | ||
"name": "wdio-reportportal-reporter", | ||
"version": "7.4.2", | ||
"version": "7.5.0", | ||
"description": "A WebdriverIO v6 plugin. Report results to Report Portal.", | ||
@@ -36,4 +36,4 @@ "main": "build/reporter.js", | ||
"dependencies": { | ||
"@wdio/logger": "^7.19.0", | ||
"@wdio/reporter": "^7.20.3", | ||
"@wdio/logger": "^7.26.0", | ||
"@wdio/reporter": "^7.28.0", | ||
"json-stringify-safe": "^5.0.1", | ||
@@ -40,0 +40,0 @@ "reportportal-js-client": "^2.2.1", |
WDIO Report Portal Reporter | ||
==================== | ||
[![Greenkeeper badge](https://badges.greenkeeper.io/BorisOsipov/wdio-reportportal-reporter.svg)](https://greenkeeper.io/) | ||
@@ -7,6 +8,8 @@ | ||
![npm](https://img.shields.io/npm/dm/wdio-reportportal-reporter) | ||
> A WebdriverIO reporter plugin to report results to Report Portal(http://reportportal.io/). | ||
> A WebdriverIO reporter plugin to report results to Report Portal(<http://reportportal.io/>). | ||
## Installation | ||
The easiest way is to keep `wdio-reportportal-reporter` and `wdio-reportportal-service` as a devDependency in your `package.json`. | ||
```json | ||
@@ -20,5 +23,9 @@ { | ||
``` | ||
Instructions on how to install `WebdriverIO` can be found [here](https://webdriver.io/docs/gettingstarted.html). | ||
## Configuration | ||
Configure the output directory in your wdio.conf.js file: | ||
```js | ||
@@ -77,31 +84,36 @@ const reportportal = require('wdio-reportportal-reporter'); | ||
Api methods can be accessed using: | ||
```js | ||
const reporter = require('wdio-reportportal-reporter') | ||
``` | ||
### Methods description | ||
* `reporter.addAttribute({key, value}) ` – add an attribute to current test. | ||
* `reporter.addAttribute({key, value})` – add an attribute to current test. | ||
* `key` (*string*, optional) - attribute key. It must be non-empty string. | ||
* `value` (*string*, required)– attribute value. It must be non-empty string. | ||
* `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.addAttributeToCurrentSuite({key, value})` - add an attribute to current suite. | ||
* `key` (*string*, optional) - attribute key. It must be non-empty string. | ||
* `value` (*string*, required)– attribute value. It must be non-empty string. | ||
* `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 | ||
* `message` (*string*)– log message content. | ||
* `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 | ||
* `message` (*string*)– log message content. | ||
* `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. | ||
* `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 | ||
* `message` (*string*)– log message content. | ||
* `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 | ||
* `message` (*string*)– log message content. | ||
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. | ||
@@ -112,2 +124,3 @@ | ||
Mocha example: | ||
```js | ||
@@ -132,2 +145,3 @@ const reportportal = require('wdio-reportportal-reporter'); | ||
Jasmine example: | ||
```js | ||
@@ -154,2 +168,3 @@ const reportportal = require('wdio-reportportal-reporter'); | ||
WDIO Cucumber "5.14.3+" Example: | ||
```js | ||
@@ -176,2 +191,3 @@ const reportportal = require('wdio-reportportal-reporter'); | ||
## Getting link to Report Portal UI launch page | ||
```js | ||
@@ -186,2 +202,3 @@ const RpService = require("wdio-reportportal-service"); | ||
``` | ||
or more complicated way | ||
@@ -208,4 +225,4 @@ | ||
```sh | ||
$ export REPORT_PORTAL_LAUNCH_ID=SomeLaunchId | ||
$ npm run wdio | ||
export REPORT_PORTAL_LAUNCH_ID=SomeLaunchId | ||
npm run wdio | ||
``` | ||
@@ -212,0 +229,0 @@ |
Sorry, the diff of this file is not supported yet
101516
36
2396
224
Updated@wdio/logger@^7.26.0
Updated@wdio/reporter@^7.28.0