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

Inherits:
Selenium::WebDriver::Remote::W3C::Bridge
  • Object
show all
Includes:
Device::AppManagement, Device::AppState, Device::Context, Device::Device, Device::DeviceLock, Device::FileManagement, Device::ImageComparison, Device::ImeActions, Device::KeyEvent, Device::Keyboard, Device::ScreenRecord::Command, Device::Setting, Device::TouchActions, Device::Value
Defined in:
lib/appium_lib_core/common/base/bridge/w3c.rb

Constant Summary

Constants included from Device::AppState

Device::AppState::STATUS

Constants included from Device::ImageComparison

Device::ImageComparison::GET_SIMILARITY, Device::ImageComparison::MATCH_FEATURES, Device::ImageComparison::MATCH_TEMPLATE, Device::ImageComparison::MODE

Instance Method Summary collapse

Methods included from Device::TouchActions

#multi_touch, #touch_actions

Methods included from Device::Device

#device_time, #shake

Methods included from Device::ScreenRecord::Command

#stop_and_save_recording_screen, #stop_recording_screen

Methods included from Device::AppState

#app_state

Methods included from Device::AppManagement

#activate_app, #app_installed?, #app_strings, #background_app, #close_app, #install_app, #launch_app, #remove_app, #reset, #terminate_app

Methods included from Device::ImageComparison

#compare_images, #find_image_occurrence, #get_images_similarity, #match_images_features

Methods included from Device::KeyEvent

#keyevent, #long_press_keycode, #press_keycode

Methods included from Device::FileManagement

#pull_file, #pull_folder, #push_file

Methods included from Device::Value

#replace_value, #set_immediate_value

Methods included from Device::Context

#available_contexts, #current_context, #set_context, #switch_to_default_context, #within_context

Methods included from Device::Setting

#get_settings, #update_settings

Methods included from Device::ImeActions

#ime_activate, #ime_activated, #ime_active_engine, #ime_available_engines, #ime_deactivate

Methods included from Device::Keyboard

#hide_keyboard, #is_keyboard_shown

Methods included from Device::DeviceLock

#device_locked?, #lock, #unlock

Instance Method Details

#available_log_typesObject

logs

For Appium No implementation for W3C webdriver module



203
204
205
206
# File 'lib/appium_lib_core/common/base/bridge/w3c.rb', line 203

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

#commands(command) ⇒ Object



27
28
29
# File 'lib/appium_lib_core/common/base/bridge/w3c.rb', line 27

def commands(command)
  ::Appium::Core::Commands::W3C::COMMANDS[command]
end

#element_attribute(element, name) ⇒ Object

For Appium override



71
72
73
74
75
# File 'lib/appium_lib_core/common/base/bridge/w3c.rb', line 71

def element_attribute(element, name)
  # For W3C
  # execute_atom :getAttribute, element, name
  execute :get_element_attribute, id: element.ref, name: name
end

#find_element_by(how, what, parent = nil) ⇒ Object

For Appium override



79
80
81
82
83
84
85
86
87
88
# File 'lib/appium_lib_core/common/base/bridge/w3c.rb', line 79

def find_element_by(how, what, parent = nil)
  how, what = convert_locators(how, what)

  id = if parent
         execute :find_child_element, { id: parent }, { using: how, value: what }
       else
         execute :find_element, {}, { using: how, value: what }
       end
  ::Selenium::WebDriver::Element.new self, element_id_from(id)
end

#find_element_by_image(full_image:, partial_image:, match_threshold: nil, visualize: false) ⇒ ::Appium::Core::ImageElement|nil

Returns:

Raises:

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


108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/appium_lib_core/common/base/bridge/w3c.rb', line 108

def find_element_by_image(full_image:, partial_image:, match_threshold: nil, visualize: false)
  options = {}
  options[:threshold] = match_threshold unless match_threshold.nil?
  options[:visualize] = visualize

  params = {}
  params[:mode] = :matchTemplate
  params[:firstImage] = full_image
  params[:secondImage] = partial_image
  params[:options] = options if options

  result = execute(:compare_images, {}, params)
  rect = result['rect']

  if rect
    return ::Appium::Core::ImageElement.new(self,
                                            rect['x'],
                                            rect['y'],
                                            rect['width'],
                                            rect['height'],
                                            result['visualization'])
  end
  nil
end

#find_elements_by(how, what, parent = nil) ⇒ Object

For Appium override



92
93
94
95
96
97
98
99
100
101
102
# File 'lib/appium_lib_core/common/base/bridge/w3c.rb', line 92

def find_elements_by(how, what, parent = nil)
  how, what = convert_locators(how, what)

  ids = if parent
          execute :find_child_elements, { id: parent }, { using: how, value: what }
        else
          execute :find_elements, {}, { using: how, value: what }
        end

  ids.map { |id| ::Selenium::WebDriver::Element.new self, element_id_from(id) }
end

#find_elements_by_image(full_image:, partial_images:, match_threshold: nil, visualize: false) ⇒ []|[::Appium::Core::ImageElement]

Returns:

Raises:

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


137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/appium_lib_core/common/base/bridge/w3c.rb', line 137

def find_elements_by_image(full_image:, partial_images:, match_threshold: nil, visualize: false)
  options = {}
  options[:threshold] = match_threshold unless match_threshold.nil?
  options[:visualize] = visualize

  params = {}
  params[:mode] = :matchTemplate
  params[:firstImage] = full_image
  params[:options] = options if options

  partial_images.each_with_object([]) do |partial_image, acc|
    params[:secondImage] = partial_image

    begin
      result = execute(:compare_images, {}, params)
      rect = result['rect']

      if result['rect']
        acc.push ::Appium::Core::ImageElement.new(self,
                                                  rect['x'],
                                                  rect['y'],
                                                  rect['width'],
                                                  rect['height'],
                                                  result['visualization'])
      end
    rescue ::Selenium::WebDriver::Error::WebDriverError => e
      acc if e.message.include?('Cannot find any occurrences')
    end
  end
end

#get_timeoutsObject

Port from MJSONWP



50
51
52
# File 'lib/appium_lib_core/common/base/bridge/w3c.rb', line 50

def get_timeouts
  execute :get_timeouts
end

#locationObject

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



185
186
187
188
# File 'lib/appium_lib_core/common/base/bridge/w3c.rb', line 185

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



210
211
212
213
214
215
216
217
218
219
220
# File 'lib/appium_lib_core/common/base/bridge/w3c.rb', line 210

def log(type)
  data = execute :get_log, {}, { type: type.to_s }

  Array(data).map do |l|
    begin
      ::Selenium::WebDriver::LogEntry.new l.fetch('level', 'UNKNOWN'), l.fetch('timestamp'), l.fetch('message')
    rescue KeyError
      next
    end
  end
end

#network_connectionObject

For Appium override called in ‘extend DriverExtensions::HasNetworkConnection`



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

def network_connection
  execute :get_network_connection
end

#network_connection=(type) ⇒ Object

For Appium override called in ‘extend DriverExtensions::HasNetworkConnection`



178
179
180
# File 'lib/appium_lib_core/common/base/bridge/w3c.rb', line 178

def network_connection=(type)
  execute :set_network_connection, {}, { parameters: { type: type } }
end

#page_sourceObject

For Appium override



61
62
63
64
65
66
67
# File 'lib/appium_lib_core/common/base/bridge/w3c.rb', line 61

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

#session_capabilitiesObject

Port from MJSONWP



55
56
57
# File 'lib/appium_lib_core/common/base/bridge/w3c.rb', line 55

def session_capabilities
  ::Selenium::WebDriver::Remote::W3C::Capabilities.json_create execute(:get_capabilities)
end

#set_location(lat, lon, alt) ⇒ Object

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



193
194
195
196
# File 'lib/appium_lib_core/common/base/bridge/w3c.rb', line 193

def set_location(lat, lon, alt)
  loc = { latitude: lat, longitude: lon, altitude: alt }
  execute :set_location, {}, { location: loc }
end

#take_element_screenshot(element) ⇒ Object



226
227
228
# File 'lib/appium_lib_core/common/base/bridge/w3c.rb', line 226

def take_element_screenshot(element)
  execute :take_element_screenshot, id: element.ref
end

#take_viewport_screenshotObject



222
223
224
# File 'lib/appium_lib_core/common/base/bridge/w3c.rb', line 222

def take_viewport_screenshot
  execute_script('mobile: viewportScreenshot')
end