-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathcommon_test.rb
More file actions
202 lines (175 loc) · 7.32 KB
/
Copy pathcommon_test.rb
File metadata and controls
202 lines (175 loc) · 7.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# frozen_string_literal: true
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
require 'test_helper'
require 'webmock/minitest'
# $ rake test:unit TEST=test/unit/common_test.rb
class AppiumLibCoreTest
class Common
class AppiumCoreBaseBridgeTest < Minitest::Test
include AppiumLibCoreTest::Mock
def setup
@bridge = Appium::Core::Base::Bridge.new url: 'http://127.0.0.1:4723/wd/hub'
end
RESPONSE_BASE_VALUE = {
sessionId: '1234567890',
capabilities: {
platformName: :android,
automationName: 'uiautomator2',
app: 'test/functional/app/api.apk.zip',
platformVersion: '7.1.1',
deviceName: 'Android Emulator',
appPackage: 'io.appium.android.apis'
}
}.freeze
CAPS = {
platformName: :android,
automationName: 'uiautomator2',
app: "#{Dir.pwd}/test/functional/app/api.apk.zip",
platformVersion: '7.1.1',
deviceName: 'Android Emulator',
appPackage: 'io.appium.android.apis'
}.freeze
APPIUM_PREFIX_CAPS = {
platformName: :android,
'appium:automationName' => 'uiautomator2',
'appium:app' => "#{Dir.pwd}/test/functional/app/api.apk.zip",
'appium:platformVersion' => '7.1.1',
'appium:deviceName' => 'Android Emulator',
'appium:appPackage' => 'io.appium.android.apis'
}.freeze
def test_create_session_w3c
response = { value: RESPONSE_BASE_VALUE }.to_json
stub_request(:post, 'http://127.0.0.1:4723/wd/hub/session')
.with(body: { capabilities: { alwaysMatch: APPIUM_PREFIX_CAPS, firstMatch: [{}] } }.to_json)
.to_return(headers: Mock::HEADER, status: 200, body: response)
stub_request(:get, 'http://127.0.0.1:4723/wd/hub/sessions')
.to_return(headers: Mock::HEADER, status: 200, body: { value: [{ id: 'c363add8-a7ca-4455-b9e3-9ac4d69e95b3',
capabilities: CAPS }] }.to_json)
driver = ::Appium::Core.for({ caps: CAPS, appium_lib: {} }).start_driver
assert_requested(:post, 'http://127.0.0.1:4723/wd/hub/session', times: 1)
sessions = driver.sessions
assert_requested(:get, 'http://127.0.0.1:4723/wd/hub/sessions', times: 1)
assert_equal 1, sessions.length
assert_equal 'c363add8-a7ca-4455-b9e3-9ac4d69e95b3', sessions.first['id']
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: { capabilities: { alwaysMatch: appium_prefix_http_caps, firstMatch: [{}] } }.to_json)
.to_return(headers: Mock::HEADER, status: 200, body: response)
core = ::Appium::Core.for({ caps: http_caps, appium_lib: {} })
core.start_driver
assert_requested(:post, 'http://127.0.0.1:4723/wd/hub/session', times: 1)
assert_equal 'http://example.com/test.apk.zip', core.caps[:app]
end
def test_add_appium_prefix_already_have_appium_prefix
cap = {
platformName: :ios,
automationName: 'XCUITest',
'appium:app' => 'test/functional/app/UICatalog.app.zip',
platformVersion: '11.4',
deviceName: 'iPhone Simulator',
useNewWDA: true,
some_capability1: 'some_capability1',
someCapability2: 'someCapability2',
'some_capability3' => 'string_shold_keep',
'some_capability4' => {
'nested_key1' => 1,
nested_key2: 2
}
}
base_caps = Appium::Core::Base::Capabilities.new cap
expected = {
'platformName' => :ios,
'automationName' => 'XCUITest',
'appium:app' => 'test/functional/app/UICatalog.app.zip',
'platformVersion' => '11.4',
'deviceName' => 'iPhone Simulator',
'useNewWDA' => true,
'someCapability1' => 'some_capability1',
'someCapability2' => 'someCapability2',
'some_capability3' => 'string_shold_keep',
'some_capability4' => { 'nested_key1' => 1, 'nestedKey2' => 2 }
}
assert_equal expected, base_caps.as_json
caps_with_appium = @bridge.add_appium_prefix(base_caps)
expected = {
platformName: :ios,
'appium:automationName' => 'XCUITest',
'appium:app' => 'test/functional/app/UICatalog.app.zip',
'appium:platformVersion' => '11.4',
'appium:deviceName' => 'iPhone Simulator',
'appium:useNewWDA' => true,
'appium:some_capability1' => 'some_capability1',
'appium:someCapability2' => 'someCapability2',
'appium:some_capability3' => 'string_shold_keep',
'appium:some_capability4' => {
'nested_key1' => 1,
nested_key2: 2
}
}
assert_equal expected, caps_with_appium.__send__(:capabilities)
expected = {
'platformName' => :ios,
'appium:automationName' => 'XCUITest',
'appium:app' => 'test/functional/app/UICatalog.app.zip',
'appium:platformVersion' => '11.4',
'appium:deviceName' => 'iPhone Simulator',
'appium:useNewWDA' => true,
'appium:some_capability1' => 'some_capability1',
'appium:someCapability2' => 'someCapability2',
'appium:some_capability3' => 'string_shold_keep',
'appium:some_capability4' => {
'nested_key1' => 1,
'nestedKey2' => 2
}
}
assert_equal expected, caps_with_appium.as_json # for testing
end
def test_add_appium_prefix_has_no_parameter
cap = {}
base_caps = Appium::Core::Base::Capabilities.new cap
expected = {}
assert_equal expected, @bridge.add_appium_prefix(base_caps).__send__(:capabilities)
end
end
end
end