Class: Appium::Core::Base::Driver
- Inherits:
-
Selenium::WebDriver::Driver
- Object
- Selenium::WebDriver::Driver
- Appium::Core::Base::Driver
- Includes:
- SearchContext, TakeScreenshot, Selenium::WebDriver::DriverExtensions::HasRemoteStatus, Selenium::WebDriver::DriverExtensions::HasSessionId, Selenium::WebDriver::DriverExtensions::HasWebStorage, Selenium::WebDriver::DriverExtensions::Rotatable, Selenium::WebDriver::DriverExtensions::UploadsFiles
- Defined in:
- lib/appium_lib_core/common/base/driver.rb
Constant Summary collapse
- DEFAULT_MATCH_THRESHOLD =
0.5
Constants included from SearchContext
Instance Method Summary collapse
-
#back ⇒ String
Get the device window’s size.
-
#dialect ⇒ :oss|:w3c
Get the dialect value.
-
#find_element_by_image(png_img_path, match_threshold: DEFAULT_MATCH_THRESHOLD, visualize: false) ⇒ ::Appium::Core::ImageElement
Return ImageElement if current view has a partial image.
-
#find_elements_by_image(png_img_paths, match_threshold: DEFAULT_MATCH_THRESHOLD, visualize: false) ⇒ [::Appium::Core::ImageElement], ::Appium::Core::Error::CoreError
Return ImageElement if current view has partial images.
-
#get_timeouts ⇒ Hash
For W3C.
-
#initialize(opts = {}) ⇒ Driver
constructor
A new instance of Driver.
-
#logs ⇒ String
Get the device window’s logs.
-
#session_capabilities ⇒ Selenium::WebDriver::Remote::Capabilities
Retrieve the capabilities of the specified session.
-
#window_rect ⇒ Selenium::WebDriver::Rectangle
Get the device window’s rect.
-
#window_size ⇒ Selenium::WebDriver::Dimension
Get the device window’s size.
Methods included from TakeScreenshot
#element_screenshot_as, #save_element_screenshot, #save_screenshot, #screenshot_as
Methods included from SearchContext
add_finders, #find_element, #find_elements
Constructor Details
#initialize(opts = {}) ⇒ Driver
Returns a new instance of Driver.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 18 def initialize(opts = {}) listener = opts.delete(:listener) @bridge = ::Appium::Core::Base::Bridge.handshake(opts) if @bridge.dialect == :oss # MJSONWP extend ::Selenium::WebDriver::DriverExtensions::HasTouchScreen extend ::Selenium::WebDriver::DriverExtensions::HasLocation extend ::Selenium::WebDriver::DriverExtensions::HasNetworkConnection elsif @bridge.dialect == :w3c # TODO: Only for Appium. Ideally, we'd like to remove the below like selenium-webdriver extend ::Selenium::WebDriver::DriverExtensions::HasTouchScreen extend ::Selenium::WebDriver::DriverExtensions::HasLocation extend ::Selenium::WebDriver::DriverExtensions::HasNetworkConnection end super(@bridge, listener: listener) end |
Instance Method Details
#back ⇒ String
Get the device window’s size.
72 73 74 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 72 def back navigate.back end |
#dialect ⇒ :oss|:w3c
Get the dialect value
36 37 38 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 36 def dialect @bridge.dialect end |
#find_element_by_image(png_img_path, match_threshold: DEFAULT_MATCH_THRESHOLD, visualize: false) ⇒ ::Appium::Core::ImageElement
Return ImageElement if current view has a partial image
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 205 def find_element_by_image(png_img_path, match_threshold: DEFAULT_MATCH_THRESHOLD, visualize: false) full_image = @bridge.screenshot partial_image = Base64.encode64 File.read(png_img_path) element = begin @bridge.find_element_by_image(full_image: full_image, partial_image: partial_image, match_threshold: match_threshold, visualize: visualize) rescue Selenium::WebDriver::Error::TimeOutError raise ::Appium::Core::Error::NoSuchElementError rescue ::Selenium::WebDriver::Error::WebDriverError => e raise ::Appium::Core::Error::NoSuchElementError if e..include?('Cannot find any occurrences') raise ::Appium::Core::Error::CoreError, e. end raise ::Appium::Core::Error::NoSuchElementError if element.nil? element end |
#find_elements_by_image(png_img_paths, match_threshold: DEFAULT_MATCH_THRESHOLD, visualize: false) ⇒ [::Appium::Core::ImageElement], ::Appium::Core::Error::CoreError
Return ImageElement if current view has partial images
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 240 def find_elements_by_image(png_img_paths, match_threshold: DEFAULT_MATCH_THRESHOLD, visualize: false) full_image = @bridge.screenshot partial_images = png_img_paths.map do |png_img_path| Base64.encode64 File.read(png_img_path) end begin @bridge.find_elements_by_image(full_image: full_image, partial_images: partial_images, match_threshold: match_threshold, visualize: visualize) rescue Selenium::WebDriver::Error::TimeOutError [] rescue ::Selenium::WebDriver::Error::WebDriverError => e return [] if e..include?('Cannot find any occurrences') raise ::Appium::Core::Error::CoreError, e. end end |
#get_timeouts ⇒ Hash
For W3C. Get the timeout related settings on the server side.
96 97 98 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 96 def get_timeouts @bridge.get_timeouts end |
#logs ⇒ String
Get the device window’s logs.
84 85 86 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 84 def logs @logs ||= Logs.new(@bridge) end |
#session_capabilities ⇒ Selenium::WebDriver::Remote::Capabilities
Retrieve the capabilities of the specified session. It’s almost same as ‘@driver.capabilities` but you can get more details.
185 186 187 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 185 def session_capabilities @bridge.session_capabilities end |
#window_rect ⇒ Selenium::WebDriver::Rectangle
Get the device window’s rect.
62 63 64 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 62 def window_rect manage.window.rect end |
#window_size ⇒ Selenium::WebDriver::Dimension
Get the device window’s size.
48 49 50 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 48 def window_size manage.window.size end |