-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Improve run_wdio to print out failed tests #4843
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ const xml2js = require('xml2js'); | |
| const parser = new xml2js.Parser({ attrkey: 'ATTR' }); | ||
| const child_process = require('child_process'); | ||
| const prompt = require('prompt-sync')(); | ||
| const chalk = require('chalk'); | ||
|
|
||
| const specFolder = 'wdio/test'; | ||
|
|
||
|
|
@@ -53,7 +54,7 @@ function SelectSpecs(folder) { | |
| let opts = SelectSpecs(specFolder); | ||
| console.log(`Selected tests: ${opts}`); | ||
|
|
||
| function OverrideHyperV() { | ||
| function EnsureRunningInHyperV() { | ||
| const baseboardMfr = child_process | ||
| .execSync('powershell.exe (gwmi Win32_BaseBoard).Manufacturer') | ||
| .toString() | ||
|
|
@@ -69,26 +70,39 @@ function OverrideHyperV() { | |
| } | ||
| } | ||
|
|
||
| OverrideHyperV(); | ||
|
|
||
| const Launcher = require('@wdio/cli').default; | ||
|
|
||
| const wdio = new Launcher('wdio.conf.js', { specs: opts }); | ||
|
|
||
| function parseLog(logfile) { | ||
| const xmlString = fs.readFileSync(logfile); | ||
| let name; | ||
| let failures = {}; | ||
| parser.parseString(xmlString, (err, res) => { | ||
| if (!res.testsuites) { | ||
| name = 'something went wrong'; | ||
| failures = 'something went wrong'; | ||
| } else { | ||
| const attr = res.testsuites.testsuite[0].ATTR; | ||
| if (attr.errors > 0 || attr.failures > 0) { | ||
| name = attr.name; | ||
| for (let i = 0; i < res.testsuites.testsuite.length; i++) { | ||
| const attr = res.testsuites.testsuite[i].ATTR; | ||
| if (attr.errors > 0 || attr.failures > 0) { | ||
| let name = attr.name; | ||
| failures[name] = {}; | ||
| const testcases = res.testsuites.testsuite[i].testcase; | ||
| for (let j = 0; j < testcases.length; j++) { | ||
|
||
| if (testcases[j].error && testcases[j].error[0].ATTR) { | ||
| failures[name].testcase = testcases[j].ATTR.name; | ||
| failures[name].error = testcases[j].error[0].ATTR.message; | ||
| const systemErr = testcases[j]['system-err'][0]; | ||
| const stack = systemErr.substr( | ||
| systemErr.indexOf('\n at ') + 1 | ||
| ); | ||
| failures[name].stack = stack; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }); | ||
| return name; | ||
| return failures; | ||
| } | ||
|
|
||
| function parseLogs() { | ||
|
|
@@ -100,20 +114,42 @@ function parseLogs() { | |
| return names; | ||
| } | ||
|
|
||
| function PrintFailedTests(ft) { | ||
| for (let i = 0; i < Object.keys(ft).length; i++) { | ||
asklar marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const key = Object.keys(ft)[i]; | ||
| console.log(chalk.redBright(key)); | ||
| console.log( | ||
| ' ', | ||
| chalk.underline('testcase'), | ||
| chalk.bold(ft[key].testcase) | ||
asklar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ); | ||
| console.log(' ', chalk.underline('error'), chalk.bold(ft[key].error)); | ||
| console.log(' ', chalk.underline('stack')); | ||
| console.log(ft[key].stack); | ||
| } | ||
| } | ||
|
|
||
| function Process(code) { | ||
| const failedTests = parseLogs(); | ||
| for (let i = 0; i < failedTests.length; i++) { | ||
| console.log(`Failed test: ${failedTests[i]}`); | ||
| console.log('Failed tests: '); | ||
| PrintFailedTests(failedTests[i]); | ||
| } | ||
| process.exit(code); | ||
| } | ||
|
|
||
| wdio.run().then( | ||
| code => { | ||
| Process(code); | ||
| }, | ||
| error => { | ||
| console.error('Launcher failed to start the test', error.stacktrace); | ||
| process.exit(1); | ||
| } | ||
| ); | ||
| function RunWdio() { | ||
asklar marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| EnsureRunningInHyperV(); | ||
|
|
||
| wdio.run().then( | ||
| code => { | ||
| Process(code); | ||
| }, | ||
| error => { | ||
| console.error('Launcher failed to start the test', error.stacktrace); | ||
| process.exit(1); | ||
| } | ||
| ); | ||
| } | ||
|
|
||
| RunWdio(); | ||


Uh oh!
There was an error while loading. Please reload this page.