Skip to content

Commit

Permalink
can set packages over http (#108)
Browse files Browse the repository at this point in the history
* can set packages over http

* update changelog

* fix rubocop
  • Loading branch information
KazuCocoa authored Jul 17, 2018
1 parent 634d003 commit 4ee5ddb
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file.
### Enhancements

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

### Deprecations

Expand Down
26 changes: 26 additions & 0 deletions lib/appium_lib_core/driver.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'uri'

module Appium
module Core
class Driver
Expand Down Expand Up @@ -93,6 +95,28 @@ class Driver
# @core = Appium::Core.for(self, opts) # create a core driver with `opts` and extend methods into `self`
# @core.start_driver(server_url: server_url) # start driver
#
# # Start iOS driver with .zip file over HTTP
# opts = {
# caps: {
# platformName: :ios,
# platformVersion: '11.0',
# deviceName: 'iPhone Simulator',
# automationName: 'XCUITest',
# app: 'http://example.com/path/to/MyiOS.app.zip'
# },
# appium_lib: {
# server_url: "http://custom-host:8080/wd/hub.com",
# export_session: false,
# port: 8080,
# wait: 0,
# wait_timeout: 20,
# wait_interval: 0.3,
# listener: nil,
# }
# }
# @core = Appium::Core.for(self, opts)
# @core.start_driver(server_url: server_url)
#
def self.for(target, opts = {})
new(target, opts)
end
Expand Down Expand Up @@ -366,6 +390,8 @@ def get_appium_lib_opts(opts)
# The path can be local or remote for Sauce.
def set_app_path
return unless @caps && @caps[:app] && !@caps[:app].empty?
return if @caps[:app] =~ URI::DEFAULT_PARSER.make_regexp

@caps[:app] = File.expand_path(@caps[:app])
end

Expand Down
91 changes: 91 additions & 0 deletions test/unit/common_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,47 @@ def test_create_session_force_mjsonwp_false
driver
end

def test_create_session_force_mjsonwp_with_http_package
response = {
status: 0, # To make bridge.dialect == :oss
value: {
sessionId: '1234567890',
capabilities: {
platformName: :android,
automationName: 'uiautomator2',
app: 'test/functional/app/api.apk',
platformVersion: '7.1.1',
deviceName: 'Android Emulator',
appPackage: 'io.appium.android.apis'
}
}
}.to_json
http_caps = {
platformName: :android,
automationName: 'uiautomator2',
app: 'http://example.com/test.apk.zip',
platformVersion: '7.1.1',
deviceName: 'Android Emulator',
appPackage: 'io.appium.android.apis'
}

stub_request(:post, 'http://127.0.0.1:4723/wd/hub/session')
.with(body: { desiredCapabilities: http_caps }.to_json)
.to_return(headers: Mock::HEADER, status: 200, body: response)

stub_request(:post, "#{Mock::SESSION}/timeouts/implicit_wait")
.with(body: { ms: 20_000 }.to_json)
.to_return(headers: Mock::HEADER, status: 200, body: { value: nil }.to_json)

core = ::Appium::Core.for(self, { caps: http_caps.merge({ forceMjsonwp: true }), appium_lib: {} })
core.start_driver

assert_requested(:post, 'http://127.0.0.1:4723/wd/hub/session', times: 1)
assert_requested(:post, "#{Mock::SESSION}/timeouts/implicit_wait", body: { ms: 20_000 }.to_json, times: 1)

assert_equal 'http://example.com/test.apk.zip', core.caps[:app]
end

def test_create_session_w3c
response = { value: RESPONSE_BASE_VALUE }.to_json

Expand All @@ -100,6 +141,56 @@ def test_create_session_w3c
driver
end

def test_create_session_w3c_with_http_package
response = {
value: {
sessionId: '1234567890',
capabilities: {
platformName: :android,
automationName: 'uiautomator2',
app: 'http://example.com/test.apk.zip',
platformVersion: '7.1.1',
deviceName: 'Android Emulator',
appPackage: 'io.appium.android.apis'
}
}
}.to_json
http_caps = {
platformName: :android,
automationName: 'uiautomator2',
app: 'http://example.com/test.apk.zip',
platformVersion: '7.1.1',
deviceName: 'Android Emulator',
appPackage: 'io.appium.android.apis'
}

appium_prefix_http_caps = {
platformName: :android,
'appium:automationName' => 'uiautomator2',
'appium:app' => 'http://example.com/test.apk.zip',
'appium:platformVersion' => '7.1.1',
'appium:deviceName' => 'Android Emulator',
'appium:appPackage' => 'io.appium.android.apis'
}

stub_request(:post, 'http://127.0.0.1:4723/wd/hub/session')
.with(body: { desiredCapabilities: http_caps,
capabilities: { alwaysMatch: appium_prefix_http_caps, firstMatch: [{}] } }.to_json)
.to_return(headers: Mock::HEADER, status: 200, body: response)

stub_request(:post, "#{Mock::SESSION}/timeouts")
.with(body: { implicit: 20_000 }.to_json)
.to_return(headers: Mock::HEADER, status: 200, body: { value: nil }.to_json)

core = ::Appium::Core.for(self, { caps: http_caps, appium_lib: {} })
core.start_driver

assert_requested(:post, 'http://127.0.0.1:4723/wd/hub/session', times: 1)
assert_requested(:post, "#{Mock::SESSION}/timeouts", body: { implicit: 20_000 }.to_json, times: 1)

assert_equal 'http://example.com/test.apk.zip', core.caps[:app]
end

def test_add_appium_prefix_compatible_with_oss
cap = {
platformName: :ios,
Expand Down

0 comments on commit 4ee5ddb

Please sign in to comment.