Last active
December 3, 2017 00:20
-
-
Save Donavan/5612894a2fb8910088b9b95c9837e799 to your computer and use it in GitHub Desktop.
PageObject Weirdness
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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