You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a gem called Captain Hook that adds before/after hooks to arbitrary objects. I built it for the purpose of DRYing up my automation code. I have a gist up of at PageObject extension that defines a new set of "hookable" accessors. It works be replacing the "_element" method PageObject adds to return a Watir element wrapped by a Captain Hook "Hookable" wrapper (A small SimpleDelegator wrapper).
The gist is way bigger than the changes it makes. It's as big as it is because it needs to override the shortcut methods that bypass the Watir element if we've hooked the method being short circuited.
I've been testing it in a large project for the past few weeks ensuring it works as intended and is actually useful before going public. Originally I had some caching built in to avoid building the Hookable object each time we instantiated an element, but that turned out to be a terrible idea.
The DSL allows for more complicated hooks where parameters are passed as well as using procs/lambdas. It also has the notion of a "context" for the method call, allowing the hook to make calls on other objects.
I'm opening this ticket to see if there's interest in merging this into PageObject itself, perhaps as the default accessors, or if I should continue with my original plan of making it part of a wider extension Gem.
The text was updated successfully, but these errors were encountered:
I have a gem called Captain Hook that adds before/after hooks to arbitrary objects. I built it for the purpose of DRYing up my automation code. I have a gist up of at PageObject extension that defines a new set of "hookable" accessors. It works be replacing the "_element" method PageObject adds to return a Watir element wrapped by a Captain Hook "Hookable" wrapper (A small SimpleDelegator wrapper).
The gist is way bigger than the changes it makes. It's as big as it is because it needs to override the shortcut methods that bypass the Watir element if we've hooked the method being short circuited.
I've been testing it in a large project for the past few weeks ensuring it works as intended and is actually useful before going public. Originally I had some caching built in to avoid building the Hookable object each time we instantiated an element, but that turned out to be a terrible idea.
With it I can declare a set of hooks like so:
Then use them when I declare the elements:
Hooks can be combined for composition:
The DSL allows for more complicated hooks where parameters are passed as well as using procs/lambdas. It also has the notion of a "context" for the method call, allowing the hook to make calls on other objects.
I'm opening this ticket to see if there's interest in merging this into PageObject itself, perhaps as the default accessors, or if I should continue with my original plan of making it part of a wider extension Gem.
The text was updated successfully, but these errors were encountered: