Re: Vugen 11.52 + Truclient: Force transaction to fail (1665 Views)
Valued Contributor
Posts: 75
Registered: ‎01-05-2012
Message 1 of 3 (1,700 Views)
Accepted Solution

Vugen 11.52 + Truclient: Force transaction to fail

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?



Trusted Contributor
Posts: 125
Registered: ‎11-20-2011
Message 2 of 3 (1,671 Views)

Re: Vugen 11.52 + Truclient: Force transaction to fail

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.


Valued Contributor
Posts: 75
Registered: ‎01-05-2012
Message 3 of 3 (1,665 Views)

Re: Vugen 11.52 + Truclient: Force transaction to fail

[ Edited ]

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:


Lucky Workaround.PNG


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.

The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.