Skip to content

How do I get the details (instruction Id & instruction) of the failed command(s) in the test run

This example demonstrates how to fetch the information of failures like instruction id or the failed instruction in the flow of execution if any exceptions came up during execution.

In the example below, we have two scripts where the first script has the application flow with verification while the second script has the steps to be executed when there is a failure in application flow. The execution jumps to the Test Script (exception handler Test Script) upon any failure in Exception Handler Code from command "setExceptionHandlerContext". Script 2 sends an email about the error captured in the first script.

Solution:

Script 1:

# Command Target Value
Enter Age
1 type id="txt_age" 45 
Enter Income
2 type id="txt_income" 55000 
Enter Zipcode
3 type
id="txt_ZipCode"
10001 
Click on the Calculate button
4 click
id="btn_calculateControls"

Verify the PDP page
5 assertText
//div[@id="outputheader"]/h1
Results
To get if there is any Failed Command and store the presence of command in variable "FailedCommand"
6 getFailedInstructionCommand
FailedCommand
 
If FailedCommand returns any value/text, execute exception handling script
7 if
"${FailedCommand}"!=""
 
Print the value in FailedCommand
8 echo
${FailedCommand} 
To get the instruction ID of the failed instruction
9 getFailedInstructionId
InstructionID
To get the instruction ID of the last failed instruction
10 getIdentifierForLastFailedInstruction
LastFailedInstructionIdentifier 
Execute the handler script
11 setExceptionHandlerContextScript 2(W)
End the if statement
12 endIf
 

Script 2: 

# Command Target Value
To begin the email service block
1 emailBlockStart    
To set the sender for the composed email
2 setSender info@eureqatest.com  
To set the subject for the composed and email
3 setSubject Worksoft SaaS Notification: <Subject>  
To set the "To" recipient list for the composed email
4 setRecipientToList recipient1@gmail.com  
To create the email body with a variable name
5 createBody body_template  
To create an email body part from Text or HTML string
6 createBodyPartFromTextOrHTML

Hi <mention recipient's name here>,<br/> 
<mention your body text here such as "product not available" with> Failed Command - ${FailedCommand} <br/>

Failed Instruction ID - ${FailedInstructionID } <br/>

Last Failed Instruction Identifier - ${LastFailedInstructionIdentifier}

body_template
To set the screenshot captured during the test run as an attachment to the email
7 setAttachmentScreenshot ${LastFailedInstructionIdentifier}  
To send the composed email to the sender&rsquo;s specified in <To> list
8 sendEmail    
End of the email block
9 emailBlockEnd    

Tips, Tricks, Gotchas & Best Practices:  

  • Customization of the emails can be done. Refer to Email command examples.
  • As a best practice, it is always advisable to define the variable names without any spaces and if you want to differentiate the words, use underscore or hyphen.

Representative Usage Scenarios for this Example:

Use Case #1:

Consider an e-commerce site, for example, 'Amazon' where when product availability is to be verified or if the page you have accessed is loaded correctly is to be tested for and if there are any exceptions, then you can use these exception handling commands to customize the outcome you require. 

Feedback and Knowledge Base