Skip to content

Commit

Permalink
Several bugfixes and code cleanup(#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
AmsterGet committed Aug 28, 2020
1 parent 8e6d28a commit 1c4d62a
Show file tree
Hide file tree
Showing 8 changed files with 211 additions and 125 deletions.
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ Example:

## Step reporting configuration

By defaut, this agent report the following structure:
By default, this agent reports the following structure:

- feature - SUITE
- scenario - TEST
Expand All @@ -177,6 +177,28 @@ To report your steps as logs, you need to pass an additional parameter to the ag

This will report your your steps with logs to a log level without creating statistics for every step.

## Reporting skipped cucumber steps as failed

By default, cucumber marks steps which follow a failed step as `skipped`.
When `scenarioBasedStatistics` is set to `false` (the default behavior)
Report Portal reports these steps as failures to investigate.

To change this behavior and instead mark skipped steps which follow a failed step as `cancelled`,
you need to add an additional parameter to the agent config: `"reportSkippedCucumberStepsOnFailedTest": false`

```json
{
"token": "${rp.token}",
"endpoint": "${rp.endpoint}/api/v1",
"launch": "${rp.launch}",
"project": "${rp.your_project}",
"takeScreenshot": "onFailure",
"reportSkippedCucumberStepsOnFailedTest": false
}
```

Steps which are marked as `skipped` that do not follow a failed step will continue to mark the step and the scenario as `skipped`.

## Attachments

Attachments are being reported as logs. You can either just attach a file using cucumber's `this.attach` or specify log level and message:
Expand Down
24 changes: 24 additions & 0 deletions modules/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const STATUSES = {
CANCELLED: 'cancelled',
INFO: 'info',
WARN: 'warn',
STARTED: 'started',
PENDING: 'pending',
NOT_IMPLEMENTED: 'not_implemented',
UNDEFINED: 'undefined',
Expand Down Expand Up @@ -61,11 +62,34 @@ const RP_EVENTS = {
STATUS: 'rp/status',
};

// @see https://github.com/Automattic/cli-table#custom-styles
const TABLE_CONFIG = {
chars: {
top: '',
'top-left': '',
'top-mid': '',
'top-right': '',
mid: '',
'left-mid': '',
'mid-mid': '',
'right-mid': '',
bottom: '',
'bottom-left': '',
'bottom-mid': '',
'bottom-right': '',
},
style: {
head: [],
border: [],
},
};

module.exports = {
AFTER_HOOK_URI_TO_SKIP,
RP_ENTITY_LAUNCH,
STATUSES,
LOG_LEVELS,
CUCUMBER_EVENTS,
RP_EVENTS,
TABLE_CONFIG,
};
43 changes: 29 additions & 14 deletions modules/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

const { cleanContext } = require('./utils');
const itemFinders = require('./itemFinders');

class Context {
constructor() {
Expand All @@ -31,14 +32,15 @@ class Context {

findStep(event) {
let stepObj = null;
const stepSourceLocation = this.context.stepDefinitions.steps[event.index];
const stepDefinition = this.context.stepDefinitions.steps[event.index];

if (stepSourceLocation.sourceLocation) {
this.context.isBeforeHook = false;
if (stepDefinition.hookType) {
stepObj = { keyword: stepDefinition.hookType };
} else {
this.context.scenario.steps.forEach((step) => {
if (
stepSourceLocation.sourceLocation.uri === event.testCase.sourceLocation.uri &&
stepSourceLocation.sourceLocation.line === step.location.line
stepDefinition.sourceLocation.uri === event.testCase.sourceLocation.uri &&
stepDefinition.sourceLocation.line === step.location.line
) {
stepObj = step;
}
Expand All @@ -47,25 +49,38 @@ class Context {
if (this.context.background) {
this.context.background.steps.forEach((step) => {
if (
stepSourceLocation.sourceLocation.uri === event.testCase.sourceLocation.uri &&
stepSourceLocation.sourceLocation.line === step.location.line
stepDefinition.sourceLocation.uri === event.testCase.sourceLocation.uri &&
stepDefinition.sourceLocation.line === step.location.line
) {
stepObj = step;
}
});
}
} else {
stepObj = { keyword: this.context.isBeforeHook ? 'Before' : 'After' };
}
return stepObj;
}

countFailedScenarios(uri) {
if (this.context.failedScenarios[uri]) {
this.context.failedScenarios[uri]++;
} else {
this.context.failedScenarios[uri] = 1;
countTotalScenarios(feature, featureUri) {
let total = feature.children.length;
feature.children.forEach((child) => {
if (child.examples) {
child.examples.forEach((ex) => {
total += ex.tableBody.length - 1;
});
}
});
this.context.background = itemFinders.findBackground(feature);
if (this.context.background) {
total -= 1;
}

this.context.scenariosCount[featureUri] = { total, done: 0 };
}

incrementFailedScenariosCount(uri) {
this.context.failedScenarios[uri] = this.context.failedScenarios[uri]
? this.context.failedScenarios[uri] + 1
: 1;
}

resetContext() {
Expand Down
Loading

0 comments on commit 1c4d62a

Please sign in to comment.