#!/usr/bin/env bash FILE_PATTERN="$@" if [ $# -lt 1 ]; then printf "\n" echo Usage: ./generate_summary.sh *.json printf "\n" exit fi if [[ -z "$(ls -1 $FILE_PATTERN 2>/dev/null)" ]] ; then printf "\n" echo No report files exists. Exiting... printf "\n" exit fi if ! command -v jq &> /dev/null then printf "\n" echo "JSON parser jq could not be found" echo "Please install it!" printf "\n" exit fi total_scenarios="$(jq . $FILE_PATTERN | grep keyword |grep Scenario | wc -l)" failed_scenarios="$(jq . $FILE_PATTERN | grep status | grep failed | wc -l)" printf "\n" printf "#############################\n" printf "### TEST SCENARIO SUMMARY ###\n" printf "#############################\n" printf "\n" if [ -z "$total_scenarios" ] then printf "No scenarios found\n" else printf "Total: %s\nFailed: %s\n" $total_scenarios $failed_scenarios fi total="$(jq . $FILE_PATTERN | grep status | wc -l)" failed="$(jq . $FILE_PATTERN | grep status | grep failed | wc -l)" skipped="$(jq . $FILE_PATTERN | grep status | grep skipped | wc -l)" pending="$(jq . $FILE_PATTERN | grep status | grep pending | wc -l)" printf "\n" printf "#########################\n" printf "### TEST STEP SUMMARY ###\n" printf "#########################\n" printf "\n" if [ -z "$total" ] then printf "No test steps found\n" else printf "Total: %s\nFailed: %s\nSkipped: %s\nPending: %s\n" $total $failed $skipped $pending fi all_issues="$(cat $FILE_PATTERN | jq -c '.[] |.elements'[0].extraData |jq -c 'select(.rootCase != null)' |jq -c '"\(.rootCase.errHash)#\(.rootCase.desc)#\(.rootCase.type)#\(.rootCase.scope)#\(.id) "' | sed 's/^.//;s/.$//')" unique_issues="$(cat $FILE_PATTERN | jq -c '.[] |.elements'[0].extraData |jq -c 'select(.rootCase != null)' |jq -c '"\(.rootCase.errHash)_#\(.rootCase.errDesc)_#\(.rootCase.type)_#\(.rootCase.scope)_##@\(.rootCase.url)@##-Go \(.rootCase.key)-#_^\(.rootCase.desc)"' | sed 's/^.//;s/.$//'| sort | uniq -c | sort -r | sed 's/^ *//g' | sed 's/[[:space:]]/\_#/')" printf "\n" echo $unique_issues printf "\n" total_issues="$(echo "$unique_issues" | grep "_#" | wc -l)" tbd_issues="$(echo "$unique_issues" | grep "_#null_#" | wc -l)" application_issues="$(echo "$unique_issues" | grep "_#app_#" | wc -l)" automation_issues="$(echo "$unique_issues" | grep "_#auto_#" | wc -l)" unknown_issues="$(echo "$unique_issues" | grep "_#unknow_#" | wc -l)" total_impact="$(echo "$unique_issues" | grep "_#" | sed 's/_#/ /g' | awk '{print $1}' | awk '{s+=$1} END {printf "%.0f", s}')" tbd_impact="$(echo "$unique_issues" | grep "_#null_#" | sed 's/_#/ /g' | awk '{print $1}' | awk '{s+=$1} END {printf "%.0f", s}')" application_impact="$(echo "$unique_issues" | grep "_#app_#" | sed 's/_#/ /g' | awk '{print $1}' | awk '{s+=$1} END {printf "%.0f", s}')" automation_impact="$(echo "$unique_issues" | grep "_#auto_#" | sed 's/_#/ /g' | awk '{print $1}' | awk '{s+=$1} END {printf "%.0f", s}')" unknown_impact="$(echo "$unique_issues" | grep "_#unknow_#" | sed 's/_#/ /g' | awk '{print $1}' | awk '{s+=$1} END {printf "%.0f", s}')" total_impact_percent="$(echo "$total_impact *100 / $total_impact" | bc)" tbd_impact_percent="$(echo "scale=0 ; $tbd_impact * 100 / $total_impact " | bc)" application_impact_percent="$(echo "scale=0 ; $application_impact * 100 / $total_impact" | bc)" automation_impact_percent="$(echo "scale=0 ; $automation_impact * 100 / $total_impact" | bc)" unknown_impact_percent="$(echo "scale=0 ; $unknown_impact * 100 / $total_impact" | bc)" printf "\n" printf "###########################\n" printf "Scenarios impacted - total: ^%s (%s%%)^\n" $total_impact $total_impact_percent printf "Scenarios impacted - tbd: ^%s (%s%%)^\n" $tbd_impact $tbd_impact_percent printf "Scenarios impacted - application: ^%s (%s%%)^\n" $application_impact $application_impact_percent printf "Scenarios impacted - automation: ^%s (%s%%)^\n" $automation_impact $automation_impact_percent printf "Scenarios impacted - unknown: ^%s (%s%%)^\n" $unknown_impact $unknown_impact_percent printf "###########################\n" printf "\n" printf "\n" printf "###########################\n" printf "### ROOT CAUSE ANALYSIS ###\n" printf "###########################\n" printf "\n" if [ -z "$unique_issues" ] then printf "No issues found\n" else printf "Total issues: %s\nTo be defined: %s\nApplication: %s\nAutomation: %s\nUnknown: %s\n" $total_issues $tbd_issues $application_issues $automation_issues $unknown_issues printf "\n" printf "Most impactful issues\n" printf "\n" echo "${unique_issues}"|sed 's/_#/ /g' fi slow_steps="$(cat $FILE_PATTERN | jq -c '.[] |.elements' | jq -c '.[] |.steps'[] | jq '"\(.result.duration/1000000) ms_#\(.name)|"' |sort -Vr | head -10 |sed 's/^.//;s/.$//')" #times="$(cat $FILE_PATTERN | jq -c '.[] |.elements' | jq -c '.[] |.steps'[]| jq '"\(.result.duration) \(.name)"' |sort -Vr | head -10 | sed 's/^.//;s/.$//' | awk '{system("date -d@"$1/1000000000" -u +%H:%M:%S")}')" printf "\n" printf "##########################\n" printf "### SLOWEST TEST STEPS ###\n" printf "##########################\n" printf "\n" if [ -z "$slow_steps" ] then printf "No test steps found\n" else echo $slow_steps|sed 's/_#/ /g' |sed 's/|/\n/g'|sed -e 's/^[ \t]*//' printf "\n" fi worker_list="$(cat $FILE_PATTERN | jq -c '.[] |.elements'[0].extraData | jq -c '"\(.start)_#\(.end)_#\(.worker)_#\(.id)_#\(.name)"' | sed 's/^.//;s/.$//' | sort -k1)" number_of_workers="$(cat $FILE_PATTERN | jq -c '.[] |.elements'[0].extraData | jq -c '"\(.worker)"' | sed 's/^.//;s/.$//'| sort | uniq | wc -l )" printf "Number of workers: %s\n" $number_of_workers printf "\n" printf "####################################################\n" printf "### JOB/WORKER LIST SORTED BY TIME OF COMPLETION ###\n" printf "####################################################\n" printf "\n" if [ -z "$worker_list" ] then printf "No jobs found\n" else echo "$worker_list" fi printf "\n" printf "### END REPORT ####\n" printf "\n" printf "####################################################\n" printf "### GENERATING HTML REPORT ###\n" printf "####################################################\n" printf "\n" now=$(date +"%Y-%m-%d") file=$(echo bz-report-$now.html) printf "%s\n" Generating file: $file #cat bz-report-template.html > $file cat > $file <<'EOF' Boozang - Test Execution Summary

Test Execution Summary

Summary
EOF printf "" $total_scenarios >> $file cat >> $file <<'EOF' EOF printf "" $failed_scenarios >> $file cat >> $file <<'EOF' EOF printf "" $number_of_workers >> $file cat >> $file <<'EOF'
Total Scenarios%s
Failed Scenarios%s
Total Workers%s
Test Steps
EOF printf "" $total >> $file cat >> $file <<'EOF' EOF printf "" $failed >> $file cat >> $file <<'EOF' EOF printf "" $skipped >> $file cat >> $file <<'EOF' EOF printf "" $pending >> $file cat >> $file <<'EOF'
Total%s
Failed%s
Skipped%s
Pending%s
Total Issues
EOF printf "" $application_issues >> $file cat >> $file <<'EOF' EOF printf "" $automation_issues >> $file cat >> $file <<'EOF' EOF printf "" $unknown_issues >> $file cat >> $file <<'EOF' EOF printf "" $tbd_issues >> $file cat >> $file <<'EOF'
Application%s
Automation%s
Unknown%s
To be defined%s
Failed Scenario Breakdown
EOF printf "" $application_impact $application_impact_percent >> $file cat >> $file <<'EOF' EOF printf "" $automation_impact $automation_impact_percent >> $file cat >> $file <<'EOF' EOF printf "" $unknown_impact $unknown_impact_percent >> $file cat >> $file <<'EOF' EOF printf "" $tbd_impact $tbd_impact_percent >> $file cat >> $file <<'EOF'
Application fails%s (%s%%)
Automation fails%s (%s%%)
Unknown fails%s (%s%%)
TBD fails%s (%s%%)
EOF cat >> $file <<'EOF'
EOF if [ -z "$unique_issues" ] then printf "" >> $file else while IFS= read -r line ; do echo "
Impact Error Hash Description Type Scope Url
No issues found
" >> $file; echo $line | sed 's~_#~~g' | sed 's/\s+/,/' |sed 's/#@null@#/-/g' | sed 's/null/-/g' |sed 's/#@/\/g'|sed 's/#@/\/g' |sed 's/#-//g'| sed 's/-#/\<\/a>/g'|sed 's~_^~~g' >> $file; done <<< "$unique_issues" printf "
" >> $file; fi cat >> $file <<'EOF'
EOF if [ -z "$slow_steps" ] then printf "" >> $file else while IFS= read -r line ; do echo "" >> $file; done <<< "$slow_steps" printf "
Time Test Step
No test steps found
" >> $file; echo $line | sed 's~_#~~g' |sed 's/|/\n/g' >> $file; echo "
" >> $file; fi cat >> $file <<'EOF'
EOF if [ -z "$worker_list" ] then printf "" >> $file else while IFS= read -r line ; do echo "" >> $file; done <<< "$worker_list" printf "
Start End Worker Test id Test name
No workers found
" >> $file; echo $line | sed 's~_#~~g' |sed 's/|/\n/g' >> $file; echo "
" >> $file; fi cat >> $file <<'EOF'
EOF now=$(date +"%Y-%m-%d") csvfile=$(echo bz-issues-$now.csv) printf "%s\n" Generating CSV issue file: $csvfile if [ -z "$unique_issues" ] then printf "No issues found. No CSV file exported." >> $csvfile else while IFS= read -r line ; do echo $line | sed 's~_#~,~g' | sed 's/\s+/,/' |sed 's/|/\n/g' |sed 's/#@null@#/-/g' | sed 's/null/-/g' |sed 's/#@/\,/g' |sed 's/@#//g' >> $csvfile; done <<< "$unique_issues" fi # Return error code if any non-automation issues exists if [ -z "$unique_issues" ] || [ "$total_issues" == "$automation_issues" ] then echo "No non-automation issues found. Exiting with status code 0" exit 0 else echo "Issues found. Exiting with status code 1" exit 1 fi