Checks that depend on values from previous checks

I’d like to extract an attribute from a parent element (eg the ‘action’ value from a form), and then use this value to extract an attribute (eg the ‘name’ from an input) from a child element. I’ve achieved this so far by calling .check(A).check(B), with both optional. However, when check A fails to find a value, check B errors, as ${formAction} does not contain a value.

What’s the best way of achieving this to avoid errors? Is conditional logic within HttpChecks possible?

def extractFormAction(): HttpCheck = {

css(“form[method=‘get’]”,“action”)

.find

.optional

.saveAs(“formAction”)

}

def extractInputName(): HttpCheck = {

css(“form[action=’${formAction}’] input”,“name”)

.find

.optional

.saveAs(“formInputName”)

}

def getAndCheck(actionName: String, url : String): ChainBuilder = {

exec(http(actionName).get(url)

.check(extractFormAction).check(extractInputName))

}

Thanks,

Rob