selenium - How to invoke all instance methods of a class in Ruby? -
i'm working on throwing own little test method runner script.
i need way call of methods in class. when invoke run_tests method, program stuck in infinite loop. causing , solutions?
class fadtest < seleniumtest def can_open_page @driver.get(@base_url + "/") wait_element_present(:link, "doctors") @driver.find_element(:link, "doctors").click puts "page opened" end def test_method puts "it works" end def run_tests klass = self.class klass.instance_methods(false).each |method| klass.instance_method(method).bind(self).call end end end
as mentioned wand maker, run_tests involves recursion. code being executed in following manner:
- find class of object
- call
someclass.instance_methods.each {} - once reach
run_tests, start iteration on again. - infinite loop -- never reach remaining instance methods.
i not sure how have designed tests, here few options solve problem
if tested objects have class fadtest, can edit logic within iteration, preferred solution what tin man suggested
klass.instance_methods(false).each |method| next if method == :run_tests # ... end only problem still scanning :run_tests element. if want remain full proof , not have :run_tests in array, can try what cary swoveland suggested:
(klass.instance_methods(false) - [:run_tests]).each {} if class of tested object is not fadtest, suggest rewrite of method.
def self.run_tests(object) klass = object.class klass.instance_methods(false).each {} end fadtest.run_tests(some_object)
Comments
Post a Comment