public class OrWebTask extends CompositeWebTask
CompositeWebTask
which chains subtasks in a logical OR.
It allows to handle situations where it is not known exactly what
the state of the SUT before a task starts will be, but
it is known that there are only X possible initial states.
With OrWebTask
, you can write one task for each of
the possible scenarios to handle, and have them executed in turn,
until one finishes without throwing any exception.
In case none of the alternatives finishes cleanly, then the last
thrown exception will be thrown.
All of the subtasks must be homogeneous, i.e. they all must finish on
the same page when they don't fail.
In its most basic form, OrWebTask
runs subtasks in order,
until one succeeds.
This works as long as each of the failing subtasks leaves the state of
the page and the DOM intact, in a way that the next alternative is able
to run cleanly as if the previous ones had never run.
For this condition to hold, for example, each alternative
should be always on the very same page, at any time,
never navigate to another page, and should not change the state
of dialogs (i.e. should not open dialogs which were not initially open,
or close dialogs which were initially open).
This constraint can be removed by implementing a mechanism that restores the initial situation. Two possible ways:
OrWebTask
which runs
a separate "restorer" task every time an alternative subtask fails
In the basic form, in other words by default, the "restorer"
is a WebTasks.nullTask()
.
It can be changed with withRestorer(WebTask)
.
logger, user
Constructor and Description |
---|
OrWebTask(List<WebTask> subtasks) |
OrWebTask(WebTask... subtasks) |
Modifier and Type | Method and Description |
---|---|
WebPage |
run(WebPage initialPage)
Runs each subtask in order, and finally return the
page that the last task was visiting.
|
OrWebTask |
withRestorer(WebTask restorer) |
append, iterator
browser, driver, getUser, setUser
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEach, spliterator
public OrWebTask(WebTask... subtasks)
public WebPage run(WebPage initialPage)
CompositeWebTask
run
in interface WebTask
run
in class CompositeWebTask
initialPage
- the page it is displayed before this task startsCopyright © 2015. All rights reserved.