-
Notifications
You must be signed in to change notification settings - Fork 12
Handle a detailed result of any operation
Ultron allows you to process the result of any operation in your own custom way. It provides full info to do that.
Let's loot at the example
object SomePage : Page<SomePage>{
private val espressoElement = withId(R.id.espressoId)
private val espressoWebViewElement = xpath("some_xpath")
private val uiautomatorElement = byResId(R.id.uiatomatorId)
}
Now, we want to catch the result of operation and do smth reasonable. There is a method that opens the door - withResultHandler
espressoElement.withResultHandler { operationResult ->
// smth that make sense
}
What it gives to us?
espressoWebViewElement
, uiautomatorElement
also have withResultHandler
method.
A little explanation in case you would like to be more familiar with Ultron framework
There is an entity which we call ResultHandler
. By default all Utron operations has the same ResultHandler
. It catches the result of operation and asks OperationResultAnalyzer
to analyze the result. In case operationResult.success
is false
the result analyzer throws catched exception.
There are 2 ways of using custom ResultHandler:
- Specify it for page property and it will be applied for all operations with this element
object SomePage : Page<SomePage>() {
private val eventStatus = withId(R.id.last_event_status).withResultHandler { operationResult ->
// smth that make sense
}
}
- Specify it inside special step there the element operation should be processed in different way. This ResultHandler will be applied only once for single operation.
object SomePage : Page<SomePage>() {
fun someSpecificUserStep(expectedEventText: String){
eventStatus.withResultHandler { operationResult ->
// smth that make sense
}.hasText(expectedEventText)
}
}