Skip to content
Snippets Groups Projects
Commit 31fd63bc authored by Tasneem Natshah's avatar Tasneem Natshah
Browse files

Issue #3360106: Add a new section in the setting to generate JSON format

parent f03337ea
No related branches found
No related tags found
No related merge requests found
......@@ -4,5 +4,7 @@ features_path: "tests/features"
html_report: true
html_report_dir: "tests/reports"
html_report_format: "cucumberjs_html_formatter"
json_report: false
json_report_dir: "tests/reports"
log_report_dir: "tests/logs"
editing_mode: "free_text"
......@@ -20,6 +20,12 @@ cucumber_ui.settings:
html_report_formatter:
type: string
label: "HTML report formatter"
json_report:
type: boolean
label: "Enable JSON report"
json_report_dir:
type: string
label: "JSON report directory"
log_report_dir:
type: string
label: "Log report directory"
......
......@@ -98,6 +98,8 @@ class CucumberUiController extends ControllerBase {
$html_report = $config->get('html_report');
$html_report_dir = $config->get('html_report_dir');
$log_report_dir = $config->get('log_report_dir');
$json_report = $config->get('json_report');
$json_report_dir = $config->get('json_report_dir');
$output = '';
if ($html_report) {
......@@ -114,6 +116,19 @@ class CucumberUiController extends ControllerBase {
}
}
else if ($json_report) {
if (isset($json_report_dir) && $json_report_dir != '') {
$json_report = $json_report_dir . '/index.json';
if ($json_report && file_exists($json_report)) {
$output = file_get_contents($json_report);
}
else {
$output = $this->t('No JSON test report yet!');
}
}
}
else {
if (isset($log_report_dir) && $log_report_dir != '') {
......
......@@ -336,10 +336,10 @@ So that I know it is working
$html_report_format = '';
if ($html_report_formatter == 'cucumberjs_html_formatter') {
$html_report_format = "yarn nightwatch --format html:".$html_report_dir."/index.html";
$html_report_format = " --format html:".$html_report_dir."/index.html";
}
elseif ($html_report_formatter == 'bootstrap_html_formatter') {
$html_report_format = "yarn nightwatch --format bootstrap:".$html_report_dir."/index.html";
$html_report_format = " --format bootstrap:".$html_report_dir."/index.html";
}
$log_report_dir = $config->get('log_report_dir');
......@@ -368,7 +368,7 @@ So that I know it is working
if (isset($html_report_dir) && $html_report_dir != '') {
if ($this->fileSystem->prepareDirectory($html_report_dir, FileSystemInterface::CREATE_DIRECTORY)) {
$command = "cd $config_path; $html_report_format;";
$command = "cd $config_path; yarn nightwatch $html_report_format";
}
else {
$this->messenger->addError($this->t('The HTML Output directory does not exists or is not writable.'));
......@@ -385,7 +385,7 @@ So that I know it is working
if ($this->fileSystem->prepareDirectory($log_report_dir, FileSystemInterface::CREATE_DIRECTORY)) {
$log_report_output_file = $log_report_dir . '/cucumber-ui-test.log';
$command = "cd $config_path; $html_report_format;";
$command = "cd $config_path; yarn nightwatch $html_report_format";
}
else {
$this->messenger->addError($this->t('The Log Output directory does not exists or is not writable.'));
......@@ -396,6 +396,27 @@ So that I know it is working
}
}
// JSON report format
$json_report = $config->get('json_report');
$json_report_dir = $config->get('json_report_dir');
if ($json_report) {
if (isset($json_report_dir) && $json_report_dir != '') {
if ($this->fileSystem->prepareDirectory($json_report_dir, FileSystemInterface::CREATE_DIRECTORY)) {
$command .= " --format json:".$json_report_dir."/index.json";
}
else {
$this->messenger->addError($this->t('The JSON Output directory does not exists or is not writable.'));
}
}
else {
$this->messenger->addError($this->t('HTML report directory and file is not configured.'));
}
}
$command .= ';';
$output = shell_exec($command);
if (isset($output)) {
......
......@@ -227,10 +227,10 @@ class CucumberUiRunTests extends FormBase
$html_report_format = '';
if ($html_report_formatter == 'cucumberjs_html_formatter') {
$html_report_format = "yarn nightwatch --format html:./tests/reports/index.html";
$html_report_format = " --format html:".$html_report_dir."/index.html";
}
elseif ($html_report_formatter == 'bootstrap_html_formatter') {
$html_report_format = "yarn nightwatch --format bootstrap:./tests/reports/index.html";
$html_report_format = " --format bootstrap:".$html_report_dir."/index.html";
}
$log_report_dir = $config->get('log_report_dir');
......@@ -249,7 +249,7 @@ class CucumberUiRunTests extends FormBase
if (isset($html_report_dir) && $html_report_dir != '') {
if ($this->fileSystem->prepareDirectory($html_report_dir, FileSystemInterface::CREATE_DIRECTORY)) {
$command = "cd $config_path; $html_report_format;";
$command = "cd $config_path; yarn nightwatch $html_report_format";
}
else {
$form_state->setErrorByName('submit_button', $this->t('The HTML Output directory does not exists or is not writable.'));
......@@ -265,7 +265,7 @@ class CucumberUiRunTests extends FormBase
if ($this->fileSystem->prepareDirectory($log_report_dir, FileSystemInterface::CREATE_DIRECTORY)) {
$log_report_output_file = $log_report_dir . "/cucumber-ui-test.log";
$command = "cd $config_path; $html_report_format;";
$command = "cd $config_path; yarn nightwatch $html_report_format";
}
else {
$form_state->setErrorByName('submit_button', $this->t('The Log Output directory does not exists or is not writable.'));
......@@ -276,7 +276,28 @@ class CucumberUiRunTests extends FormBase
}
}
$process = new Process($command);
// JSON report format
$json_report = $config->get('json_report');
$json_report_dir = $config->get('json_report_dir');
if ($json_report) {
if (isset($json_report_dir) && $json_report_dir != '') {
if ($this->fileSystem->prepareDirectory($json_report_dir, FileSystemInterface::CREATE_DIRECTORY)) {
$command .= " --format json:".$json_report_dir."/index.json";
}
else {
$this->messenger->addError($this->t('The JSON Output directory does not exists or is not writable.'));
}
}
else {
$this->messenger->addError($this->t('HTML report directory and file is not configured.'));
}
}
$command .= ';';
$process = new Process($command);
$process->enableOutput();
try {
......
......@@ -73,6 +73,7 @@ class CucumberUiSettings extends ConfigFormBase {
'#type' => 'textfield',
'#maxlength' => 512,
'#default_value' => $config->get('features_path'),
'#suffix' => '</div></div>',
];
$form['html_report'] = [
......@@ -105,6 +106,25 @@ class CucumberUiSettings extends ConfigFormBase {
'#suffix' => '</div></div>',
];
$form['json_report'] = [
'#type' => 'checkbox',
'#title' => $this->t('Enable JSON report format'),
'#default_value' => $config->get('json_report'),
'#description' => $this->t('Check to enable generating an JSON report for your test results.'),
'#prefix' => '<div class="panel">
<h3 class="panel__title">' . $this->t('JSON formatted Report') . '</h3>
<div class="panel__content">',
];
$form['json_report_dir'] = [
'#title' => $this->t('JSON report directory'),
'#description' => $this->t('The full absolute path for the tests/json-reports. No trailing slash at the end.'),
'#type' => 'textfield',
'#maxlength' => 512,
'#default_value' => $config->get('json_report_dir'),
'#suffix' => '</div></div>',
];
$form['log_report_dir'] = [
'#title' => $this->t('Console log report directory'),
'#description' => $this->t('The full absolute path for the tests/logs. No trailing slash at the end'),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment