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 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
-
#enable_idempotency_header ⇒ Bool
readonly
Return if adding ‘x-idempotency-key’ header is enabled for each new session request.
-
#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
-
.attach_to(session_id, url: nil, automation_name: nil, platform_name: nil, http_client_ops: { http_client: nil, open_timeout: 999_999, read_timeout: 999_999 }) ⇒ Selenium::WebDriver
Attach to an existing session.
-
.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.
-
#attach_to(session_id, url: nil, automation_name: nil, platform_name: nil, http_client_ops: { http_client: nil, open_timeout: 999_999, read_timeout: 999_999 }) ⇒ Object
Attach to an existing session.
- #get_http_client(http_client: nil, open_timeout: nil, read_timeout: nil) ⇒ Object
-
#quit_driver ⇒ void
- Deprecated
-
Quits the driver.
-
#set_implicit_wait_by_default(wait) ⇒ Object
Ignore setting default wait if the target driver has no implementation.
-
#setup_for_new_session(opts = {}) ⇒ Object
Set up for a new session.
-
#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
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.
129 130 131 |
# File 'lib/appium_lib_core/driver.rb', line 129 def automation_name @automation_name end |
#caps ⇒ Core::Base::Capabilities (readonly)
Selenium webdriver capabilities
109 110 111 |
# File 'lib/appium_lib_core/driver.rb', line 109 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
.
134 135 136 |
# File 'lib/appium_lib_core/driver.rb', line 134 def custom_url @custom_url end |
#default_wait ⇒ Integer (readonly)
Default wait time for elements to appear in Appium server side. Provide { appium_lib: { wait: 30 } }
to Appium::Core.for
139 140 141 |
# File 'lib/appium_lib_core/driver.rb', line 139 def default_wait @default_wait end |
#device ⇒ Symbol (readonly)
Device type to request from the appium server
124 125 126 |
# File 'lib/appium_lib_core/driver.rb', line 124 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:
-
directConnectProtocol
-
directConnectHost
-
directConnectPort
-
directConnectPath
ignore them if this parameter is false
. Defaults to true. These keys can have appium:
prefix.
181 182 183 |
# File 'lib/appium_lib_core/driver.rb', line 181 def direct_connect @direct_connect end |
#driver ⇒ Appium::Core::Base::Driver (readonly)
165 166 167 |
# File 'lib/appium_lib_core/driver.rb', line 165 def driver @driver end |
#enable_idempotency_header ⇒ Bool (readonly)
Return if adding ‘x-idempotency-key’ header is enabled for each new session request. Following commands should not have the key. The key is unique for each http client instance. Defaults to true
github.com/appium/appium-base-driver/pull/400
120 121 122 |
# File 'lib/appium_lib_core/driver.rb', line 120 def enable_idempotency_header @enable_idempotency_header end |
#http_client ⇒ Appium::Core::Base::Http::Default (readonly)
Return http client called in start_driver()
113 114 115 |
# File 'lib/appium_lib_core/driver.rb', line 113 def http_client @http_client end |
#listener ⇒ Object (readonly)
instance of AbstractEventListener for logging support Nil by default
162 163 164 |
# File 'lib/appium_lib_core/driver.rb', line 162 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.
145 146 147 |
# File 'lib/appium_lib_core/driver.rb', line 145 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.
158 159 160 |
# File 'lib/appium_lib_core/driver.rb', line 158 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.
152 153 154 |
# File 'lib/appium_lib_core/driver.rb', line 152 def wait_timeout @wait_timeout end |
Class Method Details
.attach_to(session_id, url: nil, automation_name: nil, platform_name: nil, http_client_ops: { http_client: nil, open_timeout: 999_999, read_timeout: 999_999 }) ⇒ Selenium::WebDriver
Attach to an existing session. The main usage of this method is to attach to an existing session for debugging. The generated driver instance has the capabilities which has the given automationName and platformName only since the W3C WebDriver spec does not provide an endpoint to get running session’s capabilities.
307 308 309 310 311 312 313 314 315 316 317 318 |
# File 'lib/appium_lib_core/driver.rb', line 307 def self.attach_to( session_id, url: nil, automation_name: nil, platform_name: nil, http_client_ops: { http_client: nil, open_timeout: 999_999, read_timeout: 999_999 } ) new.attach_to( session_id, automation_name: automation_name, platform_name: platform_name, url: url, http_client_ops: http_client_ops ) end |
.for(opts = {}) ⇒ Driver
Creates a new driver and extend particular methods
283 284 285 |
# File 'lib/appium_lib_core/driver.rb', line 283 def self.for(opts = {}) new.setup_for_new_session(opts) end |
Instance Method Details
#appium_server_version ⇒ Hash
Returns the server’s version info. This method calls driver.remote_status
internally
Returns blank hash in a case driver.remote_status
got an error such as Selenium Grid. It returns 500 error against ‘remote_status’.
536 537 538 539 540 541 542 543 544 |
# File 'lib/appium_lib_core/driver.rb', line 536 def appium_server_version return {} if @driver.nil? @driver.remote_status rescue StandardError # Ignore error case in a case the target appium server # does not support `/status` API. {} end |
#attach_to(session_id, url: nil, automation_name: nil, platform_name: nil, http_client_ops: { http_client: nil, open_timeout: 999_999, read_timeout: 999_999 }) ⇒ Object
Attach to an existing session
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 |
# File 'lib/appium_lib_core/driver.rb', line 445 def attach_to(session_id, url: nil, automation_name: nil, platform_name: nil, http_client_ops: { http_client: nil, open_timeout: 999_999, read_timeout: 999_999 }) raise ::Appium::Core::Error::ArgumentError, 'The :url must not be nil' if url.nil? raise ::Appium::Core::Error::ArgumentError, 'The :automation_name must not be nil' if automation_name.nil? raise ::Appium::Core::Error::ArgumentError, 'The :platform_name must not be nil' if platform_name.nil? @custom_url = url # use lowercase internally @automation_name = convert_downcase(automation_name) @device = convert_downcase(platform_name) extend_for(device: @device, automation_name: @automation_name) @http_client = get_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) # Note that 'enable_idempotency_header' works only a new session reqeust. The attach_to method skips # the new session request, this it does not needed. 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, url: @custom_url, listener: @listener, existing_session_id: session_id, automation_name: automation_name, platform_name: platform_name) rescue Errno::ECONNREFUSED raise "ERROR: Unable to connect to Appium. Is the server running on #{@custom_url}?" end @driver end |
#get_http_client(http_client: nil, open_timeout: nil, read_timeout: nil) ⇒ Object
482 483 484 |
# File 'lib/appium_lib_core/driver.rb', line 482 def get_http_client(http_client: nil, open_timeout: nil, read_timeout: nil) http_client || Appium::Core::Base::Http::Default.new(open_timeout: open_timeout, read_timeout: read_timeout) end |
#quit_driver ⇒ void
This method returns an undefined value.
- Deprecated
-
Quits the driver. This method is the same as @driver.quit
507 508 509 510 511 512 |
# File 'lib/appium_lib_core/driver.rb', line 507 def quit_driver ::Appium::Logger.warn('[DEPRECATION] quit_driver will be removed. Please use @driver.quit instead.') @driver.quit rescue # rubocop:disable Style/RescueStandardError nil end |
#set_implicit_wait_by_default(wait) ⇒ Object
Ignore setting default wait if the target driver has no implementation
487 488 489 490 491 492 493 494 495 496 497 498 |
# File 'lib/appium_lib_core/driver.rb', line 487 def set_implicit_wait_by_default(wait) return if @default_wait.nil? @driver.manage.timeouts.implicit_wait = wait rescue ::Selenium::WebDriver::Error::UnknownError => e unless e..include?('The operation requested is not yet implemented') raise ::Appium::Core::Error::ServerError, e. end ::Appium::Logger.debug(e.) {} end |
#setup_for_new_session(opts = {}) ⇒ Object
Set up for a new session
338 339 340 341 342 343 344 345 346 347 348 349 350 |
# File 'lib/appium_lib_core/driver.rb', line 338 def setup_for_new_session(opts = {}) @custom_url = opts.delete :url # to set the custom url as :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 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
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 |
# File 'lib/appium_lib_core/driver.rb', line 395 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" @http_client = get_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) if @enable_idempotency_header if @http_client.instance_variable_defined? :@additional_headers @http_client.set_additional_header Appium::Core::Base::Http::RequestHeaders::KEYS[:idempotency], SecureRandom.uuid else ::Appium::Logger.warn 'No additional_headers attribute in this http client instance' end end begin @driver = ::Appium::Core::Base::Driver.new(listener: @listener, http_client: @http_client, capabilities: @caps, # ::Appium::Core::Base::Capabilities url: @custom_url, wait_timeout: @wait_timeout, wait_interval: @wait_interval) 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 rescue Errno::ECONNREFUSED raise "ERROR: Unable to connect to Appium. Is the server running on #{@custom_url}?" end if @http_client.instance_variable_defined? :@additional_headers # We only need the key for a new session request. Should remove it for other following commands. @http_client.delete_additional_header Appium::Core::Base::Http::RequestHeaders::KEYS[:idempotency] end # TODO: this method can be removed after releasing Appium 2.0, and after a while # since Appium 2.0 reuqires 'automationName'. This method won't help anymore then. # 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 |