How to use convert_arguments method of ClassMethods Package

Best Howitzer_ruby code snippet using ClassMethods.convert_arguments

element_dsl.rb

Source:element_dsl.rb Github

copy

Full Screen

...19 include Helpers20 def self.included(base) # :nodoc:21 base.extend(ClassMethods)22 end23 def convert_arguments(args, options, block_args, block_options)24 conv_args = args.map { |el| el.is_a?(Proc) ? proc_to_selector(el, block_args, block_options) : el }25 args_options = pop_options_from_array(conv_args)26 block_args_options = pop_options_from_array(block_args)27 conv_options = [args_options, options, block_args_options, block_options].map do |el|28 el.transform_keys(&:to_sym)29 end.reduce(&:merge).except(:lambda_args)30 [conv_args, conv_options]31 end32 def proc_to_selector(proc, block_args, block_options)33 lambda_args = extract_lambda_args(block_args, block_options)34 if lambda_args35 if lambda_args[:keyword_args].present?36 proc.call(*lambda_args[:args], **lambda_args[:keyword_args])37 else38 proc.call(*lambda_args[:args])39 end40 else41 puts "WARNING! Passing lambda arguments with element options is deprecated.\n" \42 "Please use 'lambda_args' method, for example: foo_element(lambda_args(title: 'Example'), wait: 10)"43 proc.call(*block_args.shift(proc.arity))44 end45 end46 def extract_lambda_args(block_args, block_options)47 (block_args.first.is_a?(Hash) && block_args.first[:lambda_args]) || block_options[:lambda_args]48 end49 def pop_options_from_array(value)50 if value.last.is_a?(Hash) && !value.last.key?(:lambda_args)51 value.pop52 else53 {}54 end55 end56 # This module holds element dsl methods57 module ClassMethods58 include Helpers59 protected60 # Creates a group of methods to interact with described HTML element(s) on page61 # @note This method generates following dynamic methods:62 #63 # <b><em>element_name</em>_element</b> - equals capybara #find(...) method64 #65 # <b><em>element_name</em>_elements</b> - equals capybara #all(...) method66 #67 # <b><em>element_name</em>_elements.first</b> - equals capybara #first(...) method68 #69 # <b>wait_for_<em>element_name</em>_element</b> - equals capybara #find(...) method but returns nil70 #71 # <b>within_<em>element_name</em>_element</b> - equals capybara #within(...) method72 #73 # <b>has_<em>element_name</em>_element?</b> - equals capybara #has_selector(...) method74 #75 # <b>has_no_<em>element_name</em>_element?</b> - equals capybara #has_no_selector(...) method76 # @param name [Symbol, String] an unique element name77 # @param args [Array] original Capybara arguments. For details, see `Capybara::Node::Finders#all`.78 # @param options [Hash] original Capybara options. For details, see `Capybara::Node::Finders#all`.79 # @example Using in a page class80 # class HomePage < Howitzer::Web::Page81 # element :top_panel, '.top'82 # element :bottom_panel, '.bottom'83 # element :new_button, :xpath, ".//*[@name='New']"84 #85 # def press_top_new_button86 # within_top_panel_element do87 # new_button_element.click88 # end89 # end90 #91 # def press_bottom_new_button92 # within_bottom_panel_element do93 # new_button_element.click94 # end95 # end96 # end97 #98 # HomePage.on do99 # is_expected.to have_top_panel_element100 # press_top_new_element101 # is_expected.to have_no_new_button_element(match: :first)102 # end103 # @example Using in a section class104 # class MenuSection < Howitzer::Web::Section105 # me '.main-menu'106 # element :menu_item, '.item'107 #108 # def menu_items109 # menu_item_elements.map(&:text)110 # end111 # end112 # @raise [BadElementParamsError] if wrong element arguments113 # @!visibility public114 def element(name, *args, **options)115 validate_arguments!(args)116 define_element(name, args, options)117 define_elements(name, args, options)118 define_wait_for_element(name, args, options)119 define_within_element(name, args, options)120 define_has_element(name, args, options)121 define_has_no_element(name, args, options)122 end123 private124 def validate_arguments!(args)125 return unless args.map(&:class).count(Proc) > 1126 raise Howitzer::BadElementParamsError, 'Using more than 1 proc in arguments is forbidden'127 end128 def define_element(name, args, options)129 define_method("#{name}_element") do |*block_args, **block_options|130 conv_args, conv_options = convert_arguments(args, options, block_args, block_options)131 if conv_options.present?132 capybara_context.find(*conv_args, **conv_options)133 else134 capybara_context.find(*conv_args)135 end136 end137 private "#{name}_element"138 end139 def define_elements(name, args, options)140 define_method("#{name}_elements") do |*block_args, **block_options|141 conv_args, conv_options = convert_arguments(args, options, block_args, block_options)142 if conv_options.present?143 capybara_context.all(*conv_args, **conv_options)144 else145 capybara_context.all(*conv_args)146 end147 end148 private "#{name}_elements"149 end150 def define_wait_for_element(name, args, options)151 define_method("wait_for_#{name}_element") do |*block_args, **block_options|152 conv_args, conv_options = convert_arguments(args, options, block_args, block_options)153 if conv_options.present?154 capybara_context.find(*conv_args, **conv_options)155 else156 capybara_context.find(*conv_args)157 end158 return nil159 end160 private "wait_for_#{name}_element"161 end162 def define_within_element(name, args, options)163 define_method("within_#{name}_element") do |*block_args, **block_options, &block|164 conv_args, conv_options = convert_arguments(args, options, block_args, block_options)165 new_scope = if conv_options.present?166 capybara_context.find(*conv_args, **conv_options)167 else168 capybara_context.find(*conv_args)169 end170 begin171 capybara_scopes.push(new_scope)172 block.call173 ensure174 capybara_scopes.pop175 end176 end177 end178 def define_has_element(name, args, options)179 define_method("has_#{name}_element?") do |*block_args, **block_options|180 conv_args, conv_options = convert_arguments(args, options, block_args, block_options)181 if conv_options.present?182 capybara_context.has_selector?(*conv_args, **conv_options)183 else184 capybara_context.has_selector?(*conv_args)185 end186 end187 end188 def define_has_no_element(name, args, options)189 define_method("has_no_#{name}_element?") do |*block_args, **block_options|190 conv_args, conv_options = convert_arguments(args, options, block_args, block_options)191 if conv_options.present?192 capybara_context.has_no_selector?(*conv_args, **conv_options)193 else194 capybara_context.has_no_selector?(*conv_args)195 end196 end197 end198 end199 end200 end201end...

Full Screen

Full Screen

convert_arguments

Using AI Code Generation

copy

Full Screen

1 def foo(a, b, c)2 def bar(a, b, c)3 def baz(a, b, c)4p t.foo(1, 2, 3)5p t.bar(1, 2, 3)6p t.baz(1, 2, 3)7p t.foo(1, 2)8p t.bar(1, 2)9p t.baz(1, 2)10 def self.included(base)11 base.extend(ClassMethods)12 def convert_arguments(*methods)13 define_method(method) do |*args|14 super(*convert_arguments(args))15 def convert_arguments(args)16 args + [nil] * (arity - args.size)

Full Screen

Full Screen

convert_arguments

Using AI Code Generation

copy

Full Screen

1 def bar(a, b, c)2Foo.new.bar(1, "2", 3.0)3 def bar(a, b, c)4Foo.new.bar(1, "2", 3.0)5 def bar(a, b, c)6Foo.new.bar(1, "2")7 def bar(a, b, c)8Foo.new.bar(1, "2", 3.0, 4)

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful