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
-
#activate_app(app_id) ⇒ Hash
Activate(Launch) the specified app.
-
#app_installed?(app_id) ⇒ Boolean
Check whether the specified app is installed on the device.
-
#app_state(app_id) ⇒ AppState::STATUS
Get the status of an existing application on the device.
-
#app_strings(language = nil) ⇒ Hash
Return the hash of all localization strings.
-
#available_contexts ⇒ Array<String>
All usable contexts, as an array of strings.
-
#back ⇒ String
Get the device window’s size.
-
#background_app(duration = 0) ⇒ String
Backgrounds the app for a set number of seconds.
-
#close_app ⇒ Object
Close an app on device.
- #compare_images(mode: :matchFeatures, first_image:, second_image:, options: nil) ⇒ Object
-
#current_context ⇒ String
The context currently being used.
-
#device_locked? ⇒ Boolean
Check current device status is weather locked or not.
-
#device_time(format = nil) ⇒ String
Get the time on the device.
-
#dialect ⇒ :oss|:w3c
Get the dialect value.
-
#find_element_by_image(png_img_path) ⇒ ::Selenium::WebDriver::Element
Return an element if current view has a partial image.
-
#find_elements_by_image(png_img_path) ⇒ ::Selenium::WebDriver::Element
Return elements if current view has a partial image.
- #find_image_occurrence(full_image:, partial_image:, visualize: false, threshold: nil) ⇒ Object
- #get_images_similarity(first_image:, second_image:, visualize: false) ⇒ Object
-
#get_settings ⇒ Object
Get appium Settings for current test session.
-
#get_timeouts ⇒ Hash
For W3C.
-
#hide_keyboard(close_key = nil, strategy = nil) ⇒ Object
Hide the onscreen keyboard.
-
#ime_activate(ime_name) ⇒ Object
Android only.
- #ime_activated ⇒ Object
-
#ime_active_engine ⇒ Object
Android only.
-
#ime_available_engines ⇒ Object
Android only.
-
#ime_deactivate ⇒ Object
Android only.
-
#initialize(opts = {}) ⇒ Driver
constructor
A new instance of Driver.
-
#install_app(path, replace: nil, timeout: nil, allow_test_packages: nil, use_sdcard: nil, grant_permissions: nil) ⇒ Object
Install the given app onto the device.
-
#is_keyboard_shown ⇒ Boolean
Get whether keyboard is displayed or not.
-
#keyevent(key, metastate = nil) ⇒ Object
Send keyevent on the device.(Only for Selendroid) developer.android.com/reference/android/view/KeyEvent.html.
-
#launch_app ⇒ Object
Start the simulator and application configured with desired capabilities.
-
#lock(duration = nil) ⇒ String
Lock the device.
-
#logs ⇒ String
Get the device window’s logs.
-
#long_press_keycode(key, metastate: [], flags: []) ⇒ Object
Long press keycode on the device.
-
#match_images_features(first_image:, second_image:, detector_name: 'ORB', match_func: 'BruteForce', good_matches_factor: nil, visualize: false) ⇒ Object
Image Comparison.
- #multi_touch(actions) ⇒ Object
-
#press_keycode(key, metastate: [], flags: []) ⇒ Object
Press keycode on the device.
-
#pull_file(path) ⇒ Base64-decoded
Pull a file from the simulator/device.
-
#pull_folder(path) ⇒ Base64-decoded
Pull a folder content from the simulator/device.
-
#push_file(path, filedata) ⇒ Object
Place a file in a specific location on the device.
- #remove_app(app_id, keep_data: nil, timeout: nil) ⇒ Object
-
#replace_value(element, *value) ⇒ Object
Replace the value to element directly.
-
#reset ⇒ Object
Reset the device, relaunching the application.
-
#send_keys(*key) ⇒ Object
(also: #type)
Send keys for a current active element.
-
#session_capabilities ⇒ Selenium::WebDriver::Remote::Capabilities
Retrieve the capabilities of the specified session.
-
#set_context(context = null) ⇒ Object
Change the context to the given context.
-
#set_immediate_value(element, *value) ⇒ Object
Set the value to element directly.
-
#shake ⇒ Object
Cause the device to shake.
- #stop_and_save_recording_screen(file_path) ⇒ Object
- #stop_recording_screen(remote_path: nil, user: nil, pass: nil, method: 'PUT') ⇒ Object
-
#switch_to_default_context ⇒ Object
Change to the default context.
-
#terminate_app(app_id, timeout: nil) ⇒ Boolean
Terminate the specified app.
-
#touch_actions(actions) ⇒ Object
touch actions.
-
#unlock ⇒ Object
Unlock the device.
-
#update_settings(settings) ⇒ Object
Update Appium Settings for current test session.
-
#window_rect ⇒ Selenium::WebDriver::Rectangle
Get the device window’s rect.
-
#window_size ⇒ Selenium::WebDriver::Dimension
Get the device window’s size.
-
#within_context(context) ⇒ Object
Perform a block within the given context, then switch back to the starting context.
Methods included from TakeScreenshot
#element_screenshot_as, #save_element_screenshot, #save_screenshot, #save_viewport_screenshot, #screenshot_as
Methods included from SearchContext
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
#activate_app(app_id) ⇒ Hash
Activate(Launch) the specified app.
515 516 517 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 515 def activate_app(app_id) @bridge.activate_app(app_id) end |
#app_installed?(app_id) ⇒ Boolean
Check whether the specified app is installed on the device
504 505 506 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 504 def app_installed?(app_id) @bridge.app_installed?(app_id) end |
#app_state(app_id) ⇒ AppState::STATUS
Get the status of an existing application on the device. State:
:not_installed : The current application state cannot be determined/is unknown
:not_running : The application is not running
:running_in_background_suspended : The application is running in the background and is suspended
:running_in_background : The application is running in the background and is not suspended
:running_in_foreground : The application is running in the foreground
For more details: developer.apple.com/documentation/xctest/xcuiapplicationstate
552 553 554 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 552 def app_state(app_id) @bridge.app_state(app_id) end |
#app_strings(language = nil) ⇒ Hash
Return the hash of all localization strings.
430 431 432 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 430 def app_strings(language = nil) @bridge.app_strings(language) end |
#available_contexts ⇒ Array<String>
Returns All usable contexts, as an array of strings.
226 227 228 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 226 def available_contexts @bridge.available_contexts end |
#back ⇒ String
Get the device window’s size.
652 653 654 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 652 def back navigate.back end |
#background_app(duration = 0) ⇒ String
Backgrounds the app for a set number of seconds. This is a blocking application
445 446 447 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 445 def background_app(duration = 0) @bridge.background_app(duration) end |
#close_app ⇒ Object
Close an app on device
409 410 411 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 409 def close_app @bridge.close_app end |
#compare_images(mode: :matchFeatures, first_image:, second_image:, options: nil) ⇒ Object
797 798 799 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 797 def compare_images(mode: :matchFeatures, first_image:, second_image:, options: nil) @bridge.compare_images(mode: mode, first_image: first_image, second_image: second_image, options: ) end |
#current_context ⇒ String
Returns The context currently being used.
216 217 218 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 216 def current_context @bridge.current_context end |
#device_locked? ⇒ Boolean
Check current device status is weather locked or not
61 62 63 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 61 def device_locked? @bridge.device_locked? end |
#device_time(format = nil) ⇒ String
Get the time on the device
607 608 609 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 607 def device_time(format = nil) @bridge.device_time(format) 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) ⇒ ::Selenium::WebDriver::Element
Return an element if current view has a partial image. The logic depends on template matching by OpenCV. You can handle settings for the comparision following below.
817 818 819 820 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 817 def find_element_by_image(png_img_path) template = Base64.encode64 File.read png_img_path find_element :image, template end |
#find_elements_by_image(png_img_path) ⇒ ::Selenium::WebDriver::Element
Return elements if current view has a partial image. The logic depends on template matching by OpenCV. You can handle settings for the comparision following below.
839 840 841 842 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 839 def find_elements_by_image(png_img_path) template = Base64.encode64 File.read png_img_path find_elements :image, template end |
#find_image_occurrence(full_image:, partial_image:, visualize: false, threshold: nil) ⇒ Object
786 787 788 789 790 791 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 786 def find_image_occurrence(full_image:, partial_image:, visualize: false, threshold: nil) @bridge.find_image_occurrence(full_image: full_image, partial_image: partial_image, visualize: visualize, threshold: threshold) end |
#get_images_similarity(first_image:, second_image:, visualize: false) ⇒ Object
793 794 795 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 793 def get_images_similarity(first_image:, second_image:, visualize: false) @bridge.get_images_similarity(first_image: first_image, second_image: second_image, visualize: visualize) end |
#get_settings ⇒ Object
Get appium Settings for current test session
120 121 122 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 120 def get_settings @bridge.get_settings end |
#get_timeouts ⇒ Hash
For W3C. Get the timeout related settings on the server side.
676 677 678 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 676 def get_timeouts @bridge.get_timeouts end |
#hide_keyboard(close_key = nil, strategy = nil) ⇒ Object
Hide the onscreen keyboard
88 89 90 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 88 def hide_keyboard(close_key = nil, strategy = nil) @bridge.hide_keyboard close_key, strategy end |
#ime_activate(ime_name) ⇒ Object
Android only. Make an engine that is available active.
142 143 144 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 142 def ime_activate(ime_name) @bridge.ime_activate(ime_name) end |
#ime_activated ⇒ Object
173 174 175 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 173 def ime_activated @bridge.ime_activated end |
#ime_active_engine ⇒ Object
Android only. Get the name of the active IME engine.
162 163 164 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 162 def ime_active_engine @bridge.ime_active_engine end |
#ime_available_engines ⇒ Object
Android only. List all available input engines on the machine.
152 153 154 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 152 def ime_available_engines @bridge.ime_available_engines end |
#ime_deactivate ⇒ Object
Android only. De-activates the currently-active IME engine.
183 184 185 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 183 def ime_deactivate @bridge.ime_deactivate end |
#install_app(path, replace: nil, timeout: nil, allow_test_packages: nil, use_sdcard: nil, grant_permissions: nil) ⇒ Object
Install the given app onto the device
469 470 471 472 473 474 475 476 477 478 479 480 481 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 469 def install_app(path, replace: nil, timeout: nil, allow_test_packages: nil, use_sdcard: nil, grant_permissions: nil) @bridge.install_app(path, replace: replace, timeout: timeout, allow_test_packages: allow_test_packages, use_sdcard: use_sdcard, grant_permissions: ) end |
#is_keyboard_shown ⇒ Boolean
Get whether keyboard is displayed or not.
98 99 100 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 98 def is_keyboard_shown # rubocop:disable Naming/PredicateName @bridge.is_keyboard_shown end |
#keyevent(key, metastate = nil) ⇒ Object
Send keyevent on the device.(Only for Selendroid) developer.android.com/reference/android/view/KeyEvent.html
345 346 347 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 345 def keyevent(key, = nil) @bridge.keyevent(key, ) end |
#launch_app ⇒ Object
Start the simulator and application configured with desired capabilities
399 400 401 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 399 def launch_app @bridge.launch_app end |
#lock(duration = nil) ⇒ String
Lock the device
51 52 53 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 51 def lock(duration = nil) @bridge.lock(duration) end |
#logs ⇒ String
Get the device window’s logs.
664 665 666 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 664 def logs @logs ||= Logs.new(@bridge) end |
#long_press_keycode(key, metastate: [], flags: []) ⇒ Object
Long press keycode on the device. developer.android.com/reference/android/view/KeyEvent.html
389 390 391 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 389 def long_press_keycode(key, metastate: [], flags: []) @bridge.long_press_keycode(key, metastate: , flags: flags) end |
#match_images_features(first_image:, second_image:, detector_name: 'ORB', match_func: 'BruteForce', good_matches_factor: nil, visualize: false) ⇒ Object
Image Comparison
772 773 774 775 776 777 778 779 780 781 782 783 784 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 772 def match_images_features(first_image:, second_image:, detector_name: 'ORB', match_func: 'BruteForce', good_matches_factor: nil, visualize: false) @bridge.match_images_features(first_image: first_image, second_image: second_image, detector_name: detector_name, match_func: match_func, good_matches_factor: good_matches_factor, visualize: visualize) end |
#multi_touch(actions) ⇒ Object
616 617 618 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 616 def multi_touch(actions) @bridge.multi_touch(actions) end |
#press_keycode(key, metastate: [], flags: []) ⇒ Object
Press keycode on the device. developer.android.com/reference/android/view/KeyEvent.html
367 368 369 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 367 def press_keycode(key, metastate: [], flags: []) @bridge.press_keycode(key, metastate: , flags: flags) end |
#pull_file(path) ⇒ Base64-decoded
Pull a file from the simulator/device. On iOS the server should have ifuse libraries installed and configured properly for this feature to work on real devices. On Android the application under test should be built with debuggable flag enabled in order to get access to its container on the internal file system.
306 307 308 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 306 def pull_file(path) @bridge.pull_file(path) end |
#pull_folder(path) ⇒ Base64-decoded
Pull a folder content from the simulator/device. On iOS the server should have ifuse libraries installed and configured properly for this feature to work on real devices. On Android the application under test should be built with debuggable flag enabled in order to get access to its container on the internal file system.
332 333 334 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 332 def pull_folder(path) @bridge.pull_folder(path) end |
#push_file(path, filedata) ⇒ Object
Place a file in a specific location on the device. On iOS, the server should have ifuse libraries installed and configured properly for this feature to work on real devices. On Android, the application under test should be built with debuggable flag enabled in order to get access to its container on the internal file system.
280 281 282 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 280 def push_file(path, filedata) @bridge.push_file(path, filedata) end |
#remove_app(app_id, keep_data: nil, timeout: nil) ⇒ Object
493 494 495 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 493 def remove_app(app_id, keep_data: nil, timeout: nil) @bridge.remove_app(app_id, keep_data: keep_data, timeout: timeout) end |
#replace_value(element, *value) ⇒ Object
Replace the value to element directly
257 258 259 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 257 def replace_value(element, *value) @bridge.replace_value(element, *value) end |
#reset ⇒ Object
Reset the device, relaunching the application.
419 420 421 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 419 def reset @bridge.reset end |
#send_keys(*key) ⇒ Object Also known as: type
Send keys for a current active element
109 110 111 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 109 def send_keys(*key) @bridge.send_keys_to_active_element(key) 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.
765 766 767 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 765 def session_capabilities @bridge.session_capabilities end |
#set_context(context = null) ⇒ Object
Change the context to the given context.
237 238 239 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 237 def set_context(context = null) @bridge.set_context(context) end |
#set_immediate_value(element, *value) ⇒ Object
Set the value to element directly
247 248 249 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 247 def set_immediate_value(element, *value) @bridge.set_immediate_value(element, *value) end |
#shake ⇒ Object
Cause the device to shake
591 592 593 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 591 def shake @bridge.shake end |
#stop_and_save_recording_screen(file_path) ⇒ Object
581 582 583 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 581 def stop_and_save_recording_screen(file_path) @bridge.stop_and_save_recording_screen(file_path) end |
#stop_recording_screen(remote_path: nil, user: nil, pass: nil, method: 'PUT') ⇒ Object
571 572 573 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 571 def stop_recording_screen(remote_path: nil, user: nil, pass: nil, method: 'PUT') @bridge.stop_recording_screen(remote_path: remote_path, user: user, pass: pass, method: method) end |
#switch_to_default_context ⇒ Object
Change to the default context. This is equivalent to ‘set_context nil`.
206 207 208 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 206 def switch_to_default_context @bridge.switch_to_default_context end |
#terminate_app(app_id, timeout: nil) ⇒ Boolean
Terminate the specified app.
531 532 533 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 531 def terminate_app(app_id, timeout: nil) @bridge.terminate_app(app_id, timeout: timeout) end |
#touch_actions(actions) ⇒ Object
touch actions
612 613 614 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 612 def touch_actions(actions) @bridge.touch_actions(actions) end |
#unlock ⇒ Object
Unlock the device
71 72 73 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 71 def unlock @bridge.unlock end |
#update_settings(settings) ⇒ Object
Update Appium Settings for current test session
131 132 133 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 131 def update_settings(settings) @bridge.update_settings(settings) end |
#window_rect ⇒ Selenium::WebDriver::Rectangle
Get the device window’s rect.
642 643 644 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 642 def window_rect manage.window.rect end |
#window_size ⇒ Selenium::WebDriver::Dimension
Get the device window’s size.
628 629 630 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 628 def window_size manage.window.size end |
#within_context(context) ⇒ Object
Perform a block within the given context, then switch back to the starting context.
196 197 198 |
# File 'lib/appium_lib_core/common/base/driver.rb', line 196 def within_context(context) block_given? ? @bridge.within_context(context, &Proc.new) : @bridge.within_context(context) end |