Skip to content

Instantly share code, notes, and snippets.

@Donavan
Last active December 3, 2017 00:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Donavan/5612894a2fb8910088b9b95c9837e799 to your computer and use it in GitHub Desktop.
Save Donavan/5612894a2fb8910088b9b95c9837e799 to your computer and use it in GitHub Desktop.
PageObject Weirdness
# Monkey patching PageObject to add to the DSL like this works
module PageObject
module Accessors
def text_field_hooked(name, identifier={:index => 0}, &block)
standard_methods(name, identifier, 'text_field_for', &block)
define_method(name) do
self.send("#{name}_element").value
end
define_method("#{name}=") do |value|
self.send("#{name}_element").value = value
end
end
end
end
# Trying to do it the right way doesn't:
class HookedTextField < PageObject::Elements::TextField
def self.accessor_methods(accessor, name)
accessor.send(:define_method, name) do
self.send("#{name}_element").value
end
accessor.send(:define_method,"#{name}=") do |value|
self.send("#{name}_element").value = value
end
end
end
PageObject.register_widget :text_field_hooked, HookedTextField, :text_field
# Technically BOTH of them work, however my test code was hooking value=
# If I do it the widget way there's no value= on the element!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment