Scripting – the essential skillset for a Quality Engineer – Part 2
Click here to read about Scripting- the essential skillset for a Quality Engineer- Part 1
There is more to scripting, however let me take a couple of examples to explain how scripting can be easy and take out the rudimentary tasks from your day-to-day work. Take it slow and steady to understand the example; it’s not a one time understanding across one single day . I kindly request the reader to invest certain time and effort within your 24/7 packed up schedule to gradually build up the skill of Shell Programming to reap its complete benefit.
Analysing a log file:
Original LOG FILE:
[106564]{223964}[144/221781529] 2015-10-12 15:40:04.557602 i TraceContext TraceContext.cpp(00827) : UserName=QA2 [106564]{223964}[144/221781529] 2015-10-12 15:40:04.557581 e LJIT cePopCustomLjit.cpp(00563) : Llang Runtime Error: Exception::SQLException301: unique constraint violated: TrexUpdate failed on table 'QA2:TEMPLATE' with error: unique constraint violation for table QA2:TEMPLATEen, constraint='$uc_UNI_3DBFC338$', value='V”^Ü∂üN·', pos=0; indexname=UNI_3DBFC338, rc=55
Let us go ahead and extract some useful information from the log:
- Find the file in log path, based on filename pattern.
- In the error log fine fine error message line based on pattern.
- Send the error details through email for further analysis.
- Include the system details and date time for reference in the error log file.
Here is the script that filters out the content that we require:
#! /bin/bash SID=$1 SYSNO=$2 HOST=10.113.23.45 PATTERN=Error_logs.txt >Error.log echo "SID = $SID" >>Error.log echo "SNO = $SYSNO" >>Error.log echo "Hostname= $HOST" >>Error.log echo "Script executed by user = "`whoami` >>Error.log echo `date` >>Error.log echo " " >>Error.log echo "Error Info:" >>Error.log grep -i 'error' $PATTERN.* | sed -n -e 's/^.*[Ee][Rr][Rr][Oo][Rr]/Error/p' >>Error.log echo "PFA of the Error logs" | `mail -a Error.log -s "Error Logs" [email protected] ` if ![ $? -eq 0 ] then echo "Script failed , Logs were not sent to mail" else echo "Script successful , Logs were sent to mail" fi
The final output from the log that can be emailed to a given user:
SID = TEST SNO = 02 Hostname = 10.113.23.45 USERNAME = QA2 Wed Oct 21 15:38:36 IST 2015
Error Info:
[106564]{223964}[144/221781529] 2015-10-12 15:40:04.557581 e LJIT cePopCustomLjit.cpp(00563) : Llang Runtime Error: Exception::SQLException301: unique constraint violated: TrexUpdate failed on table 'QA2:TEMPLATE' with error: unique constraint violation for table QA2:TEMPLATEen, constraint='$uc_UNI_3DBFC338$', value=‘V'
Test data creation to test maximum length:
- Field 1 – 10 Length – Number
- Field 2 – 64 Length – String
- Field 3 – 100 Length – Number
- Field 3 – 256 Length – String
Here is the script that can print length by the number of characters you require for integer or character data type:
echo "#############################" echo "Please provide the length : " echo "#############################" read len echo "#######################################" echo "Please provide the type of the field :" echo "Enter 1 for Number and 2 for String : " echo "#######################################" read type ch='A' num=1 if [ $type == 2 ] then printf '%*s' "$len" | tr ' ' "$ch" echo " " elif [ $type == 1 ] then printf '%*s' "$len" | tr ' ' "$num" echo " " else echo "Please provide correct inputs" echo " " fi
The output for the 10, 100 – numbers, 64, 256 – characters :
1111111111 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
To Conclude:
In the above examples:
- We learnt that scripting is not hard, it is easy
- We looked a couple of problem areas and came up with solutions
- Scripting helps QA become creative and eliminate the rudimentary tasks by automating them
I would want to take a minute to wish you good luck and promise that you will definitely reap great benefits and give u 100% assurance that this skill will make a tester’s life all the more interesting and fun .
By:
Shushma Amarnath
Coviam Technologies
Also published on Medium.
1 thought on “Scripting – the essential skillset for a Quality Engineer – Part 2”