Run Keyword Unless and Continue on Failure
After 2 generic articles (click link1 , click link2) about Robot framework, I decided to focus on one amazing feature, the keywords witch drives the test case execution brilliantly!
The keywords we are talking about are: Run Keywords , Run Keyword If , Run Keyword And Ignore Error , Run Keyword And Continue On Failure , Run Keyword And Return Status
To demonstrate the use of these keywords I will use a very simple test case scenario using the SSH library witch aim to confirm if a file exists on a remote path/machine. For audit scenario I will need to expose all files in that folder and end of test so they can achieve that test step.
For this exercise I created 3 test cases witch run result will vary between one Test Case achieving success and two that fail.
So, In the "Test Case Script Snippet 1 image" we can see the use of keyword Run Keywords (see number 1) to invoke sequential others actions at same "test step". It is a simple and practical way, mainly to do simple actions, mainly actions we don't want to get any value for storage in running variables.
Test Case Script Snippet 1
In the same image ("Test Case Script Snippet 1") we can see the number "2" (Run Keyword If) is one of ones I like most and use often in the testing script code. I do it because it will do actions based on variables. In example "C", I am assigning the word "Windows" or "Linux" to the variable ${SO} (operating system) depending on the content of the variables obtained in the previous steps (see "B" at image). This flexibility allows to create decision trees, procedure very similar to what we do on SQL syntax: "Case When Statement".
Lastly, in the case of the 3a and 3b marks at first image, I use the keyword Run Keyword and Return Status to makes a "indirect bypass" to the next keyword which for that reason, won't fail the fully test case but only the test step. Still we collecting and storing that result in a variable "${Output_file_exist}. This kind of use is particularly important because the test case globally will not fail in the execution log (see Test Case Execution Log 1 figure) and only if the software tester check the detail at the step they can identify the failed step.
Execution by Test editor for Robot Framework 1
Test Case Execution Log 1
In test cases number 2 and 3 both will fail globally. However, the way I induce them to fail is different because in the third test case we catch the detail of the error during the execution and in the second we don't do that.
Thus, in test case number 2, at block "F", we use the action Run Keyword If validating whether the output of the file exists is positive ( ${output_File_Exist}=true) or negative (false). So, carrying that information we failed the test by using keyword Fail (BuiltIn library). But even we want the test case to fail globally, we still want to run the remaining steps and for that reason we put at the beginning of the line the Robot Framework action Run Keyword And Continue On Failure (marked with number 4).
Test Case Script Snippet 2
Execution by Test editor for Robot Framework 2
Test Case Execution Log 2
In third test case, we assume a big difference to second. We say that even if the test case fail the validation (File Should Exist , library SSH), we always will ignore this error and proceed (see block marked with G and number 5: Run Keyword And Ignore Error). So in this block (marked with G), instead of associating just one variable (like previous test cases), we will associate two variables to the execution result: ${Result_state} and ${Result_detail}.
Using the "ignore error" keyword syntax, this test case would never fail. That is why we need to add the H block, where we will use the output of variable $ {Result_state} in the case of fail to transmit that outcome to global test run even at the same time continue the execution: "ELSE IF "${Result_State}" == "FAIL" Run Keyword And Continue On Failure BuiltIn.Fail".
In the RIDE execution console of it is very clear that the variable $ {Result_detail} recorded a complete detail capable of being read for any tester who need to debugging the test case: "File '\ Users \ File_1.zip' does not exist"
Test Case Script Snippet 3
Execution by Test editor for Robot Framework 3
Test Case Execution Log 3
Conclusion :
The execution of scripted actions by the Robot Framework of the type "Run Keyword ...." can hide step errors but if it is well controlled, it can be a very powerful and flexible instrument in the provision tolerance and robustness to the test case, allowing to deal with several obstacles during execution.
-----------------------------
#NovabaseFSI #Novabase #Testing #Tester #RobotFramework #TestAutomation #RPA #SoftwareTester
Source: https://www.linkedin.com/pulse/robot-framework-my-journey-part-ii-paulo-jos%C3%A9-e-v-matos
Post a Comment for "Run Keyword Unless and Continue on Failure"