Exit scenario on failure

I have a simulation that involves getting a link from an email then doing a bunch of stuff with it. Sometimes an email never gets sent. When that happens none of the steps after that are useful. Here’s my (failed) attempt to address:

.exitBlockOnFail(
exec()
.exec(ApiSignatureRequest.sendRequest)
.exec(_.set(“signerLink”, “”))
.exec(SignDocument.getSignerLink) // this is the method that looks for the email and sets signerLink
.exec(
doIfEqualsOrElse(session => session(“signerLink”).as[String], “”) {
exec(session => {

Failure(“Unable to get signer link”)
session
})
} {
System.out.println(“Link Found ${signerLink}”)
}
)
.exec(SignDocument.visitSignerPage)
…more things…
)

The “Unable to get signer link” message appears on the logs but all of the things following it are still executed. Any suggestions?

Thanks,

  • Michael

Hi Michael,

I think you want to do

`
exec(_.markAsFailed)

`

instead of returning the unchanged session in the failure case.

Hi Max,

That did exactly what I wanted it to do, thank you. One follow up question…
The resulting report shows no failures or ko, is there a way to indicate that all is not as it should be on the reporting side?

Hi Michael,

To have that in the reports I think the StatsEngine is needed, I do not think it is outside an Action.

If getting the singerLink is an HTTP call, you can use the .check and .saveAs.

Then you do not even have to check if that session attribute exists manually, as a failed check will fail the session.

BTW even if you cannot do that, I don’t think you have to set the session to empty string initially.

As you can use “{singerLink.exists()}” for the condition. You can refer to the doc on Expression Language.

Regards,
George

Hi George,

Thanks for the reply. It’s not an http call, I’ll see if I can’t wrestle in a check there somehow anyway. Excellent tip on not having to initialize that session var.

Thanks again,

  • Michael