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::TouchActions, Device::Value
- Defined in:
- lib/appium_lib_core/common/base/bridge.rb
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(async = false) ⇒ Object
Perform touch actions for W3C module.
-
#active_element ⇒ Object
(also: #switch_to_active_element)
For Appium override.
-
#add_appium_prefix(capabilities) ⇒ ::Selenium::WebDriver::Remote::Capabilities
Append
appium:
prefix for Appium following W3C spec www.w3.org/TR/webdriver/#dfn-validate-capabilities. -
#add_command(method:, url:, name:, &block) ⇒ Object
command for Appium 2.0.
-
#available_log_types ⇒ Object
logs.
- #browser ⇒ Object
- #commands(command) ⇒ Object
-
#convert_to_element(id) ⇒ ::Appium::Core::Element
For Appium.
-
#create_session(capabilities) ⇒ ::Selenium::WebDriver::Remote::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
-
#find_element_by(how, what, parent_ref = []) ⇒ Object
For Appium override.
-
#find_elements_by(how, what, parent_ref = []) ⇒ Object
For Appium override.
-
#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’.
-
#page_source ⇒ Object
For Appium override.
-
#send_keys_to_active_element(key) ⇒ Object
Port from MJSONWP.
-
#session_capabilities ⇒ Object
Port from MJSONWP.
-
#sessions ⇒ Object
Returns all available sessions on the Appium server instance.
-
#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.
42 43 44 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 42 def available_commands @available_commands end |
Instance Method Details
#action(async = false) ⇒ Object
Perform touch actions for W3C module. Generate touch
pointer action here and users can use this via driver.action
-
seleniumhq.github.io/selenium/docs/api/rb/Selenium/WebDriver/W3CActionBuilder.html
-
seleniumhq.github.io/selenium/docs/api/rb/Selenium/WebDriver/PointerActions.html
-
seleniumhq.github.io/selenium/docs/api/rb/Selenium/WebDriver/KeyActions.html
The pointer type is ‘touch’ by default in the Appium Ruby client. (The selenium one is ‘mouse’)
169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 169 def action(async = false) action_builder = ::Selenium::WebDriver::ActionBuilder.new( self, ::Selenium::WebDriver::Interactions.pointer(:touch, name: 'touch'), ::Selenium::WebDriver::Interactions.key('keyboard'), async ) # Used for default duration of each touch actions. # Override from 250 milliseconds to 50 milliseconds in PointerActions included by ::Selenium::WebDriver::ActionBuilder action_builder.default_move_duration = 0.05 action_builder end |
#active_element ⇒ Object Also known as: switch_to_active_element
For Appium override
227 228 229 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 227 def active_element ::Appium::Core::Element.new self, element_id_from(execute(:get_active_element)) end |
#add_appium_prefix(capabilities) ⇒ ::Selenium::WebDriver::Remote::Capabilities
Append appium:
prefix for Appium following W3C spec www.w3.org/TR/webdriver/#dfn-validate-capabilities
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 94 def add_appium_prefix(capabilities) w3c_capabilities = ::Selenium::WebDriver::Remote::Capabilities.new capabilities = capabilities.send(:capabilities) unless capabilities.is_a?(Hash) capabilities.each do |name, value| next if value.nil? next if value.is_a?(String) && value.empty? 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
command for Appium 2.0.
135 136 137 138 139 140 141 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 135 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 |
#available_log_types ⇒ Object
logs
For Appium No implementation for W3C webdriver module
315 316 317 318 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 315 def available_log_types types = execute :get_available_log_types Array(types).map(&:to_sym) end |
#browser ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 44 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
143 144 145 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 143 def commands(command) @available_commands[command] end |
#convert_to_element(id) ⇒ ::Appium::Core::Element
For Appium
275 276 277 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 275 def convert_to_element(id) ::Appium::Core::Element.new self, element_id_from(id) end |
#create_session(capabilities) ⇒ ::Selenium::WebDriver::Remote::Capabilities
Override Creates session handling.
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 77 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
219 220 221 222 223 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 219 def element_attribute(element, name) # For W3C in Selenium Client # execute_atom :getAttribute, element, name execute :get_element_attribute, id: element.id, name: name end |
#element_displayed?(element) ⇒ Boolean
For Appium override
210 211 212 213 214 215 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 210 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
349 350 351 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 349 def element_screenshot(element_id) execute :take_element_screenshot, id: element_id end |
#find_element_by(how, what, parent_ref = []) ⇒ Object
For Appium override
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 234 def find_element_by(how, what, parent_ref = []) how, what = convert_locator(how, what) return execute_atom(:findElements, Support::RelativeLocator.new(what).as_json).first if how == 'relative' parent_type, parent_id = parent_ref id = case parent_type when :element execute :find_child_element, { id: parent_id }, { using: how, value: what.to_s } when :shadow_root execute :find_shadow_child_element, { id: parent_id }, { using: how, value: what.to_s } else execute :find_element, {}, { using: how, value: what.to_s } end ::Appium::Core::Element.new self, element_id_from(id) end |
#find_elements_by(how, what, parent_ref = []) ⇒ Object
For Appium override
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 254 def find_elements_by(how, what, parent_ref = []) how, what = convert_locator(how, what) return execute_atom :findElements, Support::RelativeLocator.new(what).as_json if how == 'relative' parent_type, parent_id = parent_ref ids = case parent_type when :element execute :find_child_elements, { id: parent_id }, { using: how, value: what.to_s } when :shadow_root execute :find_shadow_child_elements, { id: parent_id }, { using: how, value: what.to_s } else execute :find_elements, {}, { using: how, value: what.to_s } end ids.map { |id| ::Appium::Core::Element.new self, element_id_from(id) } end |
#get_timeouts ⇒ Object
Port from MJSONWP
183 184 185 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 183 def get_timeouts execute :get_timeouts end |
#location ⇒ Object
For Appium No implementation for W3C webdriver module called in ‘extend DriverExtensions::HasLocation’
296 297 298 299 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 296 def location obj = execute(:get_location) || {} ::Selenium::WebDriver::Location.new obj['latitude'], obj['longitude'], obj['altitude'] end |
#log(type) ⇒ Object
For Appium No implementation for W3C webdriver module
322 323 324 325 326 327 328 329 330 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 322 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
333 334 335 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 333 def log_event(vendor, event) execute :post_log_event, {}, { vendor: vendor, event: event } end |
#log_events(type = nil) ⇒ Object
For Appium
338 339 340 341 342 343 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 338 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’
282 283 284 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 282 def network_connection execute :get_network_connection end |
#network_connection=(type) ⇒ Object
For Appium override called in ‘extend DriverExtensions::HasNetworkConnection’
289 290 291 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 289 def network_connection=(type) execute :set_network_connection, {}, { parameters: { type: type } } end |
#page_source ⇒ Object
For Appium override
200 201 202 203 204 205 206 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 200 def page_source # For W3C # execute_script('var source = document.documentElement.outerHTML;' \ # 'if (!source) { source = new XMLSerializer().serializeToString(document); }' \ # 'return source;') execute :get_page_source end |
#send_keys_to_active_element(key) ⇒ Object
Port from MJSONWP
193 194 195 196 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 193 def send_keys_to_active_element(key) text = ::Selenium::WebDriver::Keys.encode(key).join execute :send_keys_to_active_element, {}, { value: text.chars } end |
#session_capabilities ⇒ Object
Port from MJSONWP
188 189 190 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 188 def session_capabilities ::Selenium::WebDriver::Remote::Capabilities.json_create execute(:get_capabilities) end |
#sessions ⇒ Object
Returns all available sessions on the Appium server instance
148 149 150 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 148 def sessions execute :get_all_sessions end |
#set_location(lat, lon, alt = 0.0, speed: nil, satellites: nil) ⇒ Object
For Appium No implementation for W3C webdriver module
303 304 305 306 307 308 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 303 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
152 153 154 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 152 def status execute :status end |
#viewport_screenshot ⇒ Object
345 346 347 |
# File 'lib/appium_lib_core/common/base/bridge.rb', line 345 def execute_script('mobile: viewportScreenshot') end |