How to log a message only when a step fails

Please advise on how to log a message only when a step fails using "Log message"or any other option. There shouldn’t be any logs when that particular activity doesn’t fail.

Are you using a try catch?

If a step fails it will go to the Catch of the Try Catch Block - you can then add your log message in there.

Or you can use an if statement with a boolean condition to determine if it has failed or not and add a log in the failed route.

1 Like

@Aaditya

Use log message in Catch Block with exception.message

Thanks

1 Like

@TimK I have not used Try catch yet. I may have to add more than 5 same log messages for few steps. can i use a single try catch block to cover all these steps…? I am trying to running a series of tests and need to see the logs and cross check the failures.

Yes you can place all your activities / steps inside a single try catch. If one of the activities fails, it will go straight to the catch and the other steps will not be executed.

Exception.Message will give you the specific failure reason

1 Like

what is you are condition??

1 Like

@Pradeep_Shiv I have to add 5+ same log messages at some key areas in my test. Whenever a step fails i need to capture the log for documentation. I need to run a series of batch where i will be away and i could see the logs and rectify the failed steps.

you can use log message Activity in that particular condition in a sequence and give like "Info"

1 Like

Yes. I thought so and tried and somehow i am missing the logs when it fails. May be i have not added them at right places.

after Element exist use if condition and pass element exist output in condition and pass the log message in Then part

1 Like