Skip to content

Commit

Permalink
aisingapore#384 - run results auditing and tracking enhancement to re…
Browse files Browse the repository at this point in the history
…port option

Sending a PR to enhance report option. In current state when report option is used, TagUI will generate a HTML log file, in addition to the usual text log file.

With this enhancement, when the report option is used, TagUI will track the run results in a csv spreadsheet (tagui/src/tagui_report.csv), along with html logs that persist with a running number.

This allows users to explicitly decide which automation flows to be tracked and tabulated in tagui_report.csv. This information may be useful for personal reference, to measure time savings from automation, for keeping a trail for auditing purpose, or perhaps facilitate sending a summary to boss. Following is an example of how tagui_report.csv will look like (time taken in seconds) -

#| AUTOMATION FLOW | START TIME | FINISH TIME | ERROR STATUS | LOG FILE
:--|:--|:--|:--|:--|:--
1 | /Users/kensoh/Desktop/download_flow | Sun Apr 07 2019 17:33:58 GMT+0800 (+08) | 32.1 | SUCCESS | /Users/kensoh/Desktop/download_flow_1.html
2 | /Users/kensoh/Desktop/upload_flow | NOT STARTED | NOT FINISHED | [LINE 1] cannot understand step self-destruct | /Users/kensoh/Desktop/upload_flow_2.html
3 | /Users/kensoh/Desktop/update_flow | NOT STARTED | NOT FINISHED | [LINE 1] cannot understand step reboot computer | /Users/kensoh/Desktop/update_flow_3.html
4 | /Users/kensoh/Desktop/booking_flow | Sun Apr 07 2019 17:39:00 GMT+0800 (+08) | NOT FINISHED | cannot find confirm_booking | /Users/kensoh/Desktop/booking_flow_4.html
  • Loading branch information
kensoh committed Apr 7, 2019
1 parent 6b657dc commit b44b261
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
/src/tagui_datatable_transpose.csv
/src/tagui_datatable.csv

# exclude audit report csv file
/src/tagui_report.csv

# exclude translation temp build files
/src/languages/build.js
/src/languages/build.log
Expand Down
10 changes: 5 additions & 5 deletions src/tagui
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ if [ -z "$1" ]
then
echo "tagui v4.1.0: use following syntax and below options to run ./tagui flow_filename option(s)"
echo
echo "headless - run on invisible Chrome web browser instead of default PhantomJS (first install Chrome)"
echo "chrome - run on visible Chrome web browser instead of invisible PhantomJS (first install Chrome)"
echo "headless - run on invisible Chrome web browser instead of default PhantomJS (first install Chrome)"
echo "firefox - run on visible Firefox web browser instead of invisible PhantomJS (first install Firefox)"
echo "report - track run result in tagui/src/tagui_report.csv and save html log of automation execution"
echo "upload - upload automation flow and result to hastebin.com (expires 30 days after last view)"
echo "report - web report for sharing of run results on webserver (default is only a text log file)"
echo "debug - show run-time backend messages from PhantomJS for detailed tracing and logging"
echo "quiet - run without output except for explicit output (echo / show / check / errors etc)"
echo "speed - skip 3-second delay between datatable iterations (and skip restarting of Chrome)"
echo "quiet - run without output except for explicit output (echo / show / check / errors etc)"
echo "debug - show run-time backend messages from PhantomJS mode for detailed tracing and logging"
echo "test - testing with check step test assertions for CI/CD integration (output XUnit XML file)"
echo "baseline - output execution log and relative-path output files to a separate baseline directory"
echo "input(s) - add your own parameter(s) to be used in your automation flow as variables p1 to p9"
echo "data.csv - specify a csv file to be used as the datatable for batch automation of many records"
echo
echo "TagUI is a CLI tool for digital process automation (RPA) ~ for more info, google tagui"
echo "TagUI is a command-line tool for digital process automation (RPA) - for more info, google tagui"
echo
exit 1
fi
Expand Down
10 changes: 5 additions & 5 deletions src/tagui.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ setlocal enableextensions enabledelayedexpansion
if "%~1"=="" (
echo tagui v4.1.0: use following syntax and below options to run - tagui flow_filename option^(s^)
echo.
echo headless - run on invisible Chrome web browser instead of default PhantomJS ^(first install Chrome^)
echo chrome - run on visible Chrome web browser instead of invisible PhantomJS ^(first install Chrome^)
echo headless - run on invisible Chrome web browser instead of default PhantomJS ^(first install Chrome^)
echo firefox - run on visible Firefox web browser instead of invisible browser ^(first install Firefox^)
echo report - track run result in tagui\src\tagui_report.csv and save html log of automation execution
echo upload - upload automation flow and result to hastebin.com ^(expires 30 days after last view^)
echo report - web report for sharing of run results on webserver ^(default is only a text log file^)
echo debug - show run-time backend messages from PhantomJS for detailed tracing and logging
echo quiet - run without output except for explicit output ^(echo / show / check / errors etc^)
echo speed - skip 3-second delay between datatable iterations ^(and skip restarting of Chrome^)
echo quiet - run without output except for explicit output ^(echo / show / check / errors etc^)
echo debug - show run-time backend messages from PhantomJS mode for detailed tracing and logging
echo test - testing with check step test assertions for CI/CD integration ^(output XUnit XML file^)
echo baseline - output execution log and relative-path output files to a separate baseline directory
echo input^(s^) - add your own parameter^(s^) to be used in your automation flow as variables p1 to p9
echo data.csv - specify a csv file to be used as the datatable for batch automation of many records
echo.
echo TagUI is a CLI tool for digital process automation ^(RPA^) ~ for more info, google tagui
echo TagUI is a command-line tool for digital process automation ^(RPA^) - for more info, google tagui
echo.
exit /b 1
)
Expand Down
37 changes: 37 additions & 0 deletions src/tagui_report.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,42 @@
$log_file = fopen($script . '.log','r') or die("ERROR - cannot open " . $script . '.log' . "\n"); fclose($log_file);
$rep_file = fopen($script . '.html','w') or die("ERROR - cannot open " . $script . '.html' . "\n"); fclose($rep_file);

// below log automation outcome to audit report csv database

$log_content = file_get_contents($script . '.log');
$start_timestamp = "NOT STARTED"; $timestamp_header = "START - automation started - ";
if (strpos($log_content, $timestamp_header) !== false) {
$startpos_timestamp = strpos($log_content, $timestamp_header) + strlen($timestamp_header);
$start_timestamp = substr($log_content, $startpos_timestamp); $endpos_timestamp = strpos($start_timestamp, "\n");
$start_timestamp = trim(substr($start_timestamp, 0, $endpos_timestamp));}

$finish_timestamp = "NOT FINISHED"; $timestamp_footer = "FINISH - automation finished - ";
if (strpos($log_content, $timestamp_footer) !== false) {
$startpos_timestamp = strpos($log_content, $timestamp_footer) + strlen($timestamp_footer);
$finish_timestamp = substr($log_content, $startpos_timestamp); $endpos_timestamp = strpos($finish_timestamp, "\n");
$finish_timestamp = substr(trim(substr($finish_timestamp, 0, $endpos_timestamp)),0,-1);}

$error_status = "SUCCESS"; $error_identifier = "ERROR - ";
if (strpos($log_content, $error_identifier) !== false) {
$startpos_error = strpos($log_content, $error_identifier) + strlen($error_identifier);
$error_status = substr($log_content, $startpos_error); $endpos_error = strpos($error_status, "\n");
$error_status = trim(substr($error_status, 0, $endpos_error));}

// escape double quotes in the csv data values
$escaped_script = str_replace('"', '""', $script);
$start_timestamp = str_replace('"', '""', $start_timestamp);
$finish_timestamp = str_replace('"', '""', $finish_timestamp);
$error_status = str_replace('"', '""', $error_status);

$audit_output_header = '"#","AUTOMATION FLOW","START TIME","FINISH TIME","ERROR STATUS","LOG FILE"';
if (!file_exists('tagui_report.csv')) file_put_contents('tagui_report.csv', $audit_output_header . "\r\n");
$audit_output_count = count(file('tagui_report.csv')) - 1 + 1; // to track and increment entry # in audit file
$html_log_file = $script . '_' . $audit_output_count . '.html'; // to allow log persistence without overwriting
$audit_output_line = '"' . $audit_output_count . '","' . $escaped_script . '","' . $start_timestamp . '","';
$audit_output_line .= $finish_timestamp . '","' . $error_status . '","' . $html_log_file . '"' . "\r\n";
$audit_output_file = fopen('tagui_report.csv','a') or die("ERROR - cannot open " . 'tagui_report.csv' . "\n");
fwrite($audit_output_file, $audit_output_line); fclose($audit_output_file);

// below start conversion of text log file to html file

// add html <br> tag to newline for proper line breaks
Expand All @@ -26,5 +62,6 @@
"<link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro:600' rel='stylesheet'>\n" .
"<style>body {font-family: 'Source Sans Pro', sans-serif; width: 90%; margin: auto;}</style>" .
"</head><body><h3>\n" . $log_content . "</h3></body></html>"; file_put_contents($script . '.html',$log_content);
file_put_contents($script . '_' . $audit_output_count . '.html',$log_content); // write another file that persists

?>

0 comments on commit b44b261

Please sign in to comment.