Best Site_prism code snippet using ClassMethods.create_helper_method
element_container.rb
Source:element_container.rb
...138 define_method(name) do139 raise Appom::InvalidElementError140 end141 end142 def create_helper_method(proposed_method_name, *find_args)143 if find_args.empty?144 create_error_method(proposed_method_name)145 else146 yield147 end148 end149 ##150 # Try to get all elements until not get empty array151 #152 def create_get_all_elements(element_name, *find_args)153 method_name = "get_all_#{element_name}"154 create_helper_method(method_name, *find_args) do155 define_method(method_name) do |*runtime_args|156 args = merge_args(find_args, runtime_args)157 wait_until_get_not_empty(*args)158 end159 end160 end161 ##162 # Try to get all sections until not get empty array163 #164 def create_get_all_sections(section_class, element_name, *find_args)165 method_name = "get_all_#{element_name}"166 create_helper_method(method_name, *find_args) do167 define_method(method_name) do |*runtime_args|168 args = merge_args(find_args, runtime_args)169 wait_until_get_not_empty(*args).map do |element|170 section_class.new(self, element)171 end172 end173 end174 end175 ##176 # Check element exist177 # We will try to find all elements with *find_args178 # Condition is pass when response is not empty179 #180 def create_existence_checker(element_name, *find_args)181 method_name = "has_#{element_name}"182 create_helper_method(method_name, *find_args) do183 define_method(method_name) do |*runtime_args|184 args = merge_args(find_args, runtime_args)185 wait_until('at least one element exists', *args)186 end187 end188 end189 ##190 # Check element non-existent191 # We will try to find all elements with *find_args192 # Condition is pass when response is empty193 #194 def create_nonexistence_checker(element_name, *find_args)195 method_name = "has_no_#{element_name}"196 create_helper_method(method_name, *find_args) do197 define_method(method_name) do |*runtime_args|198 args = merge_args(find_args, runtime_args)199 wait_until('no element exists', *args)200 end201 end202 end203 ##204 # Wait until element will be enable205 #206 def create_enable_checker(element_name, *find_args)207 method_name = "#{element_name}_enable"208 create_helper_method(method_name, *find_args) do209 define_method(method_name) do |*runtime_args|210 args = merge_args(find_args, runtime_args)211 wait_until('element enable', *args)212 end213 end214 end215 ##216 # Wait until an element will be disable217 #218 def create_disable_checker(element_name, *find_args)219 method_name = "#{element_name}_disable"220 create_helper_method(method_name, *find_args) do221 define_method(method_name) do |*runtime_args|222 args = merge_args(find_args, runtime_args)223 wait_until('element disable', *args)224 end225 end226 end227 ##228 # Get parameter is passed when declared element229 #230 def create_get_element_params(element_name, *find_args)231 method_name = "#{element_name}_params"232 create_helper_method(method_name, *find_args) do233 define_method(method_name) do234 merge_args(find_args)235 end236 end237 end238 ##239 # Extract section options240 # @return section class name and the remaining parameters241 #242 def extract_section_options(args, &block)243 if args.first.is_a?(Class)244 klass = args.shift245 section_class = klass if klass.ancestors.include?(Appom::Section)246 end...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!