Documentation ¶
Overview ¶
Package action provides the interface and utilities for funnctions which takes a context and returns an error on failure.
Index ¶
- type Action
- func Combine(name string, steps ...Action) Action
- func IfSuccessThen(preFunc, action Action) Action
- func Named(name string, fn Action) Action
- func Retry(n int, action Action, interval time.Duration) Action
- func RetrySilently(n int, action Action, interval time.Duration) Action
- func Sleep(duration time.Duration) Action
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Action ¶
Action is a function that takes a context and returns an error.
func Combine ¶
Combine combines a list of functions from Context to error into one function. Combine adds the name of the operation into the error message to clarify the step. It is recommended to start the name of operations with a verb, e.g.,
"open Downloads and right click a folder"
Then the failure msg would be like:
"failed to open Downloads and right click a folder on step ..."
func IfSuccessThen ¶
IfSuccessThen returns a function that runs action only if the first function succeeds. The function returns an error only if the preFunc succeeds but action fails, It returns nil in all other situations. Example:
dialog := nodewith.Name("Dialog").Role(role.Dialog) button := nodewith.Name("Ok").Role(role.Button).Ancestor(dialog) ui := uiauto.New(tconn) if err := action.IfSuccessThen(ui.Withtimeout(5*time.Second).WaitUntilExists(dialog), ui.LeftClick(button))(ctx); err != nil { ... }
func Named ¶
Named gives a name to an action. It logs when an action starts, and if the action fails, tells you the name of the failing action.
func Retry ¶
Retry returns a function that retries a given action if it returns error. The action will be executed up to n times, including the first attempt. The last error will be returned. Any other errors will be silently logged. Between each run of the loop, it will sleep according the specified interval.
func RetrySilently ¶
RetrySilently returns a function that retries a given action if it returns error. The action will be executed up to n times, including the first attempt. The last error will be returned. Any other errors will be ignored. Between each run of the loop, it will sleep according the specified interval.