Skip to content

Commit 4ee5ddb

Browse files
authored
can set packages over http (#108)
* can set packages over http * update changelog * fix rubocop
1 parent 634d003 commit 4ee5ddb

File tree

3 files changed

+118
-0
lines changed

3 files changed

+118
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file.
55
### Enhancements
66

77
### Bug fixes
8+
- Available packages over HTTP [#106](https://github.com/appium/ruby_lib_core/issues/106)
89

910
### Deprecations
1011

lib/appium_lib_core/driver.rb

+26
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'uri'
2+
13
module Appium
24
module Core
35
class Driver
@@ -93,6 +95,28 @@ class Driver
9395
# @core = Appium::Core.for(self, opts) # create a core driver with `opts` and extend methods into `self`
9496
# @core.start_driver(server_url: server_url) # start driver
9597
#
98+
# # Start iOS driver with .zip file over HTTP
99+
# opts = {
100+
# caps: {
101+
# platformName: :ios,
102+
# platformVersion: '11.0',
103+
# deviceName: 'iPhone Simulator',
104+
# automationName: 'XCUITest',
105+
# app: 'http://example.com/path/to/MyiOS.app.zip'
106+
# },
107+
# appium_lib: {
108+
# server_url: "http://custom-host:8080/wd/hub.com",
109+
# export_session: false,
110+
# port: 8080,
111+
# wait: 0,
112+
# wait_timeout: 20,
113+
# wait_interval: 0.3,
114+
# listener: nil,
115+
# }
116+
# }
117+
# @core = Appium::Core.for(self, opts)
118+
# @core.start_driver(server_url: server_url)
119+
#
96120
def self.for(target, opts = {})
97121
new(target, opts)
98122
end
@@ -366,6 +390,8 @@ def get_appium_lib_opts(opts)
366390
# The path can be local or remote for Sauce.
367391
def set_app_path
368392
return unless @caps && @caps[:app] && !@caps[:app].empty?
393+
return if @caps[:app] =~ URI::DEFAULT_PARSER.make_regexp
394+
369395
@caps[:app] = File.expand_path(@caps[:app])
370396
end
371397

test/unit/common_test.rb

+91
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,47 @@ def test_create_session_force_mjsonwp_false
8181
driver
8282
end
8383

84+
def test_create_session_force_mjsonwp_with_http_package
85+
response = {
86+
status: 0, # To make bridge.dialect == :oss
87+
value: {
88+
sessionId: '1234567890',
89+
capabilities: {
90+
platformName: :android,
91+
automationName: 'uiautomator2',
92+
app: 'test/functional/app/api.apk',
93+
platformVersion: '7.1.1',
94+
deviceName: 'Android Emulator',
95+
appPackage: 'io.appium.android.apis'
96+
}
97+
}
98+
}.to_json
99+
http_caps = {
100+
platformName: :android,
101+
automationName: 'uiautomator2',
102+
app: 'http://example.com/test.apk.zip',
103+
platformVersion: '7.1.1',
104+
deviceName: 'Android Emulator',
105+
appPackage: 'io.appium.android.apis'
106+
}
107+
108+
stub_request(:post, 'http://127.0.0.1:4723/wd/hub/session')
109+
.with(body: { desiredCapabilities: http_caps }.to_json)
110+
.to_return(headers: Mock::HEADER, status: 200, body: response)
111+
112+
stub_request(:post, "#{Mock::SESSION}/timeouts/implicit_wait")
113+
.with(body: { ms: 20_000 }.to_json)
114+
.to_return(headers: Mock::HEADER, status: 200, body: { value: nil }.to_json)
115+
116+
core = ::Appium::Core.for(self, { caps: http_caps.merge({ forceMjsonwp: true }), appium_lib: {} })
117+
core.start_driver
118+
119+
assert_requested(:post, 'http://127.0.0.1:4723/wd/hub/session', times: 1)
120+
assert_requested(:post, "#{Mock::SESSION}/timeouts/implicit_wait", body: { ms: 20_000 }.to_json, times: 1)
121+
122+
assert_equal 'http://example.com/test.apk.zip', core.caps[:app]
123+
end
124+
84125
def test_create_session_w3c
85126
response = { value: RESPONSE_BASE_VALUE }.to_json
86127

@@ -100,6 +141,56 @@ def test_create_session_w3c
100141
driver
101142
end
102143

144+
def test_create_session_w3c_with_http_package
145+
response = {
146+
value: {
147+
sessionId: '1234567890',
148+
capabilities: {
149+
platformName: :android,
150+
automationName: 'uiautomator2',
151+
app: 'http://example.com/test.apk.zip',
152+
platformVersion: '7.1.1',
153+
deviceName: 'Android Emulator',
154+
appPackage: 'io.appium.android.apis'
155+
}
156+
}
157+
}.to_json
158+
http_caps = {
159+
platformName: :android,
160+
automationName: 'uiautomator2',
161+
app: 'http://example.com/test.apk.zip',
162+
platformVersion: '7.1.1',
163+
deviceName: 'Android Emulator',
164+
appPackage: 'io.appium.android.apis'
165+
}
166+
167+
appium_prefix_http_caps = {
168+
platformName: :android,
169+
'appium:automationName' => 'uiautomator2',
170+
'appium:app' => 'http://example.com/test.apk.zip',
171+
'appium:platformVersion' => '7.1.1',
172+
'appium:deviceName' => 'Android Emulator',
173+
'appium:appPackage' => 'io.appium.android.apis'
174+
}
175+
176+
stub_request(:post, 'http://127.0.0.1:4723/wd/hub/session')
177+
.with(body: { desiredCapabilities: http_caps,
178+
capabilities: { alwaysMatch: appium_prefix_http_caps, firstMatch: [{}] } }.to_json)
179+
.to_return(headers: Mock::HEADER, status: 200, body: response)
180+
181+
stub_request(:post, "#{Mock::SESSION}/timeouts")
182+
.with(body: { implicit: 20_000 }.to_json)
183+
.to_return(headers: Mock::HEADER, status: 200, body: { value: nil }.to_json)
184+
185+
core = ::Appium::Core.for(self, { caps: http_caps, appium_lib: {} })
186+
core.start_driver
187+
188+
assert_requested(:post, 'http://127.0.0.1:4723/wd/hub/session', times: 1)
189+
assert_requested(:post, "#{Mock::SESSION}/timeouts", body: { implicit: 20_000 }.to_json, times: 1)
190+
191+
assert_equal 'http://example.com/test.apk.zip', core.caps[:app]
192+
end
193+
103194
def test_add_appium_prefix_compatible_with_oss
104195
cap = {
105196
platformName: :ios,

0 commit comments

Comments
 (0)