How to use warn method of SitePrism Package

Best Site_prism code snippet using SitePrism.warn

dsl.rb

Source:dsl.rb Github

copy

Full Screen

...44 # The only DSL keywords that can use blocks are :section and :iframe45 def raise_if_block(obj, name, has_block, type)46 return unless has_block47 SitePrism.logger.debug("Type passed in: #{type}")48 SitePrism.logger.warn('section / iFrame can only accept blocks.')49 SitePrism.logger.error("#{obj.class}##{name} does not accept blocks")50 raise SitePrism::UnsupportedBlockError51 end52 # Warn users from naming the elements starting with no_53 def warn_if_dsl_collision(obj, name)54 return unless name.to_s.start_with?('no_')55 SitePrism.logger.warn("#{obj.class}##{name} should not start with no_")56 SitePrism::Deprecator.deprecate('Using no_ prefix in DSL definition')57 end58 # Sanitize method called before calling any SitePrism DSL method or59 # meta-programmed method. This ensures that the Capybara query is correct.60 #61 # Accepts any combination of arguments sent at DSL definition or runtime62 # and combines them in such a way that Capybara can operate with them.63 def merge_args(find_args, runtime_args, visibility_args = {})64 find_args = find_args.dup65 runtime_args = runtime_args.dup66 options = visibility_args.dup67 SitePrism.logger.debug("Initial args: #{find_args}, #{runtime_args}.")68 recombine_args(find_args, runtime_args, options)69 return [*find_args, *runtime_args, {}] if options.empty?70 [*find_args, *runtime_args, options]71 end72 # Options re-combiner. This takes the original inputs and combines73 # them such that there is only one hash passed as a final argument74 # to Capybara.75 #76 # If the hash is empty, then the hash is omitted from the payload sent77 # to Capybara, and the find / runtime arguments are sent alone.78 def recombine_args(find_args, runtime_args, options)79 options.merge!(find_args.pop) if find_args.last.is_a? Hash80 options.merge!(runtime_args.pop) if runtime_args.last.is_a? Hash81 options[:wait] = wait_time unless wait_key_present?(options)82 end83 # Detect if the +wait+ key is present in the options hash.84 # Note that setting it to to false or 0, still will return true here.85 def wait_key_present?(options)86 options.key?(:wait)87 end88 module ClassMethods89 attr_reader :expected_items90 def element(name, *find_args)91 SitePrism::Deprecator.deprecate('Passing a block to :element') if block_given?92 build(:element, name, *find_args) do93 define_method(name) do |*runtime_args, &element_block|94 warn_if_dsl_collision(self, name)95 raise_if_block(self, name, !element_block.nil?, :element)96 _find(*merge_args(find_args, runtime_args))97 end98 end99 end100 def elements(name, *find_args)101 SitePrism::Deprecator.deprecate('Passing a block to :elements') if block_given?102 build(:elements, name, *find_args) do103 define_method(name) do |*runtime_args, &element_block|104 warn_if_dsl_collision(self, name)105 raise_if_block(self, name, !element_block.nil?, :elements)106 _all(*merge_args(find_args, runtime_args))107 end108 end109 end110 def expected_elements(*elements)111 @expected_items = elements112 end113 def section(name, *args, &block)114 section_class, find_args = extract_section_options(args, &block)115 build(:section, name, *find_args) do116 define_method(name) do |*runtime_args, &runtime_block|117 warn_if_dsl_collision(self, name)118 section_element = _find(*merge_args(find_args, runtime_args))119 section_class.new(self, section_element, &runtime_block)120 end121 end122 end123 def sections(name, *args, &block)124 section_class, find_args = extract_section_options(args, &block)125 build(:sections, name, *find_args) do126 define_method(name) do |*runtime_args, &element_block|127 raise_if_block(self, name, !element_block.nil?, :sections)128 _all(*merge_args(find_args, runtime_args)).map do |element|129 section_class.new(self, element)130 end131 end132 end133 end134 def iframe(name, klass, *args)135 SitePrism.logger.debug('Block passed into iFrame construct at build time') if block_given?136 element_find_args = deduce_iframe_element_find_args(args)137 scope_find_args = deduce_iframe_scope_find_args(args)138 build(:iframe, name, *element_find_args) do139 define_method(name) do |&block|140 raise MissingBlockError unless block141 within_frame(*scope_find_args) { block.call(klass.new) }142 end143 end144 end145 def mapped_items(legacy: true)146 if legacy147 old_mapped_items148 else149 new_mapped_items150 end151 end152 private153 def old_mapped_items154 SitePrism::Deprecator.soft_deprecate(155 '.mapped_items on a class',156 'To allow easier recursion through the items in conjunction with #all_there?',157 '.mapped_items(legacy: false)'158 )159 @old_mapped_items ||= []160 end161 def new_mapped_items162 @new_mapped_items ||= {163 element: [],164 elements: [],165 section: [],166 sections: [],167 iframe: []168 }169 end170 def build(type, name, *find_args)171 if find_args.empty?172 create_error_method(name)173 else174 map_item(type, name)175 yield176 end177 add_helper_methods(name, *find_args)178 end179 def map_item(type, name)180 old_mapped_items << { type => name }181 new_mapped_items[type] << name.to_sym182 end183 def add_helper_methods(name, *find_args)184 create_existence_checker(name, *find_args)185 create_nonexistence_checker(name, *find_args)186 SitePrism::RspecMatchers.new(name)._create_rspec_existence_matchers if defined?(RSpec)187 create_visibility_waiter(name, *find_args)188 create_invisibility_waiter(name, *find_args)189 end190 def create_helper_method(proposed_method_name, *find_args)191 if find_args.empty?192 create_error_method(proposed_method_name)193 else194 yield195 end196 end197 def create_existence_checker(element_name, *find_args)198 method_name = "has_#{element_name}?"199 create_helper_method(method_name, *find_args) do200 define_method(method_name) do |*runtime_args|201 args = merge_args(find_args, runtime_args)202 element_exists?(*args)203 end204 end205 end206 def create_nonexistence_checker(element_name, *find_args)207 method_name = "has_no_#{element_name}?"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 element_does_not_exist?(*args)212 end213 end214 end215 def create_visibility_waiter(element_name, *find_args)216 method_name = "wait_until_#{element_name}_visible"217 create_helper_method(method_name, *find_args) do218 define_method(method_name) do |*runtime_args|219 args = merge_args(find_args, runtime_args, visible: true)220 return true if element_exists?(*args)221 raise SitePrism::ElementVisibilityTimeoutError222 end223 end224 end225 def create_invisibility_waiter(element_name, *find_args)226 method_name = "wait_until_#{element_name}_invisible"227 create_helper_method(method_name, *find_args) do228 define_method(method_name) do |*runtime_args|229 args = merge_args(find_args, runtime_args, visible: true)230 return true if element_does_not_exist?(*args)231 raise SitePrism::ElementInvisibilityTimeoutError232 end233 end234 end235 def create_error_method(name)236 SitePrism.logger.error("#{name} has come from an item with no locators.")237 define_method(name) { raise SitePrism::InvalidElementError }238 end239 def deduce_iframe_scope_find_args(args)240 warn_on_invalid_selector_input(args)241 case args[0]242 when Integer then [args[0]]243 when String then [:css, args[0]]244 else args245 end246 end247 def deduce_iframe_element_find_args(args)248 warn_on_invalid_selector_input(args)249 case args[0]250 when Integer then "iframe:nth-of-type(#{args[0] + 1})"251 when String then [:css, args[0]]252 else args253 end254 end255 def warn_on_invalid_selector_input(args)256 return unless looks_like_xpath?(args[0])257 SitePrism.logger.warn('The arguments passed in look like xpath. Check your locators.')258 SitePrism.logger.debug("Default locator strategy: #{Capybara.default_selector}")259 end260 def looks_like_xpath?(arg)261 arg.is_a?(String) && arg.start_with?('/', './')262 end263 def extract_section_options(args, &block)264 if args.first.is_a?(Class)265 klass = args.shift266 section_class = klass if klass.ancestors.include?(SitePrism::Section)267 end268 section_class = deduce_section_class(section_class, &block)269 arguments = deduce_search_arguments(section_class, args)270 [section_class, arguments]271 end...

Full Screen

Full Screen

deprecator.rb

Source:deprecator.rb Github

copy

Full Screen

...3 class Deprecator4 class << self5 def deprecate(old, new = nil)6 if new7 warn("#{old} is being deprecated and should no longer be used. Use #{new} instead.")8 else9 warn("#{old} is being deprecated and should no longer be used.")10 end11 warn("#{old} will be removed in SitePrism v4. You have been warned!")12 end13 def soft_deprecate(old, reason, new = nil)14 debug("The #{old} method is changing, as is SitePrism, and is now configurable.")15 debug("REASON: #{reason}.")16 debug('Moving forwards into SitePrism v4, the default behaviour will change.')17 debug("We advise you change to using #{new}") if new18 end19 private20 def warn(msg)21 SitePrism.logger.warn(msg)22 end23 def debug(msg)24 SitePrism.logger.debug(msg)25 end26 end27 end28end

Full Screen

Full Screen

warn

Using AI Code Generation

copy

Full Screen

1 def warn(message)2 def warn(message)3 def warn(message)4 def warn(message)5 def warn(message)6 def warn(message)7 def warn(message)8 def warn(message)9 def warn(message)10 def warn(message)11 def warn(message)12 def warn(message)

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