Class: Appium::Core::Driver
- Inherits:
-
Object
- Object
- Appium::Core::Driver
- Includes:
- Waitable
- Defined in:
- lib/appium_lib_core/driver.rb
Constant Summary collapse
- DEFAULT_APPIUM_PORT =
4723
Instance Attribute Summary collapse
-
#automation_name ⇒ Hash
readonly
Automation name sent to appium server or received from server If automation_name is nil, it is not set both client side and server side.
-
#caps ⇒ Core::Base::Capabilities
readonly
Selenium webdriver capabilities.
-
#custom_url ⇒ String
readonly
Custom URL for the selenium server.
-
#default_wait ⇒ Integer
readonly
Default wait time for elements to appear Returns the default client side wait.
-
#device ⇒ Symbol
readonly
Device type to request from the appium server.
- #driver ⇒ Appium::Core::Base::Driver readonly
-
#export_session ⇒ Boolean
readonly
Export session id to textfile in /tmp for 3rd party tools.
-
#export_session_path ⇒ String
readonly
By default, session id is exported in ‘/tmp/appium_lib_session’.
-
#http_client ⇒ Appium::Core::Base::Http::Default
readonly
Return http client called in start_driver().
-
#listener ⇒ Object
readonly
instance of AbstractEventListener for logging support Nil by default.
-
#port ⇒ Integer
readonly
Appium’s server port.
-
#wait_interval ⇒ Integer
readonly
Return a time to wait interval.
-
#wait_timeout ⇒ Integer
readonly
Return a time wait timeout.
Class Method Summary collapse
-
.for(target, opts = {}) ⇒ Driver
Creates a new global driver and extend particular methods to ‘target`.
Instance Method Summary collapse
-
#appium_server_version ⇒ Hash
Returns the server’s version info Returns blank hash for Selenium Grid since ‘remote_status` gets 500 error.
-
#initialize(target, opts = {}) ⇒ Driver
constructor
A new instance of Driver.
-
#platform_version ⇒ Array<Integer>
Return the platform version as an array of integers.
-
#quit_driver ⇒ void
Quits the driver.
-
#screenshot(png_save_path) ⇒ File
Takes a png screenshot and saves to the target path.
-
#start_driver(server_url: nil, 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.
Methods included from Waitable
Constructor Details
#initialize(target, opts = {}) ⇒ Driver
Returns a new instance of Driver.
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/appium_lib_core/driver.rb', line 101 def initialize(target, opts = {}) opts = Appium.symbolize_keys opts validate_keys(opts) @caps = get_caps(opts) set_appium_lib_specific_values(get_appium_lib_opts(opts)) set_app_path set_appium_device set_automation_name extend_for(device: @device, automation_name: @automation_name, target: target) self # rubocop:disable Lint/Void end |
Instance Attribute Details
#automation_name ⇒ Hash (readonly)
Automation name sent to appium server or received from server If automation_name is nil, it is not set both client side and server side.
20 21 22 |
# File 'lib/appium_lib_core/driver.rb', line 20 def automation_name @automation_name end |
#caps ⇒ Core::Base::Capabilities (readonly)
Selenium webdriver capabilities
7 8 9 |
# File 'lib/appium_lib_core/driver.rb', line 7 def caps @caps end |
#custom_url ⇒ String (readonly)
25 26 27 |
# File 'lib/appium_lib_core/driver.rb', line 25 def custom_url @custom_url end |
#default_wait ⇒ Integer (readonly)
Default wait time for elements to appear Returns the default client side wait. 20 seconds is by default. Provide Appium::Drive like { appium_lib: { wait: 30 } }
37 38 39 |
# File 'lib/appium_lib_core/driver.rb', line 37 def default_wait @default_wait end |
#device ⇒ Symbol (readonly)
Device type to request from the appium server
15 16 17 |
# File 'lib/appium_lib_core/driver.rb', line 15 def device @device end |
#driver ⇒ Appium::Core::Base::Driver (readonly)
62 63 64 |
# File 'lib/appium_lib_core/driver.rb', line 62 def driver @driver end |
#export_session ⇒ Boolean (readonly)
Export session id to textfile in /tmp for 3rd party tools. False bu default.
29 30 31 |
# File 'lib/appium_lib_core/driver.rb', line 29 def export_session @export_session end |
#export_session_path ⇒ String (readonly)
Returns By default, session id is exported in ‘/tmp/appium_lib_session’.
31 32 33 |
# File 'lib/appium_lib_core/driver.rb', line 31 def export_session_path @export_session_path end |
#http_client ⇒ Appium::Core::Base::Http::Default (readonly)
Return http client called in start_driver()
11 12 13 |
# File 'lib/appium_lib_core/driver.rb', line 11 def http_client @http_client end |
#listener ⇒ Object (readonly)
instance of AbstractEventListener for logging support Nil by default
59 60 61 |
# File 'lib/appium_lib_core/driver.rb', line 59 def listener @listener end |
#port ⇒ Integer (readonly)
Appium’s server port. 4723 is by default. Provide Appium::Drive like { appium_lib: { port: 8080 } }
42 43 44 |
# File 'lib/appium_lib_core/driver.rb', line 42 def port @port end |
#wait_interval ⇒ Integer (readonly)
Return a time to wait interval. 0.5 seconds is by default. Wait interval time for ::Appium::Core::Base::Wait, wait and wait_true Provide Appium::Drive like { appium_lib: { wait_interval: 0.1 } }
55 56 57 |
# File 'lib/appium_lib_core/driver.rb', line 55 def wait_interval @wait_interval end |
#wait_timeout ⇒ Integer (readonly)
Return a time wait timeout. 30 seconds is by default. Wait time for ::Appium::Core::Base::Wait, wait and wait_true Provide Appium::Drive like { appium_lib: { wait_timeout: 20 } }
49 50 51 |
# File 'lib/appium_lib_core/driver.rb', line 49 def wait_timeout @wait_timeout end |
Class Method Details
.for(target, opts = {}) ⇒ Driver
Creates a new global driver and extend particular methods to ‘target`
96 97 98 |
# File 'lib/appium_lib_core/driver.rb', line 96 def self.for(target, opts = {}) new(target, opts) end |
Instance Method Details
#appium_server_version ⇒ Hash
Returns the server’s version info Returns blank hash for Selenium Grid since ‘remote_status` gets 500 error
247 248 249 250 251 252 253 |
# File 'lib/appium_lib_core/driver.rb', line 247 def appium_server_version @driver.remote_status rescue Selenium::WebDriver::Error::ServerError => e raise ::Appium::Core::Error::ServerError unless e..include?('status code 500') # driver.remote_status returns 500 error for using selenium grid {} end |
#platform_version ⇒ Array<Integer>
Return the platform version as an array of integers
262 263 264 265 |
# File 'lib/appium_lib_core/driver.rb', line 262 def platform_version p_version = @driver.capabilities['platformVersion'] p_version.split('.').map(&:to_i) end |
#quit_driver ⇒ void
This method returns an undefined value.
Quits the driver
222 223 224 225 226 |
# File 'lib/appium_lib_core/driver.rb', line 222 def quit_driver @driver.quit rescue # rubocop:disable Lint/RescueWithoutErrorClass nil end |
#screenshot(png_save_path) ⇒ File
Takes a png screenshot and saves to the target path.
277 278 279 280 |
# File 'lib/appium_lib_core/driver.rb', line 277 def screenshot(png_save_path) warn '[DEPRECATION] screenshot will be removed. Please use driver.save_screenshot instead.' @driver.save_screenshot png_save_path end |
#start_driver(server_url: nil, 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
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/appium_lib_core/driver.rb', line 154 def start_driver(server_url: nil, http_client_ops: { http_client: nil, open_timeout: 999_999, read_timeout: 999_999 }) server_url ||= "http://127.0.0.1:#{@port}/wd/hub" # open_timeout and read_timeout are explicit wait. open_timeout = http_client_ops.delete(:open_timeout) read_timeout = http_client_ops.delete(:read_timeout) http_client = http_client_ops.delete(:http_client) @http_client ||= http_client ? http_client : Appium::Core::Base::Http::Default.new @http_client.open_timeout = open_timeout if open_timeout @http_client.read_timeout = read_timeout if read_timeout begin # included https://github.com/SeleniumHQ/selenium/blob/43f8b3f66e7e01124eff6a5805269ee441f65707/rb/lib/selenium/webdriver/remote/driver.rb#L29 @driver = ::Appium::Core::Base::Driver.new(http_client: @http_client, desired_capabilities: @caps, url: server_url, listener: @listener) # export session write_session_id(@driver.session_id, @export_session_path) if @export_session rescue Errno::ECONNREFUSED raise "ERROR: Unable to connect to Appium. Is the server running on #{server_url}?" end # If "automationName" is set only server side, this method set "automationName" attribute into @automation_name. # Since @automation_name is set only client side before start_driver is called. set_automation_name_if_nil set_implicit_wait_by_default(@default_wait) @driver end |