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
- Defined in:
- lib/appium_lib_core/common/base/bridge.rb
Overview
LocatorConverter
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'
Instance Attribute Summary collapse
-
#available_commands ⇒ Object
readonly
Returns the value of attribute available_commands.
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 www.w3.org/TR/webdriver/#dfn-validate-capabilities. -
#add_command(method:, url:, name:, &block) ⇒ Object
def add_command(method:, url:, name:, &block) Bridge.add_command name, method, url, &block end.
-
#attach_to(session_id, platform_name, automation_name) ⇒ ::Appium::Core::Base::Capabilities
Appium only.
-
#available_log_types ⇒ Object
logs.
- #browser ⇒ Object
- #commands(command) ⇒ Object
-
#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) ⇒ Boolean
For Appium override.
- #element_screenshot(element_id) ⇒ Object
-
#get_timeouts ⇒ Object
Port from MJSONWP.
-
#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=(type) ⇒ Object
For Appium override called in ‘extend DriverExtensions::HasNetworkConnection’.
-
#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
Instance Attribute Details
#available_commands ⇒ Object (readonly)
Returns the value of attribute available_commands.
48 49 50 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 48 def available_commands @available_commands 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
-
www.selenium.dev/selenium/docs/api/rb/Selenium/WebDriver/ActionBuilder.html
-
www.selenium.dev/selenium/docs/api/rb/Selenium/WebDriver/PointerActions.html
-
www.selenium.dev/selenium/docs/api/rb/Selenium/WebDriver/KeyActions.html
The pointer type is ‘touch’ by default in the Appium Ruby client.
206 207 208 209 210 211 212 213 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 206 def action(_deprecated_async = nil, async: false, devices: nil) ::Selenium::WebDriver::ActionBuilder.new( self, devices: devices || [::Selenium::WebDriver::Interactions.pointer(:touch, name: 'touch')], async: async, duration: 50 # milliseconds ) end |
#add_appium_prefix(capabilities) ⇒ ::Appium::Core::Base::Capabilities
Append appium:
prefix for Appium following W3C spec www.w3.org/TR/webdriver/#dfn-validate-capabilities
126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 126 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 |
#add_command(method:, url:, name:, &block) ⇒ Object
176 177 178 179 180 181 182 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 176 def add_command(method:, url:, name:, &block) ::Appium::Logger.info "Overriding the method '#{name}' for '#{url}'" if @available_commands.key? name @available_commands[name] = [method, url] ::Appium::Core::Device.add_endpoint_method name, &block end |
#attach_to(session_id, platform_name, automation_name) ⇒ ::Appium::Core::Base::Capabilities
Appium only. Attach to an existing session.
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 74 def attach_to(session_id, platform_name, automation_name) @available_commands = ::Appium::Core::Commands::COMMANDS.dup @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
284 285 286 287 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 284 def available_log_types types = execute :get_available_log_types Array(types).map(&:to_sym) end |
#browser ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 50 def browser @browser ||= begin name = @capabilities&.browser_name name ? name.tr(' ', '_').downcase.to_sym : 'unknown' rescue KeyError APPIUM_NATIVE_BROWSER_NAME end end |
#commands(command) ⇒ Object
184 185 186 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 184 def commands(command) @available_commands[command] || Bridge.extra_commands[command] end |
#convert_to_element(id) ⇒ ::Appium::Core::Element
For Appium
244 245 246 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 244 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.
109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 109 def create_session(capabilities) @available_commands = ::Appium::Core::Commands::COMMANDS.dup always_match = add_appium_prefix(capabilities) response = execute(:new_session, {}, { capabilities: { alwaysMatch: always_match, firstMatch: [{}] } }) @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
231 232 233 234 235 236 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 231 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) ⇒ Boolean
For Appium override
222 223 224 225 226 227 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 222 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
318 319 320 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 318 def element_screenshot(element_id) execute :take_element_screenshot, id: element_id end |
#get_timeouts ⇒ Object
Port from MJSONWP
216 217 218 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 216 def get_timeouts execute :get_timeouts end |
#location ⇒ Object
For Appium No implementation for W3C webdriver module called in ‘extend DriverExtensions::HasLocation’
265 266 267 268 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 265 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
291 292 293 294 295 296 297 298 299 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 291 def log(type) data = execute :get_log, {}, { type: type.to_s } Array(data).map do |l| ::Selenium::WebDriver::LogEntry.new l.fetch('level', 'UNKNOWN'), l.fetch('timestamp'), l.fetch('message') rescue KeyError next end end |
#log_event(vendor, event) ⇒ Object
For Appium
302 303 304 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 302 def log_event(vendor, event) execute :post_log_event, {}, { vendor: vendor, event: event } end |
#log_events(type = nil) ⇒ Object
For Appium
307 308 309 310 311 312 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 307 def log_events(type = nil) args = {} args['type'] = type unless type.nil? execute :get_log_events, {}, args end |
#network_connection ⇒ Object
For Appium override called in ‘extend DriverExtensions::HasNetworkConnection’
251 252 253 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 251 def network_connection execute :get_network_connection end |
#network_connection=(type) ⇒ Object
For Appium override called in ‘extend DriverExtensions::HasNetworkConnection’
258 259 260 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 258 def network_connection=(type) execute :set_network_connection, {}, { parameters: { type: type } } 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.
327 328 329 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 327 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
272 273 274 275 276 277 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 272 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
188 189 190 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 188 def status execute :status end |
#viewport_screenshot ⇒ Object
314 315 316 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 314 def execute_script('mobile: viewportScreenshot') end |