Class: Appium::Core::Base::Bridge

Inherits:
Selenium::WebDriver::Remote::Bridge
  • Object
show all
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

Direct Known Subclasses

BiDiBridge

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 Method Summary collapse

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

The pointer type is ‘touch’ by default in the Appium Ruby client.

Examples:


element = @driver.find_element(:id, "some id")
@driver.action.click(element).perform # The 'click' is a part of 'PointerActions'


190
191
192
193
194
195
196
197
198
199
# File 'lib/appium_lib_core/common/base/bridge.rb', line 190

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 www.w3.org/TR/webdriver/#dfn-validate-capabilities

Parameters:

Returns:



123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/appium_lib_core/common/base/bridge.rb', line 123

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.

Examples:


new_driver = ::Appium::Core::Driver.attach_to(
  driver.session_id,
  url: 'http://127.0.0.1:4723', automation_name: 'UiAutomator2', platform_name: 'Android'
)

Parameters:

  • session_id (String)

    The session id to attach to.

  • platform_name (String)

    The platform name to keep in the dummy capabilities

  • automation_name (String)

    The automation name to keep in the dummy capabilities

Returns:



74
75
76
77
78
79
80
81
82
# File 'lib/appium_lib_core/common/base/bridge.rb', line 74

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_typesObject

logs

For Appium No implementation for W3C webdriver module



256
257
258
259
# File 'lib/appium_lib_core/common/base/bridge.rb', line 256

def available_log_types
  types = execute :get_available_log_types
  Array(types).map(&:to_sym) # steep:ignore
end

#browserObject



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

#command_listObject

Override Selenium’s command_list to use Appium’s command definitions instead of the default W3C COMMANDS from Selenium.



162
163
164
# File 'lib/appium_lib_core/common/base/bridge.rb', line 162

def command_list
  ::Appium::Core::Commands::COMMANDS
end

#commands(command) ⇒ Object

Override Selenium’s commands to resolve extra_commands from this subclass rather than the parent Selenium::WebDriver::Remote::Bridge.



168
169
170
# File 'lib/appium_lib_core/common/base/bridge.rb', line 168

def commands(command)
  command_list[command] || self.class.extra_commands&.[](command)
end

#convert_to_element(id) ⇒ ::Appium::Core::Element

For Appium

Parameters:

  • id (Hash)

    The id which can get as a response from server

Returns:



230
231
232
# File 'lib/appium_lib_core/common/base/bridge.rb', line 230

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.

Examples:


opts = {
  caps: {
    platformName: :ios,
    automationName: 'XCUITest',
    app: 'test/functional/app/UIKitCatalog-iphonesimulator.zip',
    platformVersion: '11.4',
    deviceName: 'iPhone Simulator',
    useNewWDA: true,
  },
  appium_lib: {
    wait: 30
  }
}
core = ::Appium::Core.for(caps)
driver = core.start_driver

Parameters:

Returns:

Raises:

  • (::Selenium::WebDriver::Error::WebDriverError)


108
109
110
111
112
113
114
115
116
# File 'lib/appium_lib_core/common/base/bridge.rb', line 108

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



217
218
219
220
221
222
# File 'lib/appium_lib_core/common/base/bridge.rb', line 217

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

Returns:

  • (Boolean)


208
209
210
211
212
213
# File 'lib/appium_lib_core/common/base/bridge.rb', line 208

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



292
293
294
# File 'lib/appium_lib_core/common/base/bridge.rb', line 292

def element_screenshot(element_id)
  execute :take_element_screenshot, id: element_id
end

#get_timeoutsObject

Port from MJSONWP



202
203
204
# File 'lib/appium_lib_core/common/base/bridge.rb', line 202

def get_timeouts
  execute :get_timeouts
end

#locationObject

For Appium No implementation for W3C webdriver module called in ‘extend DriverExtensions::HasLocation’



237
238
239
240
# File 'lib/appium_lib_core/common/base/bridge.rb', line 237

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



263
264
265
266
267
268
269
270
271
272
273
# File 'lib/appium_lib_core/common/base/bridge.rb', line 263

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



276
277
278
# File 'lib/appium_lib_core/common/base/bridge.rb', line 276

def log_event(vendor, event)
  execute :post_log_event, {}, { vendor: vendor, event: event }
end

#log_events(type = nil) ⇒ Object

For Appium



281
282
283
284
285
286
# File 'lib/appium_lib_core/common/base/bridge.rb', line 281

def log_events(type = nil)
  args = {} # steep:ignore
  args['type'] = type unless type.nil?

  execute :get_log_events, {}, args
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.



301
302
303
# File 'lib/appium_lib_core/common/base/bridge.rb', line 301

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



244
245
246
247
248
249
# File 'lib/appium_lib_core/common/base/bridge.rb', line 244

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

#statusObject



172
173
174
# File 'lib/appium_lib_core/common/base/bridge.rb', line 172

def status
  execute :status
end

#viewport_screenshotObject



288
289
290
# File 'lib/appium_lib_core/common/base/bridge.rb', line 288

def viewport_screenshot
  execute_script('mobile: viewportScreenshot')
end