Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ table includes the currently implemented options.
| Option | Sample Value | Description|
|---|---|---|
| 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|
| printReport | N/A | Print the execution report to the console for synchronous job after it is completed |
Comment thread
lootic marked this conversation as resolved.
| 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|
| skipdeps | N/A | Do not scan project for dependencies. This will improve performance for large projects without dependencies to external files |
| testsuite | TestSuite1 | Name of a test suite to run|
Expand Down Expand Up @@ -116,6 +117,11 @@ Each job has a job ID, with the command "jobs cancel" a running (or queued) job

`testengine jobs status <job ID>`

### Print an execution report to the console'
Comment thread
lootic marked this conversation as resolved.
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.

`testengine jobs printReport <job ID>`

### Request an execution report from the server'
Each job has a job ID, with the command "jobs report" you can request the execution report for a completed job.
The "output" argument is mandatory, "format" is optional.
Expand Down
33 changes: 33 additions & 0 deletions bin/jobs_functions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';
const util = require('./shared_utils');
const utility = require('util');
const request = require('superagent');
const config = require('./config').config;
const sprintf = require('sprintf-js').sprintf;
Expand Down Expand Up @@ -44,6 +45,15 @@ module.exports = {
}
break;
}
case 'printreport': {
Comment thread
lootic marked this conversation as resolved.
if (args.length < 2) {
printModuleHelp();
} else {
const testJobId = args[ args.length - 1 ];
printReport(testJobId);
}
break;
}
case 'prune': {
let argumentCount = args.length;
let options = util.optionsFromArgs(args.splice(1), [
Expand All @@ -70,6 +80,7 @@ function printModuleHelp() {
util.error("Commands: ");
util.error(" list [format=text/csv/json] [user=username|list of usernames] [status=status|(list of statuses)]");
util.error(" report output=<directory> [reportFileName=<filename>] [format=junit/excel/json/pdf] <testjobId>");
util.error(" printReport <testjobId>");
util.error(" status <testjobId>");
util.error(" cancel <testjobId>");
util.error(" prune [before=YYYY-MM-DD]");
Expand Down Expand Up @@ -103,6 +114,28 @@ function terminateTestJob(testjobId) {
})
}

function printReport (testjobId) {
const endPoint = config.server + '/api/v1/testjobs';
const url = endPoint + '/' + testjobId + '/report';
util.output(`Printing report for ${testjobId} ...`);
request.get(url)
.auth(config.username, config.password)
.accept('application/json')
.send()
.end((err, res) => {
const jsonReport = res.body;
if (err !== null) {
if (err.status === 404) {
util.output(`Testjob with id ${testjobId} not found`);
} else {
util.output(err.status + ': ' + err.message);
}
return 1
}
util.output(utility.inspect(jsonReport, { showHidden: false, depth: null}));
});
}

function reportForTestJob(testjobId, outputFolder, fileName, format) {
let endPoint = config.server + '/api/v1/testjobs';
let reportFilename;
Expand Down
24 changes: 20 additions & 4 deletions bin/run_functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const JSZip = require("jszip");
const sprintf = require('sprintf-js').sprintf;
const jobs = require('./jobs_functions');
const WebSocket = require('ws');
const utility = require('util');

module.exports.dispatcher = function (args) {
if (args.length === 0) {
Expand All @@ -21,13 +22,14 @@ module.exports.dispatcher = function (args) {
let argsWithoutFilename = args.splice(1, args.length - 2);
let options = util.optionsFromArgs(argsWithoutFilename, [
'testcase',
'=async',
'async',
'=skipdeps',
'priorityJob',
'testsuite',
'securitytest',
'tags',
'environment',
'=printReport',
'output',
'reportFileName',
'format',
Expand Down Expand Up @@ -57,7 +59,7 @@ module.exports.dispatcher = function (args) {
function printModuleHelp() {
util.error("Usage: testengine run <command>");
util.error("Commands: ");
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>]");
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>]");
util.error(" [projectPassword=<password>] [proxyHost=<hostname>] [proxyPort=<port>] [proxyUser=<username>]");
util.error(" [proxyPassword=<password>] <filename>");
util.error(" help");
Expand Down Expand Up @@ -194,6 +196,9 @@ function getQueryStringFromOptions(options) {
case 'priorityJob':
queryStringPart = key + '=' + encodeURI(options[key]);
break;
case 'async':
queryStringPart = key + '=' + encodeURI(options[key]);
break;
default:
break;
}
Expand Down Expand Up @@ -370,8 +375,18 @@ function executeProject(filename, project, options) {
if (err === null) {
status = result.body.status;
jobId = result.body['testjobId'];
if (config.verbose || options.async)
if (config.verbose || options.async) {
util.output("TestJoB ID: " + jobId);
}

if (('printReport' in options) && options.async) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

util.output("Report is printed only for synchronous job");
}

if (!options.async && ('printReport' in options)) {
util.output(utility.inspect(result.body, { showHidden: false, depth: null}));
}

} else {
status = 'ERROR';
if ('status' in err) {
Expand Down Expand Up @@ -454,13 +469,14 @@ function executeProject(filename, project, options) {
process.exit();
}
} else {
if (!('async' in options)) {
if (!options.async || !('async' in options)) {
// If status isn't CANCELED, PENDING or DISCONNECTED and we have an output directory, store reports there
//
if (!missingFiles) {
if (config.showProgress)
util.output('');
util.output("Result: " + status);

if ((jobId !== null)
&& ((status !== 'CANCELED')
&& (status !== 'PENDING')
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": "testengine-cli",
"version": "1.2.1",
"version": "1.3.0",
"description": "CLI for SmartBear ReadyAPI TestEngine",
"scripts": {
"testengine": "bin/testengine.js",
Expand Down