Class: Appium::Core::Base::Bridge
- Inherits:
-
Selenium::WebDriver::Remote::Bridge
- Object
- Selenium::WebDriver::Remote::Bridge
- Appium::Core::Base::Bridge
- Includes:
- Device::AppManagement, Device::AppState, Device::Context, Device::Device, Device::DeviceLock, Device::ExecuteDriver, Device::FileManagement, Device::ImageComparison, Device::ImeActions, Device::KeyEvent, Device::Keyboard, Device::Orientation, Device::ScreenRecord::Command, Device::Setting, Device::AppManagement, Device::AppState, Device::Context, Device::Device, Device::DeviceLock, Device::ExecuteDriver, Device::FileManagement, Device::ImageComparison, Device::ImeActions, Device::KeyEvent, Device::Keyboard, Device::Orientation, Device::ScreenRecord::Command, Device::Setting, _Bridge
- Defined in:
- lib/appium_lib_core/common/base/bridge.rb,
sig/lib/appium_lib_core/common/base/bridge.rbs
Overview
LocatorConverter
Direct Known Subclasses
Constant Summary collapse
- APPIUM_PREFIX =
Prefix for extra capability defined by W3C
'appium:'- APPIUM_NATIVE_BROWSER_NAME =
No 'browserName' means the session is native appium connection
'appium'
Constants included from Device::ImageComparison
Device::ImageComparison::GET_SIMILARITY, Device::ImageComparison::MATCH_FEATURES, Device::ImageComparison::MATCH_TEMPLATE, Device::ImageComparison::MODE
Constants included from Device::AppState
Constants inherited from Selenium::WebDriver::Remote::Bridge
Selenium::WebDriver::Remote::Bridge::COMMANDS, Selenium::WebDriver::Remote::Bridge::ESCAPE_CSS_REGEXP, Selenium::WebDriver::Remote::Bridge::PORT, Selenium::WebDriver::Remote::Bridge::QUIT_ERRORS, Selenium::WebDriver::Remote::Bridge::UNICODE_CODE_POINT
Constants included from Selenium::WebDriver::Chrome::Features
Selenium::WebDriver::Chrome::Features::CHROME_COMMANDS, Selenium::WebDriver::Chrome::Features::COMMANDS
Constants included from Selenium::WebDriver::Chromium::Features
Selenium::WebDriver::Chromium::Features::CHROMIUM_COMMANDS
Constants included from Selenium::WebDriver::Firefox::Features
Selenium::WebDriver::Firefox::Features::COMMANDS, Selenium::WebDriver::Firefox::Features::FIREFOX_COMMANDS
Constants included from Selenium::WebDriver::Edge::Features
Selenium::WebDriver::Edge::Features::COMMANDS, Selenium::WebDriver::Edge::Features::EDGE_COMMANDS
Constants included from Selenium::WebDriver::Safari::Features
Selenium::WebDriver::Safari::Features::COMMANDS, Selenium::WebDriver::Safari::Features::SAFARI_COMMANDS
Instance Attribute Summary
Attributes inherited from Selenium::WebDriver::Remote::Bridge
#capabilities, #file_detector, #http
Instance Method Summary collapse
-
#action(_deprecated_async = nil, async: false, devices: nil) ⇒ Object
Perform 'touch' actions for W3C module.
-
#add_appium_prefix(capabilities) ⇒ ::Appium::Core::Base::Capabilities
Append
appium:prefix for Appium following W3C spec https://www.w3.org/TR/webdriver/#dfn-validate-capabilities. -
#attach_to(session_id, platform_name, automation_name) ⇒ ::Appium::Core::Base::Capabilities
Appium only.
-
#available_log_types ⇒ Object
logs.
- #browser ⇒ Object
- #camel_case(str_or_sym) ⇒ Object
-
#command_list ⇒ Hash[Symbol, Array[Symbol | String]]
Override Selenium's command_list to use Appium's command definitions.
-
#commands(command) ⇒ Object
Override Selenium's commands to resolve extra_commands from this subclass.
-
#convert_to_element(id) ⇒ ::Appium::Core::Element
For Appium.
-
#create_session(capabilities) ⇒ ::Appium::Core::Base::Capabilities
Override Creates session handling.
-
#element_attribute(element, name) ⇒ Object
For Appium override.
-
#element_displayed?(element) ⇒ Object
For Appium override.
- #element_screenshot(element_id) ⇒ Object
- #extension_prefix?(capability_name) ⇒ Boolean
-
#get_timeouts ⇒ Object
Port from MJSONWP.
-
#initialize(url:, http_client: nil) ⇒ Bridge
constructor
Selenium 4.46 moved server URL configuration from Bridge to the HTTP client.
- #json_create(value) ⇒ Object
-
#location ⇒ Object
For Appium No implementation for W3C webdriver module called in 'extend DriverExtensions::HasLocation'.
-
#log(type) ⇒ Object
For Appium No implementation for W3C webdriver module.
-
#log_event(vendor, event) ⇒ Object
For Appium.
-
#log_events(type = nil) ⇒ Object
For Appium.
-
#network_connection ⇒ Object
For Appium override called in 'extend DriverExtensions::HasNetworkConnection'.
-
#network_connection= ⇒ Object
For Appium override called in 'extend DriverExtensions::HasNetworkConnection'.
- #selenium_bridge_accepts_url? ⇒ Boolean
-
#send_command(command_params) ⇒ Object
for selenium-webdriver compatibility in chrome browser session.
-
#set_location(lat, lon, alt = 0.0, speed: nil, satellites: nil) ⇒ Object
For Appium No implementation for W3C webdriver module.
- #status ⇒ Object
- #viewport_screenshot ⇒ Object
Methods included from _Bridge
#bridge, #execute, #execute_async_script, #execute_script
Methods included from Device::DeviceLock
#device_locked?, #lock, #unlock
Methods included from Device::Keyboard
#hide_keyboard, #is_keyboard_shown
Methods included from Device::ImeActions
#ime_activate, #ime_activated, #ime_active_engine, #ime_available_engines, #ime_deactivate
Methods included from Device::Setting
#execute, #get_settings, #update_settings
Methods included from Device::Context
#available_contexts, #current_context, #execute, #set_context, #within_context
Methods included from Device::FileManagement
#execute, #pull_file, #pull_folder, #push_file
Methods included from Device::KeyEvent
#keyevent, #long_press_keycode, #press_keycode
Methods included from Device::ImageComparison
#compare_images, #execute, #find_image_occurrence, #get_images_similarity, #match_images_features
Methods included from Device::AppManagement
#activate_app, #app_installed?, #app_strings, #background_app, #install_app, #options?, #remove_app, #terminate_app
Methods included from Device::AppState
Methods included from Device::ScreenRecord::Command
#stop_and_save_recording_screen, #stop_recording_screen
Methods included from Device::Device
Methods included from Device::ExecuteDriver
Methods included from Device::Orientation
#execute, #screen_orientation, #screen_orientation=
Methods inherited from Selenium::WebDriver::Remote::Bridge
#accept_alert, #active_element, add_command, #add_cookie, #add_credential, #add_virtual_authenticator, #alert=, #alert_text, #cancel_fedcm_dialog, #clear_element, #clear_local_storage, #clear_session_storage, #click_element, #click_fedcm_dialog_button, #close, #convert_locator, #cookie, #cookies, #credentials, #delete_all_cookies, #delete_cookie, #dismiss_alert, #element_aria_label, #element_aria_role, #element_dom_attribute, #element_enabled?, #element_id_from, #element_location, #element_location_once_scrolled_into_view, #element_property, #element_rect, #element_selected?, #element_size, #element_tag_name, #element_text, #element_value, #element_value_of_css_property, #escape_css, #escaper, #execute, #execute_async_script, #execute_script, extra_commands, #fedcm_account_list, #fedcm_delay, #fedcm_dialog_type, #fedcm_subtitle, #fedcm_title, #find_element_by, #find_elements_by, #full_screen_window, #get, #go_back, #go_forward, #local_storage_item, #local_storage_keys, #local_storage_size, #manage, #maximize_window, #minimize_window, #new_window, #page_source, #prepare_capabilities_payload, #print_page, #quit, #refresh, #release_actions, #remove_all_credentials, #remove_credential, #remove_local_storage_item, #remove_session_storage_item, #remove_virtual_authenticator, #reposition_window, #reset_fedcm_cooldown, #resize_window, #screenshot, #select_fedcm_account, #send_actions, #send_keys_to_element, #session_id, #session_storage_item, #session_storage_keys, #session_storage_size, #set_window_rect, #shadow_root, #shadow_root_id_from, #submit_element, #switch_to_default_content, #switch_to_frame, #switch_to_parent_frame, #switch_to_window, #timeouts, #timeouts=, #title, #unwrap_script_result, #upload, #url, #user_verified, #window_handle, #window_handles, #window_position, #window_rect, #window_size
Methods included from Selenium::WebDriver::Chromium::Features
#cast_issue_message, #cast_sink_to_use=, #cast_sinks, #delete_network_conditions, #launch_app, #network_conditions, #network_conditions=, #set_permission, #start_cast_desktop_mirroring, #start_cast_tab_mirroring, #stop_casting
Methods included from Selenium::WebDriver::Firefox::Features
#context, #context=, #full_screenshot, #install_addon, #uninstall_addon
Methods included from Selenium::WebDriver::Safari::Features
#attach_debugger, #permissions, #permissions=
Methods included from _Features
Methods included from Selenium::WebDriver::Atoms
#atom_script, #execute_atom, #read_atom
Constructor Details
#initialize(url:, http_client: nil) ⇒ Bridge
Selenium 4.46 moved server URL configuration from Bridge to the HTTP client.
51 52 53 54 55 56 57 58 59 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 51 def initialize(url:, http_client: nil) if selenium_bridge_accepts_url? super else http_client ||= ::Selenium::WebDriver::Remote::Http::Default.new http_client.server_url = url super(http_client: http_client) end end |
Instance Method Details
#action(_deprecated_async = nil, async: false, devices: nil) ⇒ Object
Perform 'touch' actions for W3C module.
Generate touch pointer action here and users can use this via driver.action
- https://www.selenium.dev/documentation/webdriver/actions_api/
- https://www.selenium.dev/selenium/docs/api/rb/Selenium/WebDriver/ActionBuilder.html
- https://www.selenium.dev/selenium/docs/api/rb/Selenium/WebDriver/PointerActions.html
- https://www.selenium.dev/selenium/docs/api/rb/Selenium/WebDriver/KeyActions.html
The pointer type is 'touch' by default in the Appium Ruby client.
207 208 209 210 211 212 213 214 215 216 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 207 def action(_deprecated_async = nil, async: false, devices: nil) # steep:ignore:start ::Selenium::WebDriver::ActionBuilder.new( self, devices: devices || [::Selenium::WebDriver::Interactions.pointer(:touch, name: 'touch')], async: async, duration: 50 # milliseconds ) # steep:ignore:end end |
#add_appium_prefix(capabilities) ⇒ ::Appium::Core::Base::Capabilities
Append appium: prefix for Appium following W3C spec
https://www.w3.org/TR/webdriver/#dfn-validate-capabilities
134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 134 def add_appium_prefix(capabilities) w3c_capabilities = ::Appium::Core::Base::Capabilities.new capabilities = capabilities.send(:capabilities) unless capabilities.is_a?(Hash) capabilities.each do |name, value| capability_name = name.to_s w3c_name = extension_prefix?(capability_name) ? name : "#{APPIUM_PREFIX}#{capability_name}" w3c_capabilities[w3c_name] = value end w3c_capabilities end |
#attach_to(session_id, platform_name, automation_name) ⇒ ::Appium::Core::Base::Capabilities
Appium only. Attach to an existing session.
85 86 87 88 89 90 91 92 93 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 85 def attach_to(session_id, platform_name, automation_name) @session_id = session_id # generate a dummy capabilities instance which only has the given platformName and automationName @capabilities = ::Appium::Core::Base::Capabilities.new( 'platformName' => platform_name, 'automationName' => automation_name ) end |
#available_log_types ⇒ Object
logs
For Appium No implementation for W3C webdriver module
273 274 275 276 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 273 def available_log_types types = execute :get_available_log_types Array(types).map(&:to_sym) # steep:ignore end |
#browser ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 61 def browser @browser ||= begin name = @capabilities&.browser_name name ? name.tr(' ', '_').downcase.to_sym : 'unknown' rescue KeyError APPIUM_NATIVE_BROWSER_NAME end end |
#camel_case(str_or_sym) ⇒ Object
157 158 159 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 157 def camel_case(str_or_sym) str_or_sym.to_s.gsub(/_([a-z])/) { Regexp.last_match(1)&.upcase } end |
#command_list ⇒ Hash[Symbol, Array[Symbol | String]]
Override Selenium's command_list to use Appium's command definitions
179 180 181 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 179 def command_list ::Appium::Core::Commands::COMMANDS end |
#commands(command) ⇒ Object
Override Selenium's commands to resolve extra_commands from this subclass
185 186 187 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 185 def commands(command) command_list[command] || self.class.extra_commands&.[](command) end |
#convert_to_element(id) ⇒ ::Appium::Core::Element
For Appium
247 248 249 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 247 def convert_to_element(id) ::Appium::Core::Element.new self, element_id_from(id) end |
#create_session(capabilities) ⇒ ::Appium::Core::Base::Capabilities
Override Creates session handling.
119 120 121 122 123 124 125 126 127 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 119 def create_session(capabilities) always_match = add_appium_prefix(capabilities) response = execute(:new_session, {}, { capabilities: { alwaysMatch: always_match, firstMatch: [{}] } }) # steep:ignore @session_id = response['sessionId'] raise ::Selenium::WebDriver::Error::WebDriverError, 'no sessionId in returned payload' unless @session_id @capabilities = json_create(response['capabilities']) end |
#element_attribute(element, name) ⇒ Object
For Appium override
234 235 236 237 238 239 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 234 def element_attribute(element, name) # For W3C in Selenium Client # execute_atom :getAttribute, element, name. # 'dom_attribute' in the WebDriver Selenium. execute :get_element_attribute, id: element.id, name: name end |
#element_displayed?(element) ⇒ Object
For Appium override
225 226 227 228 229 230 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 225 def element_displayed?(element) # For W3C # https://github.com/SeleniumHQ/selenium/commit/b618499adcc3a9f667590652c5757c0caa703289 # execute_atom :isDisplayed, element execute :is_element_displayed, id: element.id end |
#element_screenshot(element_id) ⇒ Object
309 310 311 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 309 def element_screenshot(element_id) execute :take_element_screenshot, id: element_id end |
#extension_prefix?(capability_name) ⇒ Boolean
161 162 163 164 165 166 167 168 169 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 161 def extension_prefix?(capability_name) snake_cased_capability_names = ::Appium::Core::Base::Capabilities::KNOWN.map(&:to_s) camel_cased_capability_names = snake_cased_capability_names.map { |v| camel_case(v) } # Check 'EXTENSION_CAPABILITY_PATTERN' snake_cased_capability_names.include?(capability_name) || camel_cased_capability_names.include?(capability_name) || capability_name.match(':') end |
#get_timeouts ⇒ Object
Port from MJSONWP
219 220 221 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 219 def get_timeouts execute :get_timeouts end |
#json_create(value) ⇒ Object
171 172 173 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 171 def json_create(value) ::Appium::Core::Base::Capabilities.json_create(value) end |
#location ⇒ Object
For Appium No implementation for W3C webdriver module called in 'extend DriverExtensions::HasLocation'
254 255 256 257 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 254 def location obj = execute(:get_location) || {} ::Appium::Location.new obj['latitude'], obj['longitude'], obj['altitude'] end |
#log(type) ⇒ Object
For Appium No implementation for W3C webdriver module
280 281 282 283 284 285 286 287 288 289 290 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 280 def log(type) data = execute :get_log, {}, { type: type.to_s } Array(data).map do |l| # steep:ignore:start ::Selenium::WebDriver::LogEntry.new l.fetch('level', 'UNKNOWN'), l.fetch('timestamp'), l.fetch('message') # steep:ignore:end rescue KeyError next end end |
#log_event(vendor, event) ⇒ Object
For Appium
293 294 295 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 293 def log_event(vendor, event) execute :post_log_event, {}, { vendor: vendor, event: event } end |
#log_events(type = nil) ⇒ Object
For Appium
298 299 300 301 302 303 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 298 def log_events(type = nil) args = {} # steep:ignore args['type'] = type unless type.nil? execute :get_log_events, {}, args end |
#network_connection ⇒ Object
For Appium override called in 'extend DriverExtensions::HasNetworkConnection'
164 |
# File 'sig/lib/appium_lib_core/common/base/bridge.rbs', line 164
def network_connection: () -> untyped
|
#network_connection= ⇒ Object
For Appium override called in 'extend DriverExtensions::HasNetworkConnection'
169 |
# File 'sig/lib/appium_lib_core/common/base/bridge.rbs', line 169
def network_connection=: (untyped type) -> untyped
|
#selenium_bridge_accepts_url? ⇒ Boolean
151 152 153 154 155 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 151 def selenium_bridge_accepts_url? ::Selenium::WebDriver::Remote::Bridge.instance_method(:initialize).parameters.any? do |_, name| name == :url end end |
#send_command(command_params) ⇒ Object
for selenium-webdriver compatibility in chrome browser session. This may be needed in selenium-webdriver 4.8 or over? (around the version) when a session starts browserName: 'chrome' for bridge. This method is not only for Android, but also chrome desktop browser as well. So this bridge itself does not restrict the target module.
318 319 320 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 318 def send_command(command_params) execute :chrome_send_command, {}, command_params end |
#set_location(lat, lon, alt = 0.0, speed: nil, satellites: nil) ⇒ Object
For Appium No implementation for W3C webdriver module
261 262 263 264 265 266 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 261 def set_location(lat, lon, alt = 0.0, speed: nil, satellites: nil) loc = { latitude: lat, longitude: lon, altitude: alt } loc[:speed] = speed unless speed.nil? loc[:satellites] = satellites unless satellites.nil? execute :set_location, {}, { location: loc } end |
#status ⇒ Object
189 190 191 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 189 def status execute :status end |
#viewport_screenshot ⇒ Object
305 306 307 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 305 def execute_script('mobile: viewportScreenshot') end |