test-results-reporter / testbeats

Publishes test results to Microsoft Teams, Google Chat & Slack
https://testbeats.com
MIT License
94 stars 19 forks source link

Error while parsing wdio results.json #134

Closed pn4360 closed 1 year ago

pn4360 commented 1 year ago

Tool- WebdriverIO v8

Steps:

  1. I have generated results.json( it is attached below) file using the wdio json reporter plugin .
  2. However while running the report.js it throws error as
node report.js
/Users/piyushnimoria/Documents/Git/patient-web-automation/node_modules/test-results-parser/src/parsers/mocha.js:85
  rawjson.failures.forEach(test => test.state = "failed");
                   ^

TypeError: Cannot read properties of undefined (reading 'forEach')
    at formatMochaJsonReport (/Users/piyushnimoria/Documents/Git/patient-web-automation/node_modules/test-results-parser/src/parsers/mocha.js:85:20)
    at getTestResult (/Users/piyushnimoria/Documents/Git/patient-web-automation/node_modules/test-results-parser/src/parsers/mocha.js:47:30)
    at Object.parse (/Users/piyushnimoria/Documents/Git/patient-web-automation/node_modules/test-results-parser/src/parsers/mocha.js:114:10)
    at Object.parse (/Users/piyushnimoria/Documents/Git/patient-web-automation/node_modules/test-results-parser/src/parsers/index.js:59:27)
    at Object.parse (/Users/piyushnimoria/Documents/Git/patient-web-automation/node_modules/test-results-parser/src/index.js:4:17)
    at Object.run (/Users/piyushnimoria/Documents/Git/patient-web-automation/node_modules/test-results-reporter/src/commands/publish.js:25:33)
    at publish (/Users/piyushnimoria/Documents/Git/patient-web-automation/node_modules/test-results-reporter/src/index.js:4:22)
    at Object.<anonymous> (/Users/piyushnimoria/Documents/Git/patient-web-automation/src/report.js:50:1)
    at Module._compile (node:internal/modules/cjs/loader:1233:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1287:10)

Report.js

const { publish, defineConfig } = require('test-results-reporter');

const config = defineConfig({
    "reports": [
        {
            "targets": [
                {
                    "name": "slack",
                    "inputs": {
                        "url": "<hook>",
                        "publish": "test-summary-slim",
                        "only-failures": false,
                        "title": "PA_THER Automation Report"
                    },
                    "extensions": [
                        {
                            "name": "report-portal-analysis",
                            "inputs": {
                                "url": "<url>",
                                "api_key": "<api_key>",
                                "project": "PWA_QA"
                            }
                        },
                        {
                            "name": "mentions",
                            "inputs": {
                                "users": [
                                    {
                                        "name": "<name>",
                                        "slack_uid": "@piyush"
                                    }
                                ]
                            }
                        }
                    ]
                }
            ],
            "results": [
                {
                    "type": "mocha",
                    "files": [
                        "results-0-0.json"
                    ]
                }
            ]
        }
    ]
});
publish({ config });

Results.json

{
    "start": "2023-08-03T15:02:52.469Z",
    "end": "2023-08-03T15:04:01.892Z",
    "capabilities": {
        "acceptInsecureCerts": false,
        "browserName": "chrome",
        "browserVersion": "115.0.5790.114",
        "chrome": {
            "chromedriverVersion": "114.0.5735.90 (386bc09e8f4f2e025eddae123f36f6263096ae49-refs/branch-heads/5735@{#1052})",
            "userDataDir": "/var/folders/qf/xrxdng0j6n7g8mwmf6gtrkzc0000gn/T/.com.google.Chrome.7P6d1W"
        },
        "goog:chromeOptions": {
            "debuggerAddress": "localhost:49576"
        },
        "networkConnectionEnabled": false,
        "pageLoadStrategy": "normal",
        "platformName": "MAC",
        "proxy": {},
        "se:cdp": "ws://192.168.178.36:4444/session/9e57c3ef09e5e9affe2519ab6af4d8d5/se/cdp",
        "se:cdpVersion": "115.0.5790.114",
        "setWindowRect": true,
        "strictFileInteractability": false,
        "timeouts": {
            "implicit": 0,
            "pageLoad": 300000,
            "script": 30000
        },
        "unhandledPromptBehavior": "dismiss and notify",
        "wdio:sharedStoreServicePort": 49334,
        "webauthn:extension:credBlob": true,
        "webauthn:extension:largeBlob": true,
        "webauthn:extension:minPinLength": true,
        "webauthn:extension:prf": true,
        "webauthn:virtualAuthenticators": true,
        "sessionId": "9e57c3ef09e5e9affe2519ab6af4d8d5"
    },
    "host": "localhost",
    "port": 4444,
    "baseUrl": "<base_url>",
    "framework": "mocha",
    "suites": [
        {
            "name": "mood journal CRUD  | @regression",
            "duration": 69299,
            "start": "2023-08-03T15:02:52.482Z",
            "end": "2023-08-03T15:04:01.781Z",
            "sessionId": "9e57c3ef09e5e9affe2519ab6af4d8d5",
            "tests": [
                {
                    "name": "Journal | Diabetes und Depression | New mood journal | Create new entry with combination of pleasant and unpleasant | @smoke",
                    "start": "2023-08-03T15:03:08.028Z",
                    "end": "2023-08-03T15:04:01.779Z",
                    "duration": 53751,
                    "state": "failed",
                    "errorType": "Error",
                    "error": "element (\"button=Create journal entry\") still not clickable after 50000ms",
                    "standardError": "Error: element (\"button=Create journal entry\") still not clickable after 50000ms\n    at ElementUtil.click (/Users/piyushnimoria/Documents/Git/patient-web-automation/src/utility/ElementUtil.js:28:5)\n    at MoodJournalPage.submitMixedFeelingValence (/Users/piyushnimoria/Documents/Git/patient-web-automation/src/pages/diaryPages/MoodJournalPage.js:21:5)\n    at Context.<anonymous> (/Users/piyushnimoria/Documents/Git/patient-web-automation/src/tests/smokeTests/diary/moodJournal/moodJournalCreation.spec.js:34:5)"
                }
            ],
            "hooks": [
                {
                    "start": "2023-08-03T15:02:52.483Z",
                    "end": "2023-08-03T15:03:08.027Z",
                    "duration": 15544,
                    "title": "\"before all\" hook for mood journal CRUD  | @regression",
                    "associatedSuite": "mood journal CRUD  | @regression",
                    "associatedTest": "Journal | Diabetes und Depression | New mood journal | Create new entry with combination of pleasant and unpleasant | @smoke",
                    "state": "passed"
                },
                {
                    "start": "2023-08-03T15:03:08.029Z",
                    "end": "2023-08-03T15:03:10.238Z",
                    "duration": 2209,
                    "title": "\"before each\" hook for mood journal CRUD  | @regression",
                    "associatedSuite": "mood journal CRUD  | @regression",
                    "associatedTest": "Journal | Diabetes und Depression | New mood journal | Create new entry with combination of pleasant and unpleasant | @smoke",
                    "state": "passed"
                }
            ]
        }
    ],
    "specs": [
        "file://src/tests/smokeTests/diary/moodJournal/moodJournalCreation.spec.js"
    ],
    "state": {
        "passed": 0,
        "failed": 1,
        "skipped": 0
    }
}
leelaprasadv commented 1 year ago

Hey @pn4360 I see you are trying out wdio results json with test results reporter. We do not currently support wdio json format.

As a work around, you could use wdio reporter plugins to generate supported formats and feed it to reporter. Ex: you could try generating a junit report which is a supported format. https://webdriver.io/docs/junit-reporter/

If you are willing to add this enhancement, raise a PR and we will review it and process it.