Class: Appium::Core::Driver
- Inherits:
-
Object
- Object
- Appium::Core::Driver
- Includes:
- Waitable
- Defined in:
- lib/appium_lib_core/driver.rb
Constant Summary collapse
- DEFAULT_IMPLICIT_WAIT =
0- DEFAULT_APPIUM_PORT =
4723
Instance Attribute Summary collapse
-
#automation_name ⇒ Hash
readonly
Automation name sent to appium server or received by server.
If automation_name isnil, 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 in Appium server side.
-
#device ⇒ Symbol
readonly
Device type to request from the appium server.
-
#direct_connect ⇒ Bool
readonly
[Experimental feature]
Enable an experimental feature updating Http client endpoint following below keys by Appium/Selenium server.
This works with Base::Http::Default. - #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(opts = {}) ⇒ Driver
Creates a new driver and extend particular methods.
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(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(opts = {}) ⇒ Driver
Returns a new instance of Driver.
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
# File 'lib/appium_lib_core/driver.rb', line 276 def initialize(opts = {}) @delegate_target = self # for testing purpose @automation_name = nil # initialise before 'set_automation_name' opts = Appium.symbolize_keys opts validate_keys(opts) @custom_url = opts.delete :url @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) self # rubocop:disable Lint/Void end |
Instance Attribute Details
#automation_name ⇒ Hash (readonly)
Automation name sent to appium server or received by server.
If automation_name is nil, it is not set both client side and server side.
112 113 114 |
# File 'lib/appium_lib_core/driver.rb', line 112 def automation_name @automation_name end |
#caps ⇒ Core::Base::Capabilities (readonly)
Selenium webdriver capabilities
99 100 101 |
# File 'lib/appium_lib_core/driver.rb', line 99 def caps @caps end |
#custom_url ⇒ String (readonly)
Custom URL for the selenium server. If set this attribute, ruby_lib_core try to handshake to the custom url.
Defaults to false. Then try to connect to http://127.0.0.1:#{port}/wd/hub.
117 118 119 |
# File 'lib/appium_lib_core/driver.rb', line 117 def custom_url @custom_url end |
#default_wait ⇒ Integer (readonly)
Default wait time for elements to appear in Appium server side.
Defaults to DEFAULT_IMPLICIT_WAIT.
Provide { appium_lib: { wait: 30 } } to Appium::Core.for
129 130 131 |
# File 'lib/appium_lib_core/driver.rb', line 129 def default_wait @default_wait end |
#device ⇒ Symbol (readonly)
Device type to request from the appium server
107 108 109 |
# File 'lib/appium_lib_core/driver.rb', line 107 def device @device end |
#direct_connect ⇒ Bool (readonly)
[Experimental feature]
Enable an experimental feature updating Http client endpoint following below keys by Appium/Selenium server.
This works with Base::Http::Default.
If your Selenium/Appium server decorates the new session capabilities response with the following keys:
directConnectProtocoldirectConnectHostdirectConnectPortdirectConnectPath
Ignore them if this parameter is false. Defaults to false.
171 172 173 |
# File 'lib/appium_lib_core/driver.rb', line 171 def direct_connect @direct_connect end |
#driver ⇒ Appium::Core::Base::Driver (readonly)
156 157 158 |
# File 'lib/appium_lib_core/driver.rb', line 156 def driver @driver end |
#export_session ⇒ Boolean (readonly)
Export session id to textfile in /tmp for 3rd party tools. False bu default.
121 122 123 |
# File 'lib/appium_lib_core/driver.rb', line 121 def export_session @export_session end |
#export_session_path ⇒ String (readonly)
Returns By default, session id is exported in '/tmp/appium_lib_session'.
123 124 125 |
# File 'lib/appium_lib_core/driver.rb', line 123 def export_session_path @export_session_path end |
#http_client ⇒ Appium::Core::Base::Http::Default (readonly)
Return http client called in start_driver()
103 104 105 |
# File 'lib/appium_lib_core/driver.rb', line 103 def http_client @http_client end |
#listener ⇒ Object (readonly)
instance of AbstractEventListener for logging support Nil by default
153 154 155 |
# File 'lib/appium_lib_core/driver.rb', line 153 def listener @listener end |
#port ⇒ Integer (readonly)
Appium's server port. 4723 is by default. Defaults to DEFAULT_APPIUM_PORT.
Provide { appium_lib: { port: 8080 } } to Appium::Core.for.
:custom_url is prior than :port if :custom_url is set.
136 137 138 |
# File 'lib/appium_lib_core/driver.rb', line 136 def port @port end |
#wait_interval ⇒ Integer (readonly)
Return a time to wait interval. 0.5 seconds is by default Wait::DEFAULT_INTERVAL.
Wait interval time for Base::Wait, wait and wait_true.
Provide { appium_lib: { wait_interval: 0.1 } } to Appium::Core.for.
149 150 151 |
# File 'lib/appium_lib_core/driver.rb', line 149 def wait_interval @wait_interval end |
#wait_timeout ⇒ Integer (readonly)
Return a time wait timeout. 30 seconds is by default Wait::DEFAULT_TIMEOUT.
Wait time for Base::Wait, wait and wait_true.
Provide { appium_lib: { wait_timeout: 20 } } to Appium::Core.for.
143 144 145 |
# File 'lib/appium_lib_core/driver.rb', line 143 def wait_timeout @wait_timeout end |
Class Method Details
.for(opts = {}) ⇒ Driver
Creates a new driver and extend particular methods
261 262 263 |
# File 'lib/appium_lib_core/driver.rb', line 261 def self.for(opts = {}) new(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
431 432 433 434 435 436 437 438 |
# File 'lib/appium_lib_core/driver.rb', line 431 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
447 448 449 450 |
# File 'lib/appium_lib_core/driver.rb', line 447 def platform_version p_version = @driver.capabilities['platformVersion'] || @driver.session_capabilities['platformVersion'] p_version.split('.').map(&:to_i) end |
#quit_driver ⇒ void
This method returns an undefined value.
Quits the driver
405 406 407 408 409 |
# File 'lib/appium_lib_core/driver.rb', line 405 def quit_driver @driver.quit rescue # rubocop:disable Style/RescueStandardError nil end |
#screenshot(png_save_path) ⇒ File
Takes a png screenshot and saves to the target path.
462 463 464 465 |
# File 'lib/appium_lib_core/driver.rb', line 462 def screenshot(png_save_path) ::Appium::Logger.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
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 |
# File 'lib/appium_lib_core/driver.rb', line 339 def start_driver(server_url: nil, http_client_ops: { http_client: nil, open_timeout: 999_999, read_timeout: 999_999 }) @custom_url ||= server_url || "http://127.0.0.1:#{@port}/wd/hub" create_http_client http_client: http_client_ops.delete(:http_client), open_timeout: http_client_ops.delete(:open_timeout), read_timeout: http_client_ops.delete(: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: @custom_url, listener: @listener) if @direct_connect d_c = DirectConnections.new(@driver.capabilities) @driver.update_sending_request_to(protocol: d_c.protocol, host: d_c.host, port: d_c.port, path: d_c.path) end # 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 #{@custom_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 |