How to use camel_case method of Selenium.WebDriver Package

Best Selenium code snippet using Selenium.WebDriver.camel_case

capabilities.rb

Source:capabilities.rb Github

copy

Full Screen

...125 next if value.nil?126 next if value.is_a?(String) && value.empty?127 capability_name = name.to_s128 snake_cased_capability_names = KNOWN.map(&:to_s)129 camel_cased_capability_names = snake_cased_capability_names.map(&w3c_capabilities.method(:camel_case))130 next unless snake_cased_capability_names.include?(capability_name) ||131 camel_cased_capability_names.include?(capability_name) ||132 capability_name.match(EXTENSION_CAPABILITY_PATTERN)133 w3c_capabilities[name] = value134 end135 # User can pass :firefox_options or :firefox_profile.136 #137 # TODO: (alex) Refactor this whole method into converter class.138 firefox_options = oss_capabilities['firefoxOptions'] || oss_capabilities['firefox_options'] || oss_capabilities[:firefox_options]139 firefox_profile = oss_capabilities['firefox_profile'] || oss_capabilities[:firefox_profile]140 firefox_binary = oss_capabilities['firefox_binary'] || oss_capabilities[:firefox_binary]141 if firefox_options142 WebDriver.logger.deprecate(':firefox_options capabilitiy', 'Selenium::WebDriver::Firefox::Options')143 end144 if firefox_profile145 WebDriver.logger.deprecate(':firefox_profile capabilitiy', 'Selenium::WebDriver::Firefox::Options#profile')146 end147 if firefox_binary148 WebDriver.logger.deprecate(':firefox_binary capabilitiy', 'Selenium::WebDriver::Firefox::Options#binary')149 end150 if firefox_profile && firefox_options151 second_profile = firefox_options['profile'] || firefox_options[:profile]152 if second_profile && firefox_profile != second_profile153 raise Error::WebDriverError, 'You cannot pass 2 different Firefox profiles'154 end155 end156 if firefox_options || firefox_profile || firefox_binary157 options = WebDriver::Firefox::Options.new(firefox_options || {})158 options.binary = firefox_binary if firefox_binary159 options.profile = firefox_profile if firefox_profile160 w3c_capabilities.merge!(options.as_json)161 end162 w3c_capabilities163 end164 end165 #166 # @param [Hash] opts167 # @option :browser_name [String] required browser name168 # @option :browser_version [String] required browser version number169 # @option :platform_name [Symbol] one of :any, :win, :mac, or :x170 # @option :accept_insecure_certs [Boolean] does the driver accept insecure SSL certifications?171 # @option :proxy [Selenium::WebDriver::Proxy, Hash] proxy configuration172 #173 # @api public174 #175 def initialize(opts = {})176 @capabilities = opts177 self.proxy = opts.delete(:proxy)178 end179 #180 # Allows setting arbitrary capabilities.181 #182 def []=(key, value)183 @capabilities[key] = value184 end185 def [](key)186 @capabilities[key]187 end188 def merge!(other)189 if other.respond_to?(:capabilities, true) && other.capabilities.is_a?(Hash)190 @capabilities.merge! other.capabilities191 elsif other.is_a? Hash192 @capabilities.merge! other193 else194 raise ArgumentError, 'argument should be a Hash or implement #capabilities'195 end196 end197 def proxy=(proxy)198 case proxy199 when Hash200 @capabilities[:proxy] = Proxy.new(proxy)201 when Proxy, nil202 @capabilities[:proxy] = proxy203 else204 raise TypeError, "expected Hash or #{Proxy.name}, got #{proxy.inspect}:#{proxy.class}"205 end206 end207 #208 # @api private209 #210 def as_json(*)211 hash = {}212 @capabilities.each do |key, value|213 case key214 when :platform215 hash['platform'] = value.to_s.upcase216 when :proxy217 if value218 hash['proxy'] = value.as_json219 hash['proxy']['proxyType'] &&= hash['proxy']['proxyType'].downcase220 hash['proxy']['noProxy'] = hash['proxy']['noProxy'].split(', ') if hash['proxy']['noProxy'].is_a?(String)221 end222 when String, :firefox_binary223 hash[key.to_s] = value224 when Symbol225 hash[camel_case(key.to_s)] = value226 else227 raise TypeError, "expected String or Symbol, got #{key.inspect}:#{key.class} / #{value.inspect}"228 end229 end230 hash231 end232 def to_json(*)233 JSON.generate as_json234 end235 def ==(other)236 return false unless other.is_a? self.class237 as_json == other.as_json238 end239 alias_method :eql?, :==240 protected241 attr_reader :capabilities242 private243 def camel_case(str)244 str.gsub(/_([a-z])/) { Regexp.last_match(1).upcase }245 end246 end # Capabilities247 end # W3c248 end # Remote249 end # WebDriver250end # Selenium...

Full Screen

Full Screen

options.rb

Source:options.rb Github

copy

Full Screen

2require 'selenium-webdriver'3module SauceBindings4 class Options5 class << self6 def camel_case(str)7 str.to_s.gsub(/_([a-z])/) { Regexp.last_match(1).upcase }8 end9 def chrome(**opts)10 opts[:browser_name] = 'chrome'11 opts[:valid_options] = ChromeConfigurations.valid_options12 Options.new(**opts)13 end14 def edge(**opts)15 if Selenium::WebDriver::VERSION[0] == '3'16 raise ArgumentError, 'Selenium 3 is not compatible with the Chromium based Microsoft Edge.'17 end18 opts[:browser_name] = 'MicrosoftEdge'19 opts[:valid_options] = EdgeConfigurations.valid_options20 Options.new(**opts)21 end22 def firefox(**opts)23 opts[:browser_name] = 'firefox'24 opts[:valid_options] = FirefoxConfigurations.valid_options25 Options.new(**opts)26 end27 def ie(**opts)28 opts[:browser_name] = 'internet explorer'29 opts[:valid_options] = IEConfigurations.valid_options30 Options.new(**opts)31 end32 def safari(**opts)33 opts[:browser_name] = 'safari'34 opts[:platform_name] ||= 'macOS 11'35 opts[:valid_options] = SafariConfigurations.valid_options36 Options.new(**opts)37 end38 end39 BROWSER_NAMES = {Selenium::WebDriver::Chrome::Options => 'chrome',40 Selenium::WebDriver::Edge::Options => 'MicrosoftEdge',41 Selenium::WebDriver::Firefox::Options => 'firefox',42 Selenium::WebDriver::IE::Options => 'internet explorer',43 Selenium::WebDriver::Safari::Options => 'safari'}.freeze44 W3C = %i[browser_name browser_version platform_name accept_insecure_certs page_load_strategy proxy45 set_window_rect timeouts unhandled_prompt_behavior strict_file_interactability].freeze46 SAUCE = %i[avoid_proxy build chromedriver_version command_timeout custom_data extended_debugging idle_timeout47 iedriver_version max_duration name parent_tunnel prerun priority public record_logs record_screenshots48 record_video screen_resolution selenium_version tags time_zone tunnel_identifier video_upload_on_pass49 capture_performance].freeze50 attr_reader :selenium_options, :timeouts51 def initialize(**opts)52 se_options = Array(opts.delete(:selenium_options))53 valid_options = opts.delete(:valid_options)54 if valid_options.nil?55 valid_options = SAUCE + W3C56 SauceBindings.logger.deprecate('Using `Options.new(opts)` directly',57 'static methods for desired browser',58 id: :options_init) { '(e.g., `Options.chrome(opts)`)' }59 end60 create_variables(valid_options, opts)61 @selenium_options = se_options.map(&:as_json).inject(:merge) || {}62 parse_selenium_options(se_options)63 @build ||= build_name64 @browser_name ||= selenium_options['browserName'] || 'chrome'65 @platform_name ||= 'Windows 10'66 @browser_version ||= 'latest'67 end68 def capabilities69 caps = selenium_options.dup70 W3C.each do |key|71 value = parse_w3c_key(key)72 caps[self.class.camel_case(key)] = value unless value.nil?73 end74 caps['sauce:options'] = {}75 caps['sauce:options']['username'] = ENV['SAUCE_USERNAME'] ||76 raise(ArgumentError, "needs username; use `ENV['SAUCE_USERNAME']`")77 caps['sauce:options']['accessKey'] = ENV['SAUCE_ACCESS_KEY'] ||78 raise(ArgumentError, "needs access key; use `ENV['SAUCE_ACCESS_KEY']`")79 SAUCE.each do |key|80 value = parse_sauce_key(key)81 caps['sauce:options'][self.class.camel_case(key)] = value unless value.nil?82 end83 caps84 end85 alias as_json capabilities86 def merge_capabilities(opts)87 opts.each do |key, value|88 raise ArgumentError, "#{key} is not a valid parameter for Options class" unless respond_to?("#{key}=")89 value = value.transform_keys(&:to_sym) if value.is_a?(Hash)90 send("#{key}=", value)91 end92 end93 def mac?94 @platform_name.include?('mac') || @platform_name.include?('OS X')95 end96 def windows?97 @platform_name.include?('Windows')98 end99 private100 def key_value(key)101 send(key)102 rescue NoMethodError103 # Ignored104 end105 def parse_w3c_key(key)106 value = send(key)107 if key == :proxy && value108 value.as_json109 elsif key == :timeouts110 if value111 SauceBindings.logger.deprecate(':timeouts',112 ':implicit_wait_timeout, :page_load_timeout or :script_timeout;',113 id: :timeouts) do114 '(ensure the values are set as seconds not milliseconds)'115 end116 value.transform_keys do |old_key|117 self.class.camel_case(old_key)118 end119 else120 manage_timeouts121 end122 else123 value124 end125 end126 def manage_timeouts127 timeouts = {}128 timeouts['implicit'] = ms_multiplier(@implicit_wait_timeout) if @implicit_wait_timeout129 timeouts['pageLoad'] = ms_multiplier(@page_load_timeout) if @page_load_timeout130 timeouts['script'] = ms_multiplier(@script_timeout) if @script_timeout131 timeouts unless timeouts.empty?132 end133 def ms_multiplier(int)134 raise(ArgumentError, 'Timeouts need to be entered as seconds not milliseconds') if int > 600135 int * 1000136 end137 def parse_sauce_key(key)138 value = key_value(key)139 case key140 when :prerun141 camelize_keys(value)142 when :custom_data143 camelize_keys(value)144 when :disable_record_video145 !send(:record_video)146 when :disable_video_upload_on_pass147 !send(:video_upload_on_pass)148 when :disable_record_screenshots149 !send(:record_screenshots)150 when :disable_record_logs151 !send(:record_logs)152 else153 value154 end155 end156 def camelize_keys(hash)157 hash&.transform_keys do |old_key|158 self.class.camel_case(old_key)159 end160 end161 def parse_selenium_options(selenium_opts)162 selenium_opts.each do |opt|163 W3C.each do |capability|164 value = option_value(opt, capability)165 next if capability == :timeouts && value&.empty?166 if capability == :browser_name167 @browser_name ||= BROWSER_NAMES[opt.class]168 validate_browser_name(value || BROWSER_NAMES[opt.class])169 elsif value170 send("#{capability}=", value)171 end172 end...

Full Screen

Full Screen

camel_case

Using AI Code Generation

copy

Full Screen

1element = driver.find_element(:name, 'q')2element = driver.find_element(:name, 'q')3element = driver.find_element(:name, 'q')4element = driver.find_element(:name, 'q')

Full Screen

Full Screen

camel_case

Using AI Code Generation

copy

Full Screen

1driver.find_element(:name, 'q').send_keys 'Selenium WebDriver'2driver.find_element(:name, 'btnG').click3driver.find_element(:name, 'q').send_keys 'Selenium WebDriver'4driver.find_element(:name, 'btnG').click5driver.find_element(:name, 'q').send_keys 'Selenium WebDriver'6driver.find_element(:name, 'btnG').click7driver.find_element(:name, 'q').send_keys 'Selenium WebDriver'8driver.find_element(:name, 'btnG').click9driver.find_element(:name, 'q').send_keys 'Selenium WebDriver'10driver.find_element(:name, 'btnG').click11driver.find_element(:name, 'q').send_keys 'Selenium WebDriver'12driver.find_element(:name, 'btnG').click13driver.find_element(:name, 'q').send_keys 'Selenium WebDriver'

Full Screen

Full Screen

camel_case

Using AI Code Generation

copy

Full Screen

1driver.find_element(:name, 'q').send_keys 'Selenium'2driver.find_element(:name, 'btnG').click3driver.find_element(:name, 'q').send_keys 'Selenium'4driver.find_element(:name, 'btnG').click5driver.find_element(:name, 'q').send_keys 'Selenium'6driver.find_element(:name, 'btnG').click7driver.find_element(:name, 'q').send_keys 'Selenium'8driver.find_element(:name, 'btnG').click9driver.find_element(:name, 'q').send_keys 'Selenium'10driver.find_element(:name, 'btnG').click

Full Screen

Full Screen

camel_case

Using AI Code Generation

copy

Full Screen

1driver.find_element(:name, 'q').send_keys "selenium webdriver"2driver.find_element(:name, 'btnK').click3driver.find_element(:name, 'q').send_keys "selenium webdriver"4driver.find_element(:name, 'btnK').click5driver.find_element(:name, 'q').send_keys "selenium webdriver"6driver.find_element(:name, 'btnK').click

Full Screen

Full Screen

camel_case

Using AI Code Generation

copy

Full Screen

1C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver/common/service.rb:113:in `initialize': No such file or directory - chromedriver (Errno::ENOENT)2/Users/username/.rvm/gems/ruby-2.2.3/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver/common/service.rb:113:in `initialize': No such file or directory - chromedriver (Errno::ENOENT)3/usr/local/lib/ruby/gems/2.2.0/gems/selenium-webdriver-2.53.4/lib/selenium/webdriver/common/service.rb:113:in `initialize': No such file or directory - chromedriver (Errno::ENOENT)

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.

Run Selenium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful