Skip to content

Commit e9eaf7c

Browse files
authored
Merge pull request #17 from SmartBear/TSERV-782-print-report-console
TSERV-782 Print Report to Console
2 parents e67fbc0 + 52b32ae commit e9eaf7c

4 files changed

Lines changed: 60 additions & 5 deletions

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ table includes the currently implemented options.
6565
| Option | Sample Value | Description|
6666
|---|---|---|
6767
| async | N/A | Run the project without waiting for results. The TestJobID will be printed on the console to make it possible to query status, get reports or cancel the job|
68+
| printReport | N/A | Print the execution report to the console for synchronous job after it is completed |
6869
| timeout| 30 | Specify a timeout for the running job. When the job has been running for the specified number of seconds, the job will fail and the report will include information that it timed out. If not specified, the job will always run until completed|
6970
| skipdeps | N/A | Do not scan project for dependencies. This will improve performance for large projects without dependencies to external files |
7071
| testsuite | TestSuite1 | Name of a test suite to run|
@@ -116,6 +117,11 @@ Each job has a job ID, with the command "jobs cancel" a running (or queued) job
116117

117118
`testengine jobs status <job ID>`
118119

120+
### Print an execution report to the console'
121+
Each job has a job ID, with the command "jobs printReport" you can print execution report for a completed job to the console. This allows user to view the report without writing it into a file.
122+
123+
`testengine jobs printReport <job ID>`
124+
119125
### Request an execution report from the server'
120126
Each job has a job ID, with the command "jobs report" you can request the execution report for a completed job.
121127
The "output" argument is mandatory, "format" is optional.

bin/jobs_functions.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22
const util = require('./shared_utils');
3+
const utility = require('util');
34
const request = require('superagent');
45
const config = require('./config').config;
56
const sprintf = require('sprintf-js').sprintf;
@@ -44,6 +45,15 @@ module.exports = {
4445
}
4546
break;
4647
}
48+
case 'printreport': {
49+
if (args.length < 2) {
50+
printModuleHelp();
51+
} else {
52+
const testJobId = args[ args.length - 1 ];
53+
printReport(testJobId);
54+
}
55+
break;
56+
}
4757
case 'prune': {
4858
let argumentCount = args.length;
4959
let options = util.optionsFromArgs(args.splice(1), [
@@ -70,6 +80,7 @@ function printModuleHelp() {
7080
util.error("Commands: ");
7181
util.error(" list [format=text/csv/json] [user=username|list of usernames] [status=status|(list of statuses)]");
7282
util.error(" report output=<directory> [reportFileName=<filename>] [format=junit/excel/json/pdf] <testjobId>");
83+
util.error(" printReport <testjobId>");
7384
util.error(" status <testjobId>");
7485
util.error(" cancel <testjobId>");
7586
util.error(" prune [before=YYYY-MM-DD]");
@@ -103,6 +114,28 @@ function terminateTestJob(testjobId) {
103114
})
104115
}
105116

117+
function printReport (testjobId) {
118+
const endPoint = config.server + '/api/v1/testjobs';
119+
const url = endPoint + '/' + testjobId + '/report';
120+
util.output(`Printing report for ${testjobId} ...`);
121+
request.get(url)
122+
.auth(config.username, config.password)
123+
.accept('application/json')
124+
.send()
125+
.end((err, res) => {
126+
const jsonReport = res.body;
127+
if (err !== null) {
128+
if (err.status === 404) {
129+
util.output(`Testjob with id ${testjobId} not found`);
130+
} else {
131+
util.output(err.status + ': ' + err.message);
132+
}
133+
return 1
134+
}
135+
util.output(utility.inspect(jsonReport, { showHidden: false, depth: null}));
136+
});
137+
}
138+
106139
function reportForTestJob(testjobId, outputFolder, fileName, format) {
107140
let endPoint = config.server + '/api/v1/testjobs';
108141
let reportFilename;

bin/run_functions.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const JSZip = require("jszip");
1313
const sprintf = require('sprintf-js').sprintf;
1414
const jobs = require('./jobs_functions');
1515
const WebSocket = require('ws');
16+
const utility = require('util');
1617

1718
module.exports.dispatcher = function (args) {
1819
if (args.length === 0) {
@@ -21,13 +22,14 @@ module.exports.dispatcher = function (args) {
2122
let argsWithoutFilename = args.splice(1, args.length - 2);
2223
let options = util.optionsFromArgs(argsWithoutFilename, [
2324
'testcase',
24-
'=async',
25+
'async',
2526
'=skipdeps',
2627
'priorityJob',
2728
'testsuite',
2829
'securitytest',
2930
'tags',
3031
'environment',
32+
'=printReport',
3133
'output',
3234
'reportFileName',
3335
'format',
@@ -57,7 +59,7 @@ module.exports.dispatcher = function (args) {
5759
function printModuleHelp() {
5860
util.error("Usage: testengine run <command>");
5961
util.error("Commands: ");
60-
util.error(" project [testsuite=<name>] [async] [skipdeps] [priorityJob] [testcase=<name>] [securitytest=<name>] [timeout=<seconds>] [tags=(tag1,tag2)] [output=<directory>] [reportFileName=<filename>] [format=junit/excel/json/pdf] [environment=<environment name>]");
62+
util.error(" project [testsuite=<name>] [async] [skipdeps] [priorityJob] [testcase=<name>] [securitytest=<name>] [timeout=<seconds>] [tags=(tag1,tag2)] [output=<directory>] [printReport] [reportFileName=<filename>] [format=junit/excel/json/pdf] [environment=<environment name>]");
6163
util.error(" [projectPassword=<password>] [proxyHost=<hostname>] [proxyPort=<port>] [proxyUser=<username>]");
6264
util.error(" [proxyPassword=<password>] <filename>");
6365
util.error(" help");
@@ -194,6 +196,9 @@ function getQueryStringFromOptions(options) {
194196
case 'priorityJob':
195197
queryStringPart = key + '=' + encodeURI(options[key]);
196198
break;
199+
case 'async':
200+
queryStringPart = key + '=' + encodeURI(options[key]);
201+
break;
197202
default:
198203
break;
199204
}
@@ -370,8 +375,18 @@ function executeProject(filename, project, options) {
370375
if (err === null) {
371376
status = result.body.status;
372377
jobId = result.body['testjobId'];
373-
if (config.verbose || options.async)
378+
if (config.verbose || options.async) {
374379
util.output("TestJoB ID: " + jobId);
380+
}
381+
382+
if (('printReport' in options) && options.async) {
383+
util.output("Report is printed only for synchronous job");
384+
}
385+
386+
if (!options.async && ('printReport' in options)) {
387+
util.output(utility.inspect(result.body, { showHidden: false, depth: null}));
388+
}
389+
375390
} else {
376391
status = 'ERROR';
377392
if ('status' in err) {
@@ -454,13 +469,14 @@ function executeProject(filename, project, options) {
454469
process.exit();
455470
}
456471
} else {
457-
if (!('async' in options)) {
472+
if (!options.async || !('async' in options)) {
458473
// If status isn't CANCELED, PENDING or DISCONNECTED and we have an output directory, store reports there
459474
//
460475
if (!missingFiles) {
461476
if (config.showProgress)
462477
util.output('');
463478
util.output("Result: " + status);
479+
464480
if ((jobId !== null)
465481
&& ((status !== 'CANCELED')
466482
&& (status !== 'PENDING')

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "testengine-cli",
3-
"version": "1.2.1",
3+
"version": "1.3.0",
44
"description": "CLI for SmartBear ReadyAPI TestEngine",
55
"scripts": {
66
"testengine": "bin/testengine.js",

0 commit comments

Comments
 (0)