Skip to content

Commit 4d20509

Browse files
authored
Separate appium lib (#194)
* tweak appium lib cap * update readme * update http client doc * fix typo
1 parent 4c5ff26 commit 4d20509

File tree

4 files changed

+69
-25
lines changed

4 files changed

+69
-25
lines changed

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ $ PARALLEL=1 bundle exec parallel_test test/functional/ios -n 2
9797
# shell 2
9898
$ ruby test.rb
9999
```
100+
101+
### Capabilities
102+
103+
Read [Appium/Core/Driver](https://www.rubydoc.info/github/appium/ruby_lib_core/Appium/Core/Driver) to catch up with available capabilities.
104+
Capabilities affect only ruby_lib is [Appium/Core/Options](https://www.rubydoc.info/github/appium/ruby_lib_core/Appium/Core/Options).
100105

101106
# Development
102107
- Demo app

lib/appium_lib_core/common/base/http_default.rb

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ class Default < Selenium::WebDriver::Remote::Http::Default
1212
"appium/ruby_lib_core/#{VERSION} (#{::Selenium::WebDriver::Remote::Http::Common::DEFAULT_HEADERS['User-Agent']})"
1313
}.freeze
1414

15-
# Update `server_url` to.
16-
# Set `@http` as nil to re-create http client for the server_url
17-
# @private
15+
# Update <code>server_url</code> provided when ruby_lib _core created a default http client.
16+
# Set <code>@http</code> as nil to re-create http client for the <code>server_url</code>
1817
#
1918
# @param [string] scheme A scheme to update server_url to
2019
# @param [string] host A host to update server_url to

lib/appium_lib_core/driver.rb

+61-21
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,41 @@ module Ios
1313
autoload :Xcuitest, 'appium_lib_core/ios_xcuitest'
1414
end
1515

16+
# This options affects only client side as <code>:appium_lib</code> key.<br>
17+
# Read {::Appium::Core::Driver} about each attribute
18+
class Options
19+
attr_reader :custom_url, :default_wait, :export_session, :export_session_path,
20+
:port, :wait_timeout, :wait_interval, :listener,
21+
:direct_connect
22+
23+
def initialize(appium_lib_opts)
24+
@custom_url = appium_lib_opts.fetch :server_url, nil
25+
@default_wait = appium_lib_opts.fetch :wait, Driver::DEFAULT_IMPLICIT_WAIT
26+
27+
# bump current session id into a particular file
28+
@export_session = appium_lib_opts.fetch :export_session, false
29+
@export_session_path = appium_lib_opts.fetch :export_session_path, default_tmp_appium_lib_session
30+
31+
@direct_connect = appium_lib_opts.fetch :direct_connect, false
32+
33+
@port = appium_lib_opts.fetch :port, Driver::DEFAULT_APPIUM_PORT
34+
35+
# timeout and interval used in ::Appium::Comm.wait/wait_true
36+
@wait_timeout = appium_lib_opts.fetch :wait_timeout, ::Appium::Core::Wait::DEFAULT_TIMEOUT
37+
@wait_interval = appium_lib_opts.fetch :wait_interval, ::Appium::Core::Wait::DEFAULT_INTERVAL
38+
39+
# to pass it in Selenium.new.
40+
# `listener = opts.delete(:listener)` is called in Selenium::Driver.new
41+
@listener = appium_lib_opts.fetch :listener, nil
42+
end
43+
44+
private
45+
46+
def default_tmp_appium_lib_session
47+
::Appium::Core::Base.platform.windows? ? 'C:\\\\Windows\\Temp\\appium_lib_session' : '/tmp/appium_lib_session'
48+
end
49+
end
50+
1651
class Driver
1752
include Waitable
1853
# Selenium webdriver capabilities
@@ -43,7 +78,8 @@ class Driver
4378
# @return [String] By default, session id is exported in '/tmp/appium_lib_session'
4479
attr_reader :export_session_path
4580

46-
# Default wait time for elements to appear in Appium server side. Defaults to {::Appium::Core::Driver::DEFAULT_IMPLICIT_WAIT}.<br>
81+
# Default wait time for elements to appear in Appium server side.
82+
# Defaults to {::Appium::Core::Driver::DEFAULT_IMPLICIT_WAIT}.<br>
4783
# Provide <code>{ appium_lib: { wait: 30 } }</code> to {::Appium::Core.for}
4884
# @return [Integer]
4985
attr_reader :default_wait
@@ -77,7 +113,9 @@ class Driver
77113

78114
# <b>[Experimental feature]</b><br>
79115
# Enable an experimental feature updating Http client endpoint following below keys by Appium/Selenium server.<br>
80-
# If your Selenium/Appium server decorates the new session capabilities response with the following keys:
116+
# This works with {Appium::Core::Base::Http::Default}.
117+
#
118+
# If your Selenium/Appium server decorates the new session capabilities response with the following keys:<br>
81119
# - <code>directConnectProtocol</code>
82120
# - <code>directConnectHost</code>
83121
# - <code>directConnectPort</code>
@@ -88,8 +126,15 @@ class Driver
88126
# @return [Bool]
89127
attr_reader :direct_connect
90128

91-
# Creates a new global driver and extend particular methods to <code>target</code>
129+
# Creates a new driver and extend particular methods
92130
# @param [Hash] opts A options include capabilities for the Appium Server and for the client.
131+
# @option opts [Hash] :caps Appium capabilities. Prior than :desired_capabilities
132+
# @option opts [Hash] :desired_capabilities The same as :caps.
133+
# This param is for compatibility with Selenium WebDriver format
134+
# @option opts [Appium::Core::Options] :appium_lib Capabilities affect only ruby client
135+
# @option opts [String] :url The same as :custom_url in :appium_lib.
136+
# This param is for compatibility with Selenium WebDriver format
137+
#
93138
# @return [Driver]
94139
#
95140
# @example
@@ -465,25 +510,25 @@ def set_app_path
465510
end
466511

467512
# @private
513+
# Below capabilities are set only for client side.
468514
def set_appium_lib_specific_values(appium_lib_opts)
469-
@custom_url ||= appium_lib_opts.fetch :server_url, nil
470-
@default_wait = appium_lib_opts.fetch :wait, DEFAULT_IMPLICIT_WAIT
515+
opts = Options.new appium_lib_opts
471516

472-
# bump current session id into a particular file
473-
@export_session = appium_lib_opts.fetch :export_session, false
474-
@export_session_path = appium_lib_opts.fetch :export_session_path, default_tmp_appium_lib_session
517+
@custom_url ||= opts.custom_url # Keep existence capability if it's already provided
475518

476-
@direct_connect = appium_lib_opts.fetch :direct_access, false
519+
@default_wait = opts.default_wait
477520

478-
@port = appium_lib_opts.fetch :port, DEFAULT_APPIUM_PORT
521+
@export_session = opts.export_session
522+
@export_session_path = opts.export_session_path
479523

480-
# timeout and interval used in ::Appium::Comm.wait/wait_true
481-
@wait_timeout = appium_lib_opts.fetch :wait_timeout, ::Appium::Core::Wait::DEFAULT_TIMEOUT
482-
@wait_interval = appium_lib_opts.fetch :wait_interval, ::Appium::Core::Wait::DEFAULT_INTERVAL
524+
@port = opts.port
483525

484-
# to pass it in Selenium.new.
485-
# `listener = opts.delete(:listener)` is called in Selenium::Driver.new
486-
@listener = appium_lib_opts.fetch :listener, nil
526+
@wait_timeout = opts.wait_timeout
527+
@wait_interval = opts.wait_interval
528+
529+
@listener = opts.listener
530+
531+
@direct_connect = opts.direct_connect
487532
end
488533

489534
# @private
@@ -512,11 +557,6 @@ def set_automation_name_if_nil
512557
end
513558
end
514559

515-
# @private
516-
def default_tmp_appium_lib_session
517-
::Appium::Core::Base.platform.windows? ? 'C:\\\\Windows\\Temp\\appium_lib_session' : '/tmp/appium_lib_session'
518-
end
519-
520560
# @private
521561
def write_session_id(session_id, export_path = '/tmp/appium_lib_session')
522562
export_path.tr!('/', '\\') if ::Appium::Core::Base.platform.windows?

test/test_helper.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def android_direct
144144
wait: 30,
145145
wait_timeout: 20,
146146
wait_interval: 1,
147-
direct_access: true
147+
direct_connect: true
148148
}
149149
}
150150
end

0 commit comments

Comments
 (0)