Class: Appium::Driver
- Inherits:
-
Object
- Object
- Appium::Driver
- Extended by:
- Forwardable
- Defined in:
- lib/appium_lib/driver.rb
Constant Summary collapse
- CORE_BRIDGE_METHODS =
Methods forwarded to the underlying Appium::Core::Base::Driver instance (exposed via ‘#driver`). Previously these were wired up implicitly by `extend ::Appium::Core::Device` through a static compatibility list in `ruby_lib_core` (see appium/ruby_lib_core#97). Defining them here lets `ruby_lib_core` eventually drop that list.
%i[ take_element_screenshot save_viewport_screenshot lock device_locked? unlock hide_keyboard is_keyboard_shown ime_activate ime_available_engines ime_active_engine ime_activated ime_deactivate get_settings update_settings within_context current_context available_contexts set_context push_file pull_file pull_folder keyevent press_keycode long_press_keycode match_images_features find_image_occurrence get_images_similarity compare_images app_strings background_app install_app remove_app app_installed? activate_app terminate_app app_state stop_recording_screen stop_and_save_recording_screen shake device_time execute_cdp ].freeze
Instance Attribute Summary collapse
-
#appium_debug ⇒ Object
readonly
Boolean debug mode for the Appium Ruby bindings.
-
#appium_device ⇒ Object
readonly
Returns the value of attribute appium_device.
-
#appium_port ⇒ Object
readonly
Returns the value of attribute appium_port.
-
#appium_server_status ⇒ Object
readonly
Appium’s server version.
-
#appium_wait_interval ⇒ Object
readonly
Returns the value of attribute appium_wait_interval.
-
#appium_wait_timeout ⇒ Object
readonly
Returns the value of attribute appium_wait_timeout.
-
#automation_name ⇒ Object
readonly
Returns the value of attribute automation_name.
-
#caps ⇒ Object
readonly
from Core read www.rubydoc.info/github/appium/ruby_lib_core/Appium/Core/Driver.
-
#core ⇒ Object
readonly
Instance of Appium::Core::Driver.
-
#custom_url ⇒ Object
readonly
Returns the value of attribute custom_url.
-
#default_wait ⇒ Object
readonly
Returns the value of attribute default_wait.
-
#driver ⇒ Driver
readonly
Returns the driver.
-
#global_webdriver_http_sleep ⇒ Object
The amount to sleep in seconds before every webdriver http call.
-
#http_client ⇒ Object
readonly
Returns the value of attribute http_client.
-
#listener ⇒ Object
readonly
Returns the value of attribute listener.
-
#sauce ⇒ Object
readonly
SauceLab’s settings.
-
#sauce_access_key ⇒ Object
readonly
Access Key for use on Sauce Labs.
-
#sauce_endpoint ⇒ Object
readonly
Override the Sauce Appium endpoint to allow e.g.
-
#sauce_username ⇒ Object
readonly
Username for use on Sauce Labs.
Class Method Summary collapse
-
.absolute_app_path(opts) ⇒ String
- Deprecated
-
Converts app_path to an absolute path.
- .convert_to_symbol(value) ⇒ Object
- .get_cap(caps, name) ⇒ Object
Instance Method Summary collapse
-
#action ⇒ Selenium::WebDriver::PointerActions
An entry point to chain W3C actions Read www.rubydoc.info/github/appium/ruby_lib_core/Appium/Core/Base/Bridge/W3C#action-instance_method.
-
#appium_client_version ⇒ Hash
Returns the client’s version info.
-
#appium_server_version ⇒ Hash
(also: #remote_status)
Returns the server’s version info.
-
#automation_name_is_espresso? ⇒ Boolean
Return true if automationName is ‘Espresso’.
-
#automation_name_is_uiautomator2? ⇒ Boolean
Return true if automationName is ‘uiautomator2’.
-
#automation_name_is_xcuitest? ⇒ Boolean
Return true if automationName is ‘XCUITest’.
- #current_url ⇒ Object
- #device_is_android? ⇒ Boolean
- #device_is_ios? ⇒ Boolean
- #device_is_windows? ⇒ Boolean
-
#driver_attributes ⇒ Object
Returns a hash of the driver attributes.
-
#driver_quit ⇒ void
(also: #quit_driver)
Quits the driver.
-
#element_screenshot(element, png_save_path) ⇒ File
Takes a png screenshot of particular element’s area.
-
#execute_async_script(script, *args) ⇒ Object
Wrap calling selenium webdrier APIs via ruby_core.
-
#execute_driver(script: '', type: 'webdriverio', timeout_ms: nil) ⇒ Appium::Core::Base::Device::ExecuteDriver::Result
Run a set of script against the current session, allowing execution of many commands in one Appium request.
-
#execute_script(script, *args) ⇒ Object
The same as @driver.execute_script.
-
#exists(pre_check = 0, post_check = @default_wait) { ... } ⇒ Boolean
Returns existence of element.
-
#find_element(*args) ⇒ Element
Calls @driver.find_element.
-
#find_element_by_image(png_img_path) ⇒ ::Appium::Core::ImageElement
Return ImageElement if current view has a partial image.
-
#find_elements(*args) ⇒ Array<Element>
Calls @driver.find_elements_with_appium.
-
#find_elements_by_image(png_img_paths) ⇒ [::Appium::Core::ImageElement], ::Appium::Core::Error::CoreError
Return ImageElement if current view has partial images.
- #get(url) ⇒ Object
-
#initialize(opts = {}, global_driver = false) ⇒ Driver
constructor
Creates a new driver.
-
#log_event(vendor:, event:) ⇒ nil
Logs a custom event.
- #log_event=(log_event) ⇒ Object
-
#log_events(type = nil) ⇒ Hash
Returns events with filtering with ‘type’.
- #manage ⇒ Object
- #navigate ⇒ Object
-
#no_wait ⇒ Object
Set implicit wait to zero.
-
#platform_version ⇒ Array<Integer>
Return the platform version as an array of integers.
-
#restart ⇒ Driver
Restarts the driver.
-
#screenshot(png_save_path) ⇒ File
Takes a png screenshot and saves to the target path.
-
#server_url ⇒ String
Get the server url.
-
#set_implicit_wait(wait) ⇒ Object
To ignore error for Espresso Driver.
-
#set_location(opts = {}) ⇒ Selenium::WebDriver::Location
Calls @driver.set_location.
-
#set_wait(timeout = nil) ⇒ void
Set implicit wait.
-
#start_driver(http_client_ops = { http_client: nil, open_timeout: 999_999, read_timeout: 999_999 }) ⇒ Selenium::WebDriver
Creates a new global driver and quits the old one if it exists.
- #switch_to ⇒ TargetLocator
- #title ⇒ Object
-
#window_handle ⇒ Object
Get the current window handle.
- #window_handles ⇒ Object
-
#window_rect ⇒ Selenium::WebDriver::Rectangle
Get the device window’s rect.
-
#window_size ⇒ Selenium::WebDriver::Dimension
Get the device window’s size.
-
#x ⇒ void
Quit the driver and Pry.
Constructor Details
#initialize(opts = {}, global_driver = false) ⇒ Driver
Creates a new driver. The driver is defined as global scope by default. We can avoid defining global driver.
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
# File 'lib/appium_lib/driver.rb', line 200 def initialize(opts = {}, global_driver = false) # Capybara can't put `global_driver` as the 2nd argument. global_driver = opts.delete :global_driver if global_driver.nil? $driver&.driver_quit if global_driver raise ArgumentError, 'opts must be a hash' unless opts.is_a? Hash @core = ::Appium::Core.for(opts) extend ::Appium::Core::Device opts = Appium.symbolize_keys opts appium_lib_opts = opts[:appium_lib] || {} @caps = @core.caps @custom_url = @core.custom_url @default_wait = @core.default_wait || 0 @appium_port = @core.port @appium_wait_timeout = @core.wait_timeout @appium_wait_interval = @core.wait_interval @listener = @core.listener @appium_device = @core.device @automation_name = @core.automation_name # Arrange the app capability. This must be after @core = ::Appium::Core.for(opts) set_app_path(opts) # enable debug patch @appium_debug = appium_lib_opts.fetch :debug, !!defined?(Pry) # rubocop:disable Style/DoubleNegation (appium_lib_opts) # Extend Common methods extend Appium::Common extend Appium::Device # Extend each driver's methods extend_for(device: @core.device, automation_name: @core.automation_name) # for command if @appium_debug Appium::Logger.debug opts unless opts.empty? Appium::Logger.debug "Debug is: #{@appium_debug}" Appium::Logger.debug "Device is: #{@core.device}" end # Save global reference to last created Appium driver for top level methods. $driver = self if global_driver self # rubocop:disable Lint/Void # return newly created driver end |
Instance Attribute Details
#appium_debug ⇒ Object (readonly)
Boolean debug mode for the Appium Ruby bindings
126 127 128 |
# File 'lib/appium_lib/driver.rb', line 126 def appium_debug @appium_debug end |
#appium_device ⇒ Object (readonly)
Returns the value of attribute appium_device.
116 117 118 |
# File 'lib/appium_lib/driver.rb', line 116 def appium_device @appium_device end |
#appium_port ⇒ Object (readonly)
Returns the value of attribute appium_port.
115 116 117 |
# File 'lib/appium_lib/driver.rb', line 115 def appium_port @appium_port end |
#appium_server_status ⇒ Object (readonly)
Appium’s server version
124 125 126 |
# File 'lib/appium_lib/driver.rb', line 124 def appium_server_status @appium_server_status end |
#appium_wait_interval ⇒ Object (readonly)
Returns the value of attribute appium_wait_interval.
121 122 123 |
# File 'lib/appium_lib/driver.rb', line 121 def appium_wait_interval @appium_wait_interval end |
#appium_wait_timeout ⇒ Object (readonly)
Returns the value of attribute appium_wait_timeout.
120 121 122 |
# File 'lib/appium_lib/driver.rb', line 120 def appium_wait_timeout @appium_wait_timeout end |
#automation_name ⇒ Object (readonly)
Returns the value of attribute automation_name.
117 118 119 |
# File 'lib/appium_lib/driver.rb', line 117 def automation_name @automation_name end |
#caps ⇒ Object (readonly)
112 113 114 |
# File 'lib/appium_lib/driver.rb', line 112 def caps @caps end |
#core ⇒ Object (readonly)
Instance of Appium::Core::Driver
131 132 133 |
# File 'lib/appium_lib/driver.rb', line 131 def core @core end |
#custom_url ⇒ Object (readonly)
Returns the value of attribute custom_url.
113 114 115 |
# File 'lib/appium_lib/driver.rb', line 113 def custom_url @custom_url end |
#default_wait ⇒ Object (readonly)
Returns the value of attribute default_wait.
114 115 116 |
# File 'lib/appium_lib/driver.rb', line 114 def default_wait @default_wait end |
#driver ⇒ Driver (readonly)
Returns the driver
129 130 131 |
# File 'lib/appium_lib/driver.rb', line 129 def driver @driver end |
#global_webdriver_http_sleep ⇒ Object
The amount to sleep in seconds before every webdriver http call.
96 97 98 |
# File 'lib/appium_lib/driver.rb', line 96 def global_webdriver_http_sleep @global_webdriver_http_sleep end |
#http_client ⇒ Object (readonly)
Returns the value of attribute http_client.
119 120 121 |
# File 'lib/appium_lib/driver.rb', line 119 def http_client @http_client end |
#listener ⇒ Object (readonly)
Returns the value of attribute listener.
118 119 120 |
# File 'lib/appium_lib/driver.rb', line 118 def listener @listener end |
#sauce ⇒ Object (readonly)
SauceLab’s settings
99 100 101 |
# File 'lib/appium_lib/driver.rb', line 99 def sauce @sauce end |
#sauce_access_key ⇒ Object (readonly)
Access Key for use on Sauce Labs. Set ‘false` to disable Sauce, even when SAUCE_ACCESS_KEY is in ENV. same as @sauce.access_key
105 106 107 |
# File 'lib/appium_lib/driver.rb', line 105 def sauce_access_key @sauce_access_key end |
#sauce_endpoint ⇒ Object (readonly)
Override the Sauce Appium endpoint to allow e.g. TestObject tests same as @sauce.endpoint
108 109 110 |
# File 'lib/appium_lib/driver.rb', line 108 def sauce_endpoint @sauce_endpoint end |
#sauce_username ⇒ Object (readonly)
Username for use on Sauce Labs. Set ‘false` to disable Sauce, even when SAUCE_USERNAME is in ENV. same as @sauce.username
102 103 104 |
# File 'lib/appium_lib/driver.rb', line 102 def sauce_username @sauce_username end |
Class Method Details
.absolute_app_path(opts) ⇒ String
- Deprecated
-
Converts app_path to an absolute path.
opts is the full options hash (caps and appium_lib). If server_url is set then the app path is used as is.
if app isn’t set then an error is raised.
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 |
# File 'lib/appium_lib/driver.rb', line 429 def self.absolute_app_path(opts) raise ArgumentError, 'opts must be a hash' unless opts.is_a? Hash caps = opts[:caps] || opts['caps'] || {} app_path = get_cap(caps, 'app') raise ArgumentError, 'absolute_app_path invoked and app is not set!' if app_path.nil? || app_path.empty? # Sauce storage API. http://saucelabs.com/docs/rest#storage return app_path if app_path.start_with? 'sauce-storage:' return app_path if app_path =~ URI::DEFAULT_PARSER.make_regexp # public URL for Sauce ::Appium::Logger.warn('[Deprecation] Converting the path to absolute path will be removed. ' \ 'Please specify the full path which can be accessible from the appium server') absolute_app_path = File. app_path if File.exist? absolute_app_path absolute_app_path else ::Appium::Logger.info("Use #{app_path}") app_path end end |
.convert_to_symbol(value) ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/appium_lib/driver.rb', line 72 def convert_to_symbol(value) if value.nil? value else value.to_sym end end |
.get_cap(caps, name) ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/appium_lib/driver.rb', line 81 def get_cap(caps, name) name_with_prefix = "#{::Appium::Core::Base::Bridge::APPIUM_PREFIX}#{name}" caps[convert_to_symbol name] || caps[name] || caps[convert_to_symbol name_with_prefix] || caps[name_with_prefix] end |
Instance Method Details
#action ⇒ Selenium::WebDriver::PointerActions
An entry point to chain W3C actions Read www.rubydoc.info/github/appium/ruby_lib_core/Appium/Core/Base/Bridge/W3C#action-instance_method
374 375 376 |
# File 'lib/appium_lib/driver.rb', line 374 def action @driver&.action end |
#appium_client_version ⇒ Hash
Returns the client’s version info
417 418 419 |
# File 'lib/appium_lib/driver.rb', line 417 def appium_client_version { version: ::Appium::VERSION } end |
#appium_server_version ⇒ Hash Also known as: remote_status
Returns the server’s version info
389 390 391 392 393 394 395 396 |
# File 'lib/appium_lib/driver.rb', line 389 def appium_server_version @core.appium_server_version rescue Selenium::WebDriver::Error::WebDriverError => ex raise ::Appium::Core::Error::ServerError unless ex..include?('content-type=""') # server (TestObject for instance) does not respond to status call {} end |
#automation_name_is_espresso? ⇒ Boolean
Return true if automationName is ‘Espresso’
354 355 356 |
# File 'lib/appium_lib/driver.rb', line 354 def automation_name_is_espresso? !@core.automation_name.nil? && @core.automation_name == :espresso end |
#automation_name_is_uiautomator2? ⇒ Boolean
Return true if automationName is ‘uiautomator2’
348 349 350 |
# File 'lib/appium_lib/driver.rb', line 348 def automation_name_is_uiautomator2? !@core.automation_name.nil? && @core.automation_name == :uiautomator2 end |
#automation_name_is_xcuitest? ⇒ Boolean
Return true if automationName is ‘XCUITest’
360 361 362 |
# File 'lib/appium_lib/driver.rb', line 360 def automation_name_is_xcuitest? !@core.automation_name.nil? && @core.automation_name == :xcuitest end |
#current_url ⇒ Object
748 749 750 751 752 |
# File 'lib/appium_lib/driver.rb', line 748 def current_url raise NoDriverInstanceError if @driver.nil? @driver.current_url end |
#device_is_android? ⇒ Boolean
334 335 336 |
# File 'lib/appium_lib/driver.rb', line 334 def device_is_android? @core.device == :android end |
#device_is_ios? ⇒ Boolean
338 339 340 |
# File 'lib/appium_lib/driver.rb', line 338 def device_is_ios? @core.device == :ios end |
#device_is_windows? ⇒ Boolean
342 343 344 |
# File 'lib/appium_lib/driver.rb', line 342 def device_is_windows? @core.device == :windows end |
#driver_attributes ⇒ Object
Returns a hash of the driver attributes
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 |
# File 'lib/appium_lib/driver.rb', line 316 def driver_attributes { caps: @core.caps, automation_name: @core.automation_name, custom_url: @core.custom_url, default_wait: @default_wait, sauce_username: @sauce.username, sauce_access_key: @sauce.access_key, sauce_endpoint: @sauce.endpoint, port: @core.port, device: @core.device, debug: @appium_debug, listener: @listener, wait_timeout: @core.wait_timeout, wait_interval: @core.wait_interval } end |
#driver_quit ⇒ void Also known as: quit_driver
This method returns an undefined value.
Quits the driver
496 497 498 499 500 501 |
# File 'lib/appium_lib/driver.rb', line 496 def driver_quit @driver&.quit @driver = nil rescue Selenium::WebDriver::Error::WebDriverError nil end |
#element_screenshot(element, png_save_path) ⇒ File
Takes a png screenshot of particular element’s area
489 490 491 492 |
# File 'lib/appium_lib/driver.rb', line 489 def element_screenshot(element, png_save_path) @driver&.take_element_screenshot element, png_save_path nil end |
#execute_async_script(script, *args) ⇒ Object
Wrap calling selenium webdrier APIs via ruby_core
Get the window handles of open browser windows
677 678 679 680 681 |
# File 'lib/appium_lib/driver.rb', line 677 def execute_async_script(script, *args) raise NoDriverInstanceError if @driver.nil? @driver.execute_async_script script, *args end |
#execute_driver(script: '', type: 'webdriverio', timeout_ms: nil) ⇒ Appium::Core::Base::Device::ExecuteDriver::Result
Run a set of script against the current session, allowing execution of many commands in one Appium request. Supports WebdriverIO API so far. Please read command API for more details about acceptable scripts and the output.
711 712 713 714 715 |
# File 'lib/appium_lib/driver.rb', line 711 def execute_driver(script: '', type: 'webdriverio', timeout_ms: nil) raise NoDriverInstanceError if @driver.nil? @driver.execute_driver(script: script, type: type, timeout_ms: timeout_ms) end |
#execute_script(script, *args) ⇒ Object
The same as @driver.execute_script
667 668 669 670 671 |
# File 'lib/appium_lib/driver.rb', line 667 def execute_script(script, *args) raise NoDriverInstanceError if @driver.nil? @driver.execute_script script, *args end |
#exists(pre_check = 0, post_check = @default_wait) { ... } ⇒ Boolean
Returns existence of element.
Example:
exists { button(‘sign in’) } ? puts(‘true’) : puts(‘false’)
643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 |
# File 'lib/appium_lib/driver.rb', line 643 def exists(pre_check = 0, post_check = @default_wait) # do not uset set_wait here. # it will cause problems with other methods reading the default_wait of 0 # which then gets converted to a 1 second wait. @driver&.manage&.timeouts&.implicit_wait = pre_check # the element exists unless an error is raised. exists = true begin yield # search for element rescue StandardError exists = false # error means it's not there end # restore wait @driver&.manage&.timeouts&.implicit_wait = post_check if post_check != pre_check exists end |
#find_element(*args) ⇒ Element
Calls @driver.find_element
If you call ‘Appium.promote_appium_methods`, you can call `find_element` directly.
809 810 811 812 813 |
# File 'lib/appium_lib/driver.rb', line 809 def find_element(*args) raise NoDriverInstanceError if @driver.nil? @driver.find_element(*args) end |
#find_element_by_image(png_img_path) ⇒ ::Appium::Core::ImageElement
Return ImageElement if current view has a partial image
826 827 828 829 830 |
# File 'lib/appium_lib/driver.rb', line 826 def find_element_by_image(png_img_path) raise NoDriverInstanceError if @driver.nil? @driver.find_element_by_image(png_img_path) end |
#find_elements(*args) ⇒ Array<Element>
Calls @driver.find_elements_with_appium
If you call ‘Appium.promote_appium_methods`, you can call `find_elements` directly.
If you call ‘Appium.promote_appium_methods`, you can call `find_elements` directly.
791 792 793 794 795 |
# File 'lib/appium_lib/driver.rb', line 791 def find_elements(*args) raise NoDriverInstanceError if @driver.nil? @driver.find_elements(*args) end |
#find_elements_by_image(png_img_paths) ⇒ [::Appium::Core::ImageElement], ::Appium::Core::Error::CoreError
Return ImageElement if current view has partial images
843 844 845 846 847 |
# File 'lib/appium_lib/driver.rb', line 843 def find_elements_by_image(png_img_paths) raise NoDriverInstanceError if @driver.nil? @driver.find_elements_by_image(png_img_paths) end |
#get(url) ⇒ Object
742 743 744 745 746 |
# File 'lib/appium_lib/driver.rb', line 742 def get(url) raise NoDriverInstanceError if @driver.nil? @driver.get(url) end |
#log_event(vendor:, event:) ⇒ nil
Logs a custom event. The event is available via Core::Events#get.
883 884 885 886 887 |
# File 'lib/appium_lib/driver.rb', line 883 def log_event(vendor:, event:) raise NoDriverInstanceError if @driver.nil? @driver.logs.event vendor: vendor, event: event end |
#log_event=(log_event) ⇒ Object
889 890 891 892 893 894 895 896 |
# File 'lib/appium_lib/driver.rb', line 889 def log_event=(log_event) raise if @driver.nil? unless log_event.is_a?(Hash) raise ::Appium::Core::Error::ArgumentError('log_event should be Hash like { vendor: "appium", event: "funEvent"}') end @driver.logs.event vendor: log_event[:vendor], event: log_event[:event] end |
#log_events(type = nil) ⇒ Hash
Returns events with filtering with ‘type’. Defaults to all available events.
909 910 911 912 913 |
# File 'lib/appium_lib/driver.rb', line 909 def log_events(type = nil) raise NoDriverInstanceError if @driver.nil? @driver.logs.events(type) end |
#manage ⇒ Object
736 737 738 739 740 |
# File 'lib/appium_lib/driver.rb', line 736 def manage raise NoDriverInstanceError if @driver.nil? @driver.manage end |
#navigate ⇒ Object
730 731 732 733 734 |
# File 'lib/appium_lib/driver.rb', line 730 def navigate raise NoDriverInstanceError if @driver.nil? @driver.navigate end |
#no_wait ⇒ Object
Set implicit wait to zero.
612 613 614 |
# File 'lib/appium_lib/driver.rb', line 612 def no_wait @driver&.manage&.timeouts&.implicit_wait = 0 end |
#platform_version ⇒ Array<Integer>
Return the platform version as an array of integers
401 402 403 404 405 406 |
# File 'lib/appium_lib/driver.rb', line 401 def platform_version return [] if @driver.nil? p_version = @driver.capabilities['platformVersion'] p_version.split('.').map(&:to_i) end |
#restart ⇒ Driver
Restarts the driver
462 463 464 465 |
# File 'lib/appium_lib/driver.rb', line 462 def restart driver_quit start_driver end |
#screenshot(png_save_path) ⇒ File
Takes a png screenshot and saves to the target path.
475 476 477 |
# File 'lib/appium_lib/driver.rb', line 475 def screenshot(png_save_path) @driver&.save_screenshot png_save_path end |
#server_url ⇒ String
Get the server url
453 454 455 456 457 458 |
# File 'lib/appium_lib/driver.rb', line 453 def server_url return @core.custom_url if @core.custom_url return @sauce.server_url if @sauce.sauce_server_url? "http://127.0.0.1:#{@core.port}" end |
#set_implicit_wait(wait) ⇒ Object
To ignore error for Espresso Driver
601 602 603 604 605 606 607 608 609 |
# File 'lib/appium_lib/driver.rb', line 601 def set_implicit_wait(wait) @driver.manage.timeouts.implicit_wait = wait rescue Selenium::WebDriver::Error::UnknownError => e unless e..include?('The operation requested is not yet implemented by Espresso driver') raise ::Appium::Core::Error::ServerError end {} end |
#set_location(opts = {}) ⇒ Selenium::WebDriver::Location
This method does not work on real devices.
Calls @driver.set_location
858 859 860 861 862 863 864 865 |
# File 'lib/appium_lib/driver.rb', line 858 def set_location(opts = {}) raise NoDriverInstanceError if @driver.nil? latitude = opts.fetch(:latitude) longitude = opts.fetch(:longitude) altitude = opts.fetch(:altitude, 75) @driver.set_location(latitude, longitude, altitude) end |
#set_wait(timeout = nil) ⇒ void
This method returns an undefined value.
Set implicit wait. Default to @default_wait.
626 627 628 629 |
# File 'lib/appium_lib/driver.rb', line 626 def set_wait(timeout = nil) timeout = @default_wait if timeout.nil? @driver&.manage&.timeouts&.implicit_wait = timeout end |
#start_driver(http_client_ops = { http_client: nil, open_timeout: 999_999, read_timeout: 999_999 }) ⇒ Selenium::WebDriver
Creates a new global driver and quits the old one if it exists. You can customise http_client as the following
Read www.rubydoc.info/github/appium/ruby_lib_core/Appium/Core/Device to understand more what the driver can call instance methods.
566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 |
# File 'lib/appium_lib/driver.rb', line 566 def start_driver(http_client_ops = { http_client: nil, open_timeout: 999_999, read_timeout: 999_999 }) if http_client_ops[:http_client].nil? http_client = ::Appium::Http::Default.new(open_timeout: http_client_ops[:open_timeout], read_timeout: http_client_ops[:read_timeout]) end # TODO: do not kill the previous session in the future version. if $driver.nil? driver_quit else $driver.driver_quit end # If automationName is set only in server side, then the following automation_name should be nil before # starting driver. automation_name = @core.automation_name @driver = @core.start_driver(server_url: server_url, http_client_ops: { http_client: http_client, open_timeout: 999_999, read_timeout: 999_999 }) @http_client = @core.http_client # if automation_name was nil before start_driver, then re-extend driver specific methods # to be able to extend correctly. extend_for(device: @core.device, automation_name: @core.automation_name) if automation_name.nil? @appium_server_status = appium_server_version @driver end |
#switch_to ⇒ TargetLocator
762 763 764 765 766 |
# File 'lib/appium_lib/driver.rb', line 762 def switch_to raise NoDriverInstanceError if @driver.nil? @driver.switch_to end |
#title ⇒ Object
754 755 756 757 758 |
# File 'lib/appium_lib/driver.rb', line 754 def title raise NoDriverInstanceError if @driver.nil? @driver.title end |
#window_handle ⇒ Object
Get the current window handle
724 725 726 727 728 |
# File 'lib/appium_lib/driver.rb', line 724 def window_handle raise NoDriverInstanceError if @driver.nil? @driver.window_handle end |
#window_handles ⇒ Object
717 718 719 720 721 |
# File 'lib/appium_lib/driver.rb', line 717 def window_handles raise NoDriverInstanceError if @driver.nil? @driver.window_handles end |
#window_rect ⇒ Selenium::WebDriver::Rectangle
Get the device window’s rect.
531 532 533 534 535 |
# File 'lib/appium_lib/driver.rb', line 531 def window_rect raise NoDriverInstanceError if @driver.nil? @driver.window_rect end |
#window_size ⇒ Selenium::WebDriver::Dimension
Get the device window’s size.
513 514 515 516 517 518 |
# File 'lib/appium_lib/driver.rb', line 513 def window_size # maybe exception is expected as no driver created raise NoDriverInstanceError if @driver.nil? @driver.window_size end |
#x ⇒ void
This method returns an undefined value.
Quit the driver and Pry. quit and exit are reserved by Pry.
918 919 920 921 |
# File 'lib/appium_lib/driver.rb', line 918 def x driver_quit exit # exit pry end |