Skip to content

Commit

Permalink
Leveraged recent change to WDIO where hooks are reported separate fro…
Browse files Browse the repository at this point in the history
…m tests. Hooks will now show as an array under a suite.
  • Loading branch information
Jim Davis committed Sep 8, 2016
1 parent 2c48096 commit 6d5ff56
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 8 deletions.
58 changes: 54 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ This project was derived from the 'wdio-junit-reporter' found [here](https://git

## Installation

The easiest way is to keep `wdio-json-reporter` as a devDependency in your `package.json`.
The easiest way is to keep `wdio-json-reporter` as a dependency in your `package.json`.

```json
{
"devDependencies": {
"wdio-json-reporter": "~0.0.1"
"dependencies": {
"wdio-json-reporter": "~0.1.0"
}
}
```

You can simply do it by:

```bash
npm install wdio-json-reporter --save-dev
npm install wdio-json-reporter --save
```

Instructions on how to install `WebdriverIO` can be found [here](http://webdriver.io/guide/getstarted/install.html).
Expand Down Expand Up @@ -90,6 +90,47 @@ module.exports = {
"errorType": "CommandError",
"standardError": "CommandError: element (#not-a-real-element) still not visible after 5000ms\n at Object.Future.wait (/node_modules/fibers/future.js:449:15)\n at Object.waitForVisible (/node_modules/wdio-sync/build/index.js:345:27)\n at Object.create.searchForStores.value (/PageObjects/some.page.js:15:17)\n at Context.<anonymous> (/Tests/sample.spec.js:64:25)\n at /node_modules/wdio-sync/build/index.js:579:24\n - - - - -\n at elements(\"#not-a-real-element\") - isVisible.js:49:17\n at isVisible(\"#not-a-real-element\") - waitForVisible.js:40:22"
}
],
"hooks": [
{
"start": "2016-09-08T12:50:51.829Z",
"end": "2016-09-08T12:50:54.475Z",
"duration": 2646,
"title": "\"before each\" hook",
"associatedSuite": "sample test suite number 1",
"associatedTest": "@Smoke-Sample test number 1"
},
{
"start": "2016-09-08T12:50:57.672Z",
"end": "2016-09-08T12:50:57.672Z",
"duration": 0,
"title": "\"after each\" hook",
"associatedSuite": "sample test suite number 1",
"associatedTest": "@Smoke-Sample test number 1"
},
{
"start": "2016-09-08T12:51:51.829Z",
"end": "2016-09-08T12:51:54.475Z",
"duration": 2646,
"title": "\"before each\" hook",
"associatedSuite": "sample test suite number 1",
"associatedTest": "@Smoke-Sample test number 2"
},
{
"start": "2016-09-08T12:51:57.672Z",
"end": "2016-09-08T12:51:57.672Z",
"duration": 0,
"title": "\"after each\" hook",
"associatedSuite": "sample test suite number 1",
"associatedTest": "@Smoke-Sample test number 2"
},
{
"start": "2016-09-08T12:50:57.672Z",
"end": "2016-09-08T12:50:57.672Z",
"duration": 0,
"title": "\"after all\" hook",
"associatedSuite": "sample test suite number 1"
}
]
},
{
Expand All @@ -115,6 +156,15 @@ module.exports = {
"errorType": "CommandError",
"standardError": "CommandError: element (#not-a-real-element) still not visible after 5000ms\n at Object.Future.wait (/node_modules/fibers/future.js:449:15)\n at Object.waitForVisible (/node_modules/wdio-sync/build/index.js:345:27)\n at Object.create.searchForStores.value (/PageObjects/some.page.js:15:17)\n at Context.<anonymous> (/Tests/sample.spec.js:64:25)\n at /node_modules/wdio-sync/build/index.js:579:24\n - - - - -\n at elements(\"#not-a-real-element\") - isVisible.js:49:17\n at isVisible(\"#not-a-real-element\") - waitForVisible.js:40:22"
}
],
"hooks": [
{
"start": "2016-09-08T12:50:57.672Z",
"end": "2016-09-08T12:50:57.672Z",
"duration": 0,
"title": "\"after all\" hook",
"associatedSuite": "sample test suite number 2"
}
]
}
]
Expand Down
20 changes: 17 additions & 3 deletions lib/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,29 @@ class JsonReporter extends events.EventEmitter {
testSuite.start = suite.start
testSuite.end = suite.end
testSuite.tests = []
testSuite.hooks = []

for (let hookName of Object.keys(suite.hooks)){
const hook = suite.hooks[hookName]
const hookResult = {}

hookResult.start = hook.start
hookResult.end = hook.end
hookResult.duration = hook.duration
hookResult.title = hook.title
hookResult.associatedSuite = hook.parent
hookResult.associatedTest = hook.currentTest
testSuite.hooks.push(hookResult)
}

for (let testName of Object.keys(suite.tests)) {
const test = suite.tests[testName]
const testCase = {}

testCase.name = testName
testCase.start = suite.tests[testName].start
testCase.end = suite.tests[testName].end
testCase.duration = suite.tests[testName].duration
testCase.start = test.start
testCase.end = test.end
testCase.duration = test.duration

if (test.state === 'pending') {
skippedCount = skippedCount + 1
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wdio-json-reporter",
"version": "0.0.4",
"version": "0.1.0",
"description": "A WebdriverIO plugin. Report results in json format.",
"main": "build/reporter.js",
"scripts": {
Expand Down

0 comments on commit 6d5ff56

Please sign in to comment.