How to use prepare_capabilities_payload method of Selenium.WebDriver.Remote Package

Best Selenium code snippet using Selenium.WebDriver.Remote.prepare_capabilities_payload

bridge.rb

Source:bridge.rb Github

copy

Full Screen

...39 #40 # Creates session.41 #42 def create_session(capabilities)43 response = execute(:new_session, {}, prepare_capabilities_payload(capabilities))44 @session_id = response['sessionId']45 capabilities = response['capabilities']46 raise Error::WebDriverError, 'no sessionId in returned payload' unless @session_id47 @capabilities = Capabilities.json_create(capabilities)48 case @capabilities[:browser_name]49 when 'chrome'50 extend(WebDriver::Chrome::Features)51 when 'firefox'52 extend(WebDriver::Firefox::Features)53 when 'msedge'54 extend(WebDriver::Edge::Features)55 when 'Safari', 'Safari Technology Preview'56 extend(WebDriver::Safari::Features)57 end58 end59 #60 # Returns the current session ID.61 #62 def session_id63 @session_id || raise(Error::WebDriverError, 'no current session exists')64 end65 def browser66 @browser ||= begin67 name = @capabilities.browser_name68 name ? name.tr(' ', '_').downcase.to_sym : 'unknown'69 end70 end71 def status72 execute :status73 end74 def get(url)75 execute :get, {}, {url: url}76 end77 #78 # timeouts79 #80 def timeouts81 execute :get_timeouts, {}82 end83 def timeouts=(timeouts)84 execute :set_timeout, {}, timeouts85 end86 #87 # alerts88 #89 def accept_alert90 execute :accept_alert91 end92 def dismiss_alert93 execute :dismiss_alert94 end95 def alert=(keys)96 execute :send_alert_text, {}, {value: keys.split(//), text: keys}97 end98 def alert_text99 execute :get_alert_text100 end101 #102 # navigation103 #104 def go_back105 execute :back106 end107 def go_forward108 execute :forward109 end110 def url111 execute :get_current_url112 end113 def title114 execute :get_title115 end116 def page_source117 execute_script('var source = document.documentElement.outerHTML;' \118 'if (!source) { source = new XMLSerializer().serializeToString(document); }' \119 'return source;')120 end121 #122 # Create a new top-level browsing context123 # https://w3c.github.io/webdriver/#new-window124 # @param type [String] Supports two values: 'tab' and 'window'.125 # Use 'tab' if you'd like the new window to share an OS-level window126 # with the current browsing context.127 # Use 'window' otherwise128 # @return [Hash] Containing 'handle' with the value of the window handle129 # and 'type' with the value of the created window type130 #131 def new_window(type)132 execute :new_window, {}, {type: type}133 end134 def switch_to_window(name)135 execute :switch_to_window, {}, {handle: name}136 end137 def switch_to_frame(id)138 id = find_element_by('id', id) if id.is_a? String139 execute :switch_to_frame, {}, {id: id}140 end141 def switch_to_parent_frame142 execute :switch_to_parent_frame143 end144 def switch_to_default_content145 switch_to_frame nil146 end147 QUIT_ERRORS = [IOError].freeze148 def quit149 execute :delete_session150 http.close151 rescue *QUIT_ERRORS152 end153 def close154 execute :close_window155 end156 def refresh157 execute :refresh158 end159 #160 # window handling161 #162 def window_handles163 execute :get_window_handles164 end165 def window_handle166 execute :get_window_handle167 end168 def resize_window(width, height, handle = :current)169 raise Error::WebDriverError, 'Switch to desired window before changing its size' unless handle == :current170 set_window_rect(width: width, height: height)171 end172 def window_size(handle = :current)173 unless handle == :current174 raise Error::UnsupportedOperationError,175 'Switch to desired window before getting its size'176 end177 data = execute :get_window_rect178 Dimension.new data['width'], data['height']179 end180 def minimize_window181 execute :minimize_window182 end183 def maximize_window(handle = :current)184 unless handle == :current185 raise Error::UnsupportedOperationError,186 'Switch to desired window before changing its size'187 end188 execute :maximize_window189 end190 def full_screen_window191 execute :fullscreen_window192 end193 def reposition_window(x, y)194 set_window_rect(x: x, y: y)195 end196 def window_position197 data = execute :get_window_rect198 Point.new data['x'], data['y']199 end200 def set_window_rect(x: nil, y: nil, width: nil, height: nil)201 params = {x: x, y: y, width: width, height: height}202 params.update(params) { |_k, v| Integer(v) unless v.nil? }203 execute :set_window_rect, {}, params204 end205 def window_rect206 data = execute :get_window_rect207 Rectangle.new data['x'], data['y'], data['width'], data['height']208 end209 def screenshot210 execute :take_screenshot211 end212 def element_screenshot(element)213 execute :take_element_screenshot, id: element214 end215 #216 # HTML 5217 #218 def local_storage_item(key, value = nil)219 if value220 execute_script("localStorage.setItem('#{key}', '#{value}')")221 else222 execute_script("return localStorage.getItem('#{key}')")223 end224 end225 def remove_local_storage_item(key)226 execute_script("localStorage.removeItem('#{key}')")227 end228 def local_storage_keys229 execute_script('return Object.keys(localStorage)')230 end231 def clear_local_storage232 execute_script('localStorage.clear()')233 end234 def local_storage_size235 execute_script('return localStorage.length')236 end237 def session_storage_item(key, value = nil)238 if value239 execute_script("sessionStorage.setItem('#{key}', '#{value}')")240 else241 execute_script("return sessionStorage.getItem('#{key}')")242 end243 end244 def remove_session_storage_item(key)245 execute_script("sessionStorage.removeItem('#{key}')")246 end247 def session_storage_keys248 execute_script('return Object.keys(sessionStorage)')249 end250 def clear_session_storage251 execute_script('sessionStorage.clear()')252 end253 def session_storage_size254 execute_script('return sessionStorage.length')255 end256 #257 # javascript execution258 #259 def execute_script(script, *args)260 result = execute :execute_script, {}, {script: script, args: args}261 unwrap_script_result result262 end263 def execute_async_script(script, *args)264 result = execute :execute_async_script, {}, {script: script, args: args}265 unwrap_script_result result266 end267 #268 # cookies269 #270 def manage271 @manage ||= WebDriver::Manager.new(self)272 end273 def add_cookie(cookie)274 execute :add_cookie, {}, {cookie: cookie}275 end276 def delete_cookie(name)277 execute :delete_cookie, name: name278 end279 def cookie(name)280 execute :get_cookie, name: name281 end282 def cookies283 execute :get_all_cookies284 end285 def delete_all_cookies286 execute :delete_all_cookies287 end288 #289 # actions290 #291 def action(async = false)292 ActionBuilder.new self,293 Interactions.pointer(:mouse, name: 'mouse'),294 Interactions.key('keyboard'),295 async296 end297 alias_method :actions, :action298 def mouse299 raise Error::UnsupportedOperationError, '#mouse is no longer supported, use #action instead'300 end301 def keyboard302 raise Error::UnsupportedOperationError, '#keyboard is no longer supported, use #action instead'303 end304 def send_actions(data)305 execute :actions, {}, {actions: data}306 end307 def release_actions308 execute :release_actions309 end310 def print_page(options = {})311 execute :print_page, {}, {options: options}312 end313 def click_element(element)314 execute :element_click, id: element315 end316 def send_keys_to_element(element, keys)317 # TODO: rework file detectors before Selenium 4.0318 if @file_detector319 local_files = keys.first&.split("\n")&.map { |key| @file_detector.call(Array(key)) }&.compact320 if local_files.any?321 keys = local_files.map { |local_file| upload(local_file) }322 keys = Array(keys.join("\n"))323 end324 end325 # Keep .split(//) for backward compatibility for now326 text = keys.join('')327 execute :element_send_keys, {id: element}, {value: text.split(//), text: text}328 end329 def upload(local_file)330 unless File.file?(local_file)331 WebDriver.logger.debug("File detector only works with files. #{local_file.inspect} isn`t a file!")332 raise Error::WebDriverError, "You are trying to work with something that isn't a file."333 end334 execute :upload_file, {}, {file: Zipper.zip_file(local_file)}335 end336 def clear_element(element)337 execute :element_clear, id: element338 end339 def submit_element(element)340 form = find_element_by('xpath', "./ancestor-or-self::form", [:element, element])341 execute_script("var e = arguments[0].ownerDocument.createEvent('Event');" \342 "e.initEvent('submit', true, true);" \343 'if (arguments[0].dispatchEvent(e)) { arguments[0].submit() }', form.as_json)344 end345 #346 # element properties347 #348 def element_tag_name(element)349 execute :get_element_tag_name, id: element350 end351 def element_attribute(element, name)352 WebDriver.logger.info "Using script for :getAttribute of #{name}"353 execute_atom :getAttribute, element, name354 end355 def element_dom_attribute(element, name)356 execute :get_element_attribute, id: element, name: name357 end358 def element_property(element, name)359 execute :get_element_property, id: element, name: name360 end361 def element_aria_role(element)362 execute :get_element_aria_role, id: element363 end364 def element_aria_label(element)365 execute :get_element_aria_label, id: element366 end367 def element_value(element)368 element_property element, 'value'369 end370 def element_text(element)371 execute :get_element_text, id: element372 end373 def element_location(element)374 data = execute :get_element_rect, id: element375 Point.new data['x'], data['y']376 end377 def element_rect(element)378 data = execute :get_element_rect, id: element379 Rectangle.new data['x'], data['y'], data['width'], data['height']380 end381 def element_location_once_scrolled_into_view(element)382 send_keys_to_element(element, [''])383 element_location(element)384 end385 def element_size(element)386 data = execute :get_element_rect, id: element387 Dimension.new data['width'], data['height']388 end389 def element_enabled?(element)390 execute :is_element_enabled, id: element391 end392 def element_selected?(element)393 execute :is_element_selected, id: element394 end395 def element_displayed?(element)396 WebDriver.logger.info 'Using script for :isDisplayed'397 execute_atom :isDisplayed, element398 end399 def element_value_of_css_property(element, prop)400 execute :get_element_css_value, id: element, property_name: prop401 end402 #403 # finding elements404 #405 def active_element406 Element.new self, element_id_from(execute(:get_active_element))407 end408 alias_method :switch_to_active_element, :active_element409 def find_element_by(how, what, parent_ref = [])410 how, what = convert_locator(how, what)411 return execute_atom(:findElements, Support::RelativeLocator.new(what).as_json).first if how == 'relative'412 parent_type, parent_id = parent_ref413 id = case parent_type414 when :element415 execute :find_child_element, {id: parent_id}, {using: how, value: what.to_s}416 when :shadow_root417 execute :find_shadow_child_element, {id: parent_id}, {using: how, value: what.to_s}418 else419 execute :find_element, {}, {using: how, value: what.to_s}420 end421 Element.new self, element_id_from(id)422 end423 def find_elements_by(how, what, parent_ref = [])424 how, what = convert_locator(how, what)425 return execute_atom :findElements, Support::RelativeLocator.new(what).as_json if how == 'relative'426 parent_type, parent_id = parent_ref427 ids = case parent_type428 when :element429 execute :find_child_elements, {id: parent_id}, {using: how, value: what.to_s}430 when :shadow_root431 execute :find_shadow_child_elements, {id: parent_id}, {using: how, value: what.to_s}432 else433 execute :find_elements, {}, {using: how, value: what.to_s}434 end435 ids.map { |id| Element.new self, element_id_from(id) }436 end437 def shadow_root(element)438 id = execute :get_element_shadow_root, id: element439 ShadowRoot.new self, shadow_root_id_from(id)440 end441 private442 #443 # executes a command on the remote server.444 #445 # @return [WebDriver::Remote::Response]446 #447 def execute(command, opts = {}, command_hash = nil)448 verb, path = commands(command) || raise(ArgumentError, "unknown command: #{command.inspect}")449 path = path.dup450 path[':session_id'] = session_id if path.include?(':session_id')451 begin452 opts.each { |key, value| path[key.inspect] = escaper.escape(value.to_s) }453 rescue IndexError454 raise ArgumentError, "#{opts.inspect} invalid for #{command.inspect}"455 end456 WebDriver.logger.info("-> #{verb.to_s.upcase} #{path}")457 http.call(verb, path, command_hash)['value']458 end459 def escaper460 @escaper ||= defined?(URI::Parser) ? URI::DEFAULT_PARSER : URI461 end462 def commands(command)463 COMMANDS[command]464 end465 def unwrap_script_result(arg)466 case arg467 when Array468 arg.map { |e| unwrap_script_result(e) }469 when Hash470 element_id = element_id_from(arg)471 return Element.new(self, element_id) if element_id472 shadow_root_id = shadow_root_id_from(arg)473 return ShadowRoot.new self, shadow_root_id if shadow_root_id474 arg.each { |k, v| arg[k] = unwrap_script_result(v) }475 else476 arg477 end478 end479 def element_id_from(id)480 id['ELEMENT'] || id[Element::ELEMENT_KEY]481 end482 def shadow_root_id_from(id)483 id[ShadowRoot::ROOT_KEY]484 end485 def prepare_capabilities_payload(capabilities)486 capabilities = {alwaysMatch: capabilities} if !capabilities['alwaysMatch'] && !capabilities['firstMatch']487 {capabilities: capabilities}488 end489 def convert_locator(how, what)490 how = SearchContext::FINDERS[how.to_sym] || how491 case how492 when 'class name'493 how = 'css selector'494 what = ".#{escape_css(what.to_s)}"495 when 'id'496 how = 'css selector'497 what = "##{escape_css(what.to_s)}"498 when 'name'499 how = 'css selector'...

Full Screen

Full Screen

prepare_capabilities_payload

Using AI Code Generation

copy

Full Screen

1def prepare_capabilities_payload(capabilities)2 if capabilities.is_a?(Hash)3 capabilities = Selenium::WebDriver::Remote::Capabilities.new(capabilities)4capabilities = prepare_capabilities_payload(5 :prerun => {6 },7 :customData => {8 },9 :tunnelOptions => {10 :dns => {

Full Screen

Full Screen

prepare_capabilities_payload

Using AI Code Generation

copy

Full Screen

1remote.prepare_capabilities_payload(capabilities)2puts driver.send(:bridge).send(:http).send(:prepare_capabilities_payload, driver.capabilities)3{"desiredCapabilities"=>{"browserName"=>"firefox", "version"=>"", "platform"=>"ANY", "javascriptEnabled"=>true, "takesScreenshot"=>true, "handlesAlerts"=>true, "databaseEnabled"=>false, "locationContextEnabled"=>false, "applicationCacheEnabled"=>false, "browserConnectionEnabled"=>false, "cssSelectorsEnabled"=>true, "webStorageEnabled"=>false, "rotatable"=>false, "acceptSslCerts"=>false, "nativeEvents"=>true, "proxy"=>{"proxyType"=>"direct"}}, "requiredCapabilities"=>{}, "capabilities"=>{"desiredCapabilities"=>{"browserName"=>"firefox", "version"=>"", "platform"=>"ANY", "javascriptEnabled"=>true, "takesScreenshot"=>true, "handlesAlerts"=>true, "databaseEnabled"=>false, "locationContextEnabled"=>false, "applicationCacheEnabled"=>false, "browserConnectionEnabled"=>false, "cssSelectorsEnabled"=>true, "webStorageEnabled"=>false, "rotatable"=>false, "acceptSslCerts"=>false, "nativeEvents"=>true, "proxy"=>{"proxyType"=>"direct"}}, "requiredCapabilities"=>{}, "alwaysMatch"=>{"browserName"=>"firefox", "browserVersion"=>"", "platformName"=>"ANY", "acceptInsecureCerts"=>

Full Screen

Full Screen

prepare_capabilities_payload

Using AI Code Generation

copy

Full Screen

1payload = {2 "desiredCapabilities" => {3 }4}5capabilities.send(:prepare_capabilities_payload, payload)

Full Screen

Full Screen

prepare_capabilities_payload

Using AI Code Generation

copy

Full Screen

1payload = driver.prepare_capabilities_payload(capabilities)2Selenium::WebDriver::Remote.prepare_capabilities_payload(capabilities)3payload = driver.prepare_capabilities_payload(capabilities)

Full Screen

Full Screen

prepare_capabilities_payload

Using AI Code Generation

copy

Full Screen

1payload = Selenium::WebDriver::Remote::Capabilities.prepare_capabilities_payload(caps)2payload = Selenium::WebDriver::Remote::Capabilities.prepare_capabilities_payload(caps)3payload = Selenium::WebDriver::Remote::Capabilities.prepare_capabilities_payload(caps)

Full Screen

Full Screen

prepare_capabilities_payload

Using AI Code Generation

copy

Full Screen

1 {2 }3caps = Selenium::WebDriver::Remote::Capabilities.json_create(payload)

Full Screen

Full Screen

prepare_capabilities_payload

Using AI Code Generation

copy

Full Screen

1payload = Selenium::WebDriver::Remote::Capabilities.prepare_capabilities_payload(caps)2payload = Selenium::WebDriver::Remote::Capabilities.prepare_capabilities_payload(caps)3payload = Selenium::WebDriver::Remote::Capabilities.prepare_capabilities_payload(caps)

Full Screen

Full Screen

prepare_capabilities_payload

Using AI Code Generation

copy

Full Screen

1 {2 }3caps = Selenium::WebDriver::Remote::Capabilities.json_create(payload)

Full Screen

Full Screen

prepare_capabilities_payload

Using AI Code Generation

copy

Full Screen

1payload = {2 "desiredCapabilities" => {3 }4}5capabilities.send(:prepare_capabilities_payload, payload)

Full Screen

Full Screen

prepare_capabilities_payload

Using AI Code Generation

copy

Full Screen

1 {2 }3caps = Selenium::WebDriver::Remote::Capabilities.json_create(payload)

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