09-11-2013 09:36 AM
I need to programatically force a transaction to fail in TruClient BUT allow the script to keep running, as there are other transactions in the script that are not dependent on this transaction being successful. Is there any way to do this?
Solved! Go to Solution.
09-12-2013 07:10 AM
We don’t have continue on error as in other protocols in LR. However on Step Object we do have optional steps that may not fail the execution:
I have ask if we could have it in the future, and currently it is technical limitation, and they don't see way to add it.
09-12-2013 08:01 AM - edited 09-12-2013 08:09 AM
Thanks. In my situation, I actually need to FAIL the transaction, but continue with the execution of the script.
Here's actually the workaround that I came up with to accomplish what I wanted to do. Keep in mind that this is a simple workaround - I wouldn't usually check to see whether the 'Lucky' button exists before clicking on the 'Lucky' button, but it demonstrates the principle:
The first code block (step 1) contains the following code:
var isTransactionError = false;
The second code block (step 2, in the "Else" block) contains the following code; this is only found if the error condition is true:
isTransactionError = true;
The third code block (step 4, in the first "If" block) contains the following code, which is called if the transaction is in error:
LR.log("Sorry, you're not lucky today.","Error"); LR.endTransaction("I'm feeling lucky","Fail");
The final code block (step 4, in the "Else" block) is empty; it is there because if you attach the 'End Transaction' to the entire 'If' block, it will ALWAYS report successful, and if you place it on a transaction AFTER the 'If' block, it will complain that you're ending a transaction that isn't open.
Where I am primarily using this type of logic is if my application gives me a specific error screen if a specific condition occurs, i.e., "Customer not found." This allows me to create a custom error message for that condition using the LR.log() function, rather than expecting to see customer data and get an "object not found" error when I continue on to the next transaction.
I also use it with a CATCH block after the TruClient block I'm watching for the error on. Within that CATCH block is a code block that sets isTransactionError = true in order to emulate CONTINUE ON ERROR functionality.
I use these when the failure of a single transaction does NOT necessarily fail the entire script - i.e., if looking up different customer types pulls data from different databases; one DB may be down, impacting functionality, while others remain up and usable.