Skip to content

Instantly share code, notes, and snippets.

@arjunKumbakkara
Last active January 8, 2018 12:38
Show Gist options
  • Save arjunKumbakkara/3c3ae72e09e0448638fd4362d9dccbbf to your computer and use it in GitHub Desktop.
Save arjunKumbakkara/3c3ae72e09e0448638fd4362d9dccbbf to your computer and use it in GitHub Desktop.
A Script to Automate Jmeter Load testing and the calculated TPS (Througput) is clipped into a file. With Hardcoded JMXs. #NOTE : Hardcode your JMX Test Plans and Happy running !
#!/bin/bash\
# Author : Arjun Kumbakkara
# Copyright (c) 2k17, 6dTechnologies
# Automates the Jmeter Test plan Execution and Clips the value Average Rate (which translates to Throughput aka TPS )
#PreRequisite: The JMX Test Plan (*.jmx) has to have the pattern ##-ValidToken-## (As Token expiration can occur any unmonitored timestamp)
#__________________________________________________________
#<elementProp name="" elementType="Header">
#<stringProp name="Header.name">X-Authorization</stringProp>
#<stringProp name="Header.value">12validatetoken12</stringProp>
#</elementProp>
#__________________________________________________________
echo "Automated Test Plan Execution v0.1"
echo "Below are the Preloaded JMX testplans."
echo "__________________________________________________"
echo " OPTION = 1 | FEATURE_API = Fetch Sim Assets"
echo " OPTION = 2 | FEATURE_API = Fetch Home IMSI Range"
echo " OPTION = 3 | FEATURE_API = Fetch MSISDN Range"
echo " OPTION = 4 | FEATURE_API = Fetch Available Home IMSI"
echo " OPTION = 5 | FEATURE_API = Fetch Available MSISDN"
echo " OPTION = 6 | FEATURE_API = Fetch Sponsor"
echo " OPTION = 7 | FEATURE_API = Fetch Available Sponsor IMSI"
echo " OPTION = 8 | FEATURE_API = Fetch Rate Zone"
echo " OPTION = 9 | FEATURE_API = Fetch Destination List"
echo " OPTION = 10 | FEATURE_API = Fetch Roaming Profile"
echo " OPTION = 11 | FEATURE_API = Fetch PDP Profile"
echo "__________________________________________________"
echo "Choose one as your input"
read -p "Choice:" feature
if [[ $feature -eq 0 ]] ; then
echo "ATTENTION: No Feature argument supplied"
exit 0
fi
if [ "$feature" == "1" ]; then
FEATURE="FETCH_ASSETS"
elif [ "$feature" == "2" ]; then
FEATURE="FETCH_HOME_IMSI_RANGE"
elif [ "$feature" == "3" ]; then
FEATURE="FETCH_MSISDN_RANGE"
elif [ "$feature" == "4" ]; then
FEATURE="FETCH_AVAILABLE_HOME_IMSI"
elif [ "$feature" == "5" ]; then
FEATURE="FETCH_AVAILABLE_MSISDN"
elif [ "$feature" == "6" ]; then
FEATURE="FETCH_SPONSOR"
elif [ "$feature" == "7" ]; then
FEATURE="FETCH_AVAILABLE_SPONSOR_IMSI"
elif [ "$feature" == "8" ]; then
FEATURE="FETCH_RATE_ZONE"
elif [ "$feature" == "9" ]; then
FEATURE="FETCH_DESTINATION_LIST"
elif [ "$feature" == "10" ]; then
FEATURE="FETCH_ROAMING_PROFILE"
elif [ "$feature" == "11" ]; then
FEATURE="FETCH_PDP_PROFILE"
else
echo "ATTENTION: UnIdentified Argument."
exit 0
fi
echo "__________________________________________________"
echo "Chosen Feature : $FEATURE"
echo ""
echo "Supply a valid Token for further processing"
echo ""
read -p "Valid Token:" token
echo ""
echo "Supplied valid Token : $token"
echo "__________________________________________________"
echo ""
echo "Automated Test Plan Execution Started....."
#cd /home/admin/JMETER/
#echo $PWD
RESULT_PATH=/opt/jmeter/JMETER/Result/
echo "Generated JTL file----> $PWD"/"$FEATURE_LOG.jtl "
echo ""
echo "JMX File used: $FEATURE".jmx
tokenValue="Bearer $token"
echo ""
echo "Token validation started..."
LEN=$(echo ${#token})
if [ $LEN -lt 100 ]; then
echo "Invalid Token "
exit 0
else
echo "Supplied token is length validated."
fi
echo ""
echo "Finally Formed X-Authorization Header : Bearer $token"
echo ""
#Replacing token tag .
#<stringProp name="Header.value">token.value.here</stringProp>
sed -i s/12validatetoken12/$token/g "$FEATURE".jmx
if [ ! -f "$FEATURE".jmx ]
then
echo "FATAL ERROR: JMX File Missing."
exit 0
fi
if [ -f "$RESULT_PATH$FEATURE"_LOG.jtl ]
then
rm "$RESULT_PATH$FEATURE"_LOG.jtl
fi
sh jmeter.sh -n -t "$FEATURE".jmx -l "$RESULT_PATH$FEATURE"_LOG.jtl
echo "Test plan executed anf JTL File generated. "
echo ""
echo "Moving to AggregateReport generation."
echo ""
echo "Ignore the ERROR immediate to this printing "
#$FILE = "$1"_LOG.txt
if [ -f "$RESULT_PATH$FEATURE"_LOG.txt ]
then
rm "$RESULT_PATH$FEATURE"_LOG.txt
fi
sh JMeterPluginsCMD.sh --generate-csv "$RESULT_PATH$FEATURE"_LOG.txt --input-jtl "$RESULT_PATH$FEATURE"_LOG.jtl --plugin-type AggregateReport
echo ""
echo "AggregateReport generated : $RESULT_PATH$FEATURE"_LOG.txt
echo "======================FULL REPORT PREVIEW=================================="
cat "$RESULT_PATH$FEATURE"_LOG.txt
echo "==========================================================================="
echo ""
echo "AggregateReport generated : $RESULT_PATH$FEATURE"_LOG.txt
#FILET = "$1"_THROUGHPUT.txt
if [ -f "$RESULT_PATH$FEATURE"_THROUGHPUT.txt ]
then
rm "$RESULT_PATH$FEATURE"_THROUGHPUT.txt
fi
echo "Resetting token tag in the JMX file..."
#ReplaceValue=$(cat $FEATURE.jmx)
#ReplaceValue=${ReplaceValue//##-ValidToken-##/$tokenValue}
#ReplaceValue=${ReplaceValue//$tokenValue/##-ValidToken-##}
sed -i s/$token/12validatetoken12/g "$FEATURE".jmx
echo "Token Tag reset."
echo ""
#clippedFile ="$PWD/FEATURE_THROUGHPUT.txt"
echo ">Throughput value is clipped into the below File. vi the below file to view details."
echo "$RESULT_PATH$FEATURE"_THROUGHPUT.txt
echo ""
cut -d, -f11 < "$RESULT_PATH$FEATURE"_LOG.txt > "$RESULT_PATH$FEATURE"_THROUGHPUT.txt
echo "Calculated Final Throughput :"
cut -d, -f11 < "$RESULT_PATH$FEATURE"_LOG.txt
echo ""
echo "TestPlan Execution ended."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment