@@ -121,7 +121,7 @@ def test_http_client
121
121
end
122
122
123
123
def test_default_timeout_for_http_client_with_direct
124
- def android_mock_create_session_w3c_direct ( core )
124
+ android_mock_create_session_w3c_direct = lambda do | core |
125
125
response = {
126
126
value : {
127
127
sessionId : '1234567890' ,
@@ -160,7 +160,115 @@ def android_mock_create_session_w3c_direct(core)
160
160
end
161
161
162
162
core = ::Appium ::Core . for ( Caps . android_direct )
163
- driver = android_mock_create_session_w3c_direct ( core )
163
+ driver = android_mock_create_session_w3c_direct . call ( core )
164
+
165
+ assert_equal 999_999 , driver . send ( :bridge ) . http . open_timeout
166
+ assert_equal 999_999 , driver . send ( :bridge ) . http . read_timeout
167
+ uri = driver . send ( :bridge ) . http . send ( :server_url )
168
+ assert core . direct_connect
169
+ assert_equal 'http' , uri . scheme
170
+ assert_equal 'localhost' , uri . host
171
+ assert_equal 8888 , uri . port
172
+ assert_equal '/wd/hub/' , uri . path
173
+ end
174
+
175
+ def test_default_timeout_for_http_client_with_direct_appium_prefix
176
+ android_mock_create_session_w3c_direct = lambda do |core |
177
+ response = {
178
+ value : {
179
+ sessionId : '1234567890' ,
180
+ capabilities : {
181
+ platformName : :android ,
182
+ automationName : ENV [ 'APPIUM_DRIVER' ] || 'uiautomator2' ,
183
+ app : 'test/functional/app/api.apk.zip' ,
184
+ platformVersion : '7.1.1' ,
185
+ deviceName : 'Android Emulator' ,
186
+ appPackage : 'io.appium.android.apis' ,
187
+ appActivity : 'io.appium.android.apis.ApiDemos' ,
188
+ someCapability : 'some_capability' ,
189
+ unicodeKeyboard : true ,
190
+ resetKeyboard : true ,
191
+ 'appium:directConnectProtocol' => 'http' ,
192
+ 'appium:directConnectHost' => 'localhost' ,
193
+ 'appium:directConnectPort' => '8888' ,
194
+ 'appium:directConnectPath' => '/wd/hub'
195
+ }
196
+ }
197
+ } . to_json
198
+
199
+ stub_request ( :post , 'http://127.0.0.1:4723/wd/hub/session' )
200
+ . to_return ( headers : HEADER , status : 200 , body : response )
201
+
202
+ stub_request ( :post , 'http://localhost:8888/wd/hub/session/1234567890/timeouts' )
203
+ . with ( body : { implicit : 30_000 } . to_json )
204
+ . to_return ( headers : HEADER , status : 200 , body : { value : nil } . to_json )
205
+
206
+ driver = core . start_driver
207
+
208
+ assert_requested ( :post , 'http://127.0.0.1:4723/wd/hub/session' , times : 1 )
209
+ assert_requested ( :post , 'http://localhost:8888/wd/hub/session/1234567890/timeouts' ,
210
+ body : { implicit : 30_000 } . to_json , times : 1 )
211
+ driver
212
+ end
213
+
214
+ core = ::Appium ::Core . for ( Caps . android_direct )
215
+ driver = android_mock_create_session_w3c_direct . call ( core )
216
+
217
+ assert_equal 999_999 , driver . send ( :bridge ) . http . open_timeout
218
+ assert_equal 999_999 , driver . send ( :bridge ) . http . read_timeout
219
+ uri = driver . send ( :bridge ) . http . send ( :server_url )
220
+ assert core . direct_connect
221
+ assert_equal 'http' , uri . scheme
222
+ assert_equal 'localhost' , uri . host
223
+ assert_equal 8888 , uri . port
224
+ assert_equal '/wd/hub/' , uri . path
225
+ end
226
+
227
+ def test_default_timeout_for_http_client_with_direct_appium_prefix_prior_than_non_prefix
228
+ android_mock_create_session_w3c_direct = lambda do |core |
229
+ response = {
230
+ value : {
231
+ sessionId : '1234567890' ,
232
+ capabilities : {
233
+ platformName : :android ,
234
+ automationName : ENV [ 'APPIUM_DRIVER' ] || 'uiautomator2' ,
235
+ app : 'test/functional/app/api.apk.zip' ,
236
+ platformVersion : '7.1.1' ,
237
+ deviceName : 'Android Emulator' ,
238
+ appPackage : 'io.appium.android.apis' ,
239
+ appActivity : 'io.appium.android.apis.ApiDemos' ,
240
+ someCapability : 'some_capability' ,
241
+ unicodeKeyboard : true ,
242
+ resetKeyboard : true ,
243
+ 'appium:directConnectProtocol' => 'http' ,
244
+ 'appium:directConnectHost' => 'localhost' ,
245
+ 'appium:directConnectPort' => '8888' ,
246
+ 'appium:directConnectPath' => '/wd/hub' ,
247
+ directConnectProtocol : 'https' ,
248
+ directConnectHost : 'non-appium-localhost' ,
249
+ directConnectPort : '8889' ,
250
+ directConnectPath : '/non/appium/wd/hub'
251
+ }
252
+ }
253
+ } . to_json
254
+
255
+ stub_request ( :post , 'http://127.0.0.1:4723/wd/hub/session' )
256
+ . to_return ( headers : HEADER , status : 200 , body : response )
257
+
258
+ stub_request ( :post , 'http://localhost:8888/wd/hub/session/1234567890/timeouts' )
259
+ . with ( body : { implicit : 30_000 } . to_json )
260
+ . to_return ( headers : HEADER , status : 200 , body : { value : nil } . to_json )
261
+
262
+ driver = core . start_driver
263
+
264
+ assert_requested ( :post , 'http://127.0.0.1:4723/wd/hub/session' , times : 1 )
265
+ assert_requested ( :post , 'http://localhost:8888/wd/hub/session/1234567890/timeouts' ,
266
+ body : { implicit : 30_000 } . to_json , times : 1 )
267
+ driver
268
+ end
269
+
270
+ core = ::Appium ::Core . for ( Caps . android_direct )
271
+ driver = android_mock_create_session_w3c_direct . call ( core )
164
272
165
273
assert_equal 999_999 , driver . send ( :bridge ) . http . open_timeout
166
274
assert_equal 999_999 , driver . send ( :bridge ) . http . read_timeout
@@ -173,7 +281,7 @@ def android_mock_create_session_w3c_direct(core)
173
281
end
174
282
175
283
def test_default_timeout_for_http_client_with_direct_no_path
176
- def android_mock_create_session_w3c_direct_no_path ( core )
284
+ android_mock_create_session_w3c_direct_no_path = lambda do | core |
177
285
response = {
178
286
value : {
179
287
sessionId : '1234567890' ,
@@ -211,7 +319,7 @@ def android_mock_create_session_w3c_direct_no_path(core)
211
319
end
212
320
213
321
core = ::Appium ::Core . for ( Caps . android_direct )
214
- driver = android_mock_create_session_w3c_direct_no_path ( core )
322
+ driver = android_mock_create_session_w3c_direct_no_path . call ( core )
215
323
216
324
assert_equal 999_999 , driver . send ( :bridge ) . http . open_timeout
217
325
assert_equal 999_999 , driver . send ( :bridge ) . http . read_timeout
@@ -224,7 +332,7 @@ def android_mock_create_session_w3c_direct_no_path(core)
224
332
end
225
333
226
334
def test_default_timeout_for_http_client_with_direct_no_supported_client
227
- def android_mock_create_session_w3c_direct_default_client ( core )
335
+ android_mock_create_session_w3c_direct_default_client = lambda do | core |
228
336
response = {
229
337
value : {
230
338
sessionId : '1234567890' ,
@@ -263,7 +371,7 @@ def android_mock_create_session_w3c_direct_default_client(core)
263
371
end
264
372
265
373
core = ::Appium ::Core . for ( Caps . android_direct )
266
- driver = android_mock_create_session_w3c_direct_default_client ( core )
374
+ driver = android_mock_create_session_w3c_direct_default_client . call ( core )
267
375
268
376
assert_nil driver . send ( :bridge ) . http . open_timeout
269
377
assert_nil driver . send ( :bridge ) . http . read_timeout
0 commit comments