@@ -149,7 +149,7 @@ def test_default_timeout_for_http_client_with_direct
149149 appActivity : 'io.appium.android.apis.ApiDemos' ,
150150 someCapability : 'some_capability' ,
151151 directConnectProtocol : 'http' ,
152- directConnectHost : 'localhost ' ,
152+ directConnectHost : '1.1.1.1 ' ,
153153 directConnectPort : '8888' ,
154154 directConnectPath : '/wd/hub'
155155 }
@@ -159,14 +159,14 @@ def test_default_timeout_for_http_client_with_direct
159159 stub_request ( :post , 'http://127.0.0.1:4723/session' )
160160 . to_return ( headers : HEADER , status : 200 , body : response )
161161
162- stub_request ( :post , 'http://localhost :8888/wd/hub/session/1234567890/timeouts' )
162+ stub_request ( :post , 'http://1.1.1.1 :8888/wd/hub/session/1234567890/timeouts' )
163163 . with ( body : { implicit : 30_000 } . to_json )
164164 . to_return ( headers : HEADER , status : 200 , body : { value : nil } . to_json )
165165
166166 driver = core . start_driver
167167
168168 assert_requested ( :post , 'http://127.0.0.1:4723/session' , times : 1 )
169- assert_requested ( :post , 'http://localhost :8888/wd/hub/session/1234567890/timeouts' ,
169+ assert_requested ( :post , 'http://1.1.1.1 :8888/wd/hub/session/1234567890/timeouts' ,
170170 body : { implicit : 30_000 } . to_json , times : 1 )
171171 driver
172172 end
@@ -179,7 +179,7 @@ def test_default_timeout_for_http_client_with_direct
179179 uri = driver . send ( :bridge ) . http . send ( :server_url )
180180 assert core . direct_connect
181181 assert_equal 'http' , uri . scheme
182- assert_equal 'localhost ' , uri . host
182+ assert_equal '1.1.1.1 ' , uri . host
183183 assert_equal 8888 , uri . port
184184 assert_equal '/wd/hub/' , uri . path
185185 end
@@ -198,8 +198,8 @@ def test_default_timeout_for_http_client_with_direct_appium_prefix
198198 appPackage : 'io.appium.android.apis' ,
199199 appActivity : 'io.appium.android.apis.ApiDemos' ,
200200 someCapability : 'some_capability' ,
201- 'appium:directConnectProtocol' => 'http ' ,
202- 'appium:directConnectHost' => 'localhost ' ,
201+ 'appium:directConnectProtocol' => 'https ' ,
202+ 'appium:directConnectHost' => 'appium.io ' ,
203203 'appium:directConnectPort' => '8888' ,
204204 'appium:directConnectPath' => '/wd/hub'
205205 }
@@ -209,14 +209,14 @@ def test_default_timeout_for_http_client_with_direct_appium_prefix
209209 stub_request ( :post , 'http://127.0.0.1:4723/session' )
210210 . to_return ( headers : HEADER , status : 200 , body : response )
211211
212- stub_request ( :post , 'http ://localhost :8888/wd/hub/session/1234567890/timeouts' )
212+ stub_request ( :post , 'https ://appium.io :8888/wd/hub/session/1234567890/timeouts' )
213213 . with ( body : { implicit : 30_000 } . to_json )
214214 . to_return ( headers : HEADER , status : 200 , body : { value : nil } . to_json )
215215
216216 driver = core . start_driver
217217
218218 assert_requested ( :post , 'http://127.0.0.1:4723/session' , times : 1 )
219- assert_requested ( :post , 'http ://localhost :8888/wd/hub/session/1234567890/timeouts' ,
219+ assert_requested ( :post , 'https ://appium.io :8888/wd/hub/session/1234567890/timeouts' ,
220220 body : { implicit : 30_000 } . to_json , times : 1 )
221221 driver
222222 end
@@ -228,8 +228,8 @@ def test_default_timeout_for_http_client_with_direct_appium_prefix
228228 assert_equal 999_999 , driver . send ( :bridge ) . http . read_timeout
229229 uri = driver . send ( :bridge ) . http . send ( :server_url )
230230 assert core . direct_connect
231- assert_equal 'http ' , uri . scheme
232- assert_equal 'localhost ' , uri . host
231+ assert_equal 'https ' , uri . scheme
232+ assert_equal 'appium.io ' , uri . host
233233 assert_equal 8888 , uri . port
234234 assert_equal '/wd/hub/' , uri . path
235235 end
@@ -249,7 +249,7 @@ def test_default_timeout_for_http_client_with_direct_appium_prefix_prior_than_no
249249 appActivity : 'io.appium.android.apis.ApiDemos' ,
250250 someCapability : 'some_capability' ,
251251 'appium:directConnectProtocol' => 'http' ,
252- 'appium:directConnectHost' => 'localhost ' ,
252+ 'appium:directConnectHost' => '1.1.1.1 ' ,
253253 'appium:directConnectPort' => '8888' ,
254254 'appium:directConnectPath' => '/wd/hub' ,
255255 directConnectProtocol : 'https' ,
@@ -263,14 +263,14 @@ def test_default_timeout_for_http_client_with_direct_appium_prefix_prior_than_no
263263 stub_request ( :post , 'http://127.0.0.1:4723/session' )
264264 . to_return ( headers : HEADER , status : 200 , body : response )
265265
266- stub_request ( :post , 'http://localhost :8888/wd/hub/session/1234567890/timeouts' )
266+ stub_request ( :post , 'http://1.1.1.1 :8888/wd/hub/session/1234567890/timeouts' )
267267 . with ( body : { implicit : 30_000 } . to_json )
268268 . to_return ( headers : HEADER , status : 200 , body : { value : nil } . to_json )
269269
270270 driver = core . start_driver
271271
272272 assert_requested ( :post , 'http://127.0.0.1:4723/session' , times : 1 )
273- assert_requested ( :post , 'http://localhost :8888/wd/hub/session/1234567890/timeouts' ,
273+ assert_requested ( :post , 'http://1.1.1.1 :8888/wd/hub/session/1234567890/timeouts' ,
274274 body : { implicit : 30_000 } . to_json , times : 1 )
275275 driver
276276 end
@@ -283,11 +283,54 @@ def test_default_timeout_for_http_client_with_direct_appium_prefix_prior_than_no
283283 uri = driver . send ( :bridge ) . http . send ( :server_url )
284284 assert core . direct_connect
285285 assert_equal 'http' , uri . scheme
286- assert_equal 'localhost ' , uri . host
286+ assert_equal '1.1.1.1 ' , uri . host
287287 assert_equal 8888 , uri . port
288288 assert_equal '/wd/hub/' , uri . path
289289 end
290290
291+ def test_direct_connect_loopback_host_falls_back_to_original_url
292+ response = {
293+ value : {
294+ sessionId : '1234567890' ,
295+ capabilities : {
296+ platformName : :android ,
297+ automationName : ENV [ 'APPIUM_DRIVER' ] || 'uiautomator2' ,
298+ app : 'test/functional/app/ApiDemos-debug.apk' ,
299+ platformVersion : '7.1.1' ,
300+ deviceName : 'Android Emulator' ,
301+ appPackage : 'io.appium.android.apis' ,
302+ appActivity : 'io.appium.android.apis.ApiDemos' ,
303+ someCapability : 'some_capability' ,
304+ directConnectProtocol : 'http' ,
305+ directConnectHost : 'localhost' ,
306+ directConnectPort : '8888' ,
307+ directConnectPath : '/wd/hub'
308+ }
309+ }
310+ } . to_json
311+
312+ stub_request ( :post , 'http://127.0.0.1:4723/session' )
313+ . to_return ( headers : HEADER , status : 200 , body : response )
314+
315+ stub_request ( :post , 'http://127.0.0.1:4723/session/1234567890/timeouts' )
316+ . with ( body : { implicit : 30_000 } . to_json )
317+ . to_return ( headers : HEADER , status : 200 , body : { value : nil } . to_json )
318+
319+ core = ::Appium ::Core . for ( Caps . android_direct )
320+ driver = core . start_driver
321+
322+ uri = driver . send ( :bridge ) . http . send ( :server_url )
323+ assert_equal 'http' , uri . scheme
324+ assert_equal '127.0.0.1' , uri . host
325+ assert_equal 4723 , uri . port
326+ assert_equal '/' , uri . path
327+
328+ assert_requested ( :post , 'http://127.0.0.1:4723/session' , times : 1 )
329+ assert_requested ( :post , 'http://127.0.0.1:4723/session/1234567890/timeouts' ,
330+ body : { implicit : 30_000 } . to_json , times : 1 )
331+ assert_not_requested ( :post , 'http://localhost:8888/wd/hub/session/1234567890/timeouts' )
332+ end
333+
291334 def test_default_timeout_for_http_client_with_direct_no_path
292335 android_mock_create_session_w3c_direct_no_path = lambda do |core |
293336 response = {
@@ -303,7 +346,7 @@ def test_default_timeout_for_http_client_with_direct_no_path
303346 appActivity : 'io.appium.android.apis.ApiDemos' ,
304347 someCapability : 'some_capability' ,
305348 directConnectProtocol : 'http' ,
306- directConnectHost : 'localhost ' ,
349+ directConnectHost : '1.1.1.1 ' ,
307350 directConnectPort : '8888'
308351 }
309352 }
@@ -352,7 +395,7 @@ def test_default_timeout_for_http_client_with_direct_no_supported_client
352395 appActivity : 'io.appium.android.apis.ApiDemos' ,
353396 someCapability : 'some_capability' ,
354397 directConnectProtocol : 'http' ,
355- directConnectHost : 'localhost ' ,
398+ directConnectHost : '1.1.1.1 ' ,
356399 directConnectPort : '8888' ,
357400 directConnectPath : '/wd/hub'
358401 }
@@ -517,7 +560,7 @@ def test_attach_to_an_existing_session
517560 appActivity : 'io.appium.android.apis.ApiDemos' ,
518561 someCapability : 'some_capability' ,
519562 directConnectProtocol : 'http' ,
520- directConnectHost : 'localhost ' ,
563+ directConnectHost : '1.1.1.1 ' ,
521564 directConnectPort : '8888' ,
522565 directConnectPath : '/wd/hub'
523566 }
@@ -527,14 +570,14 @@ def test_attach_to_an_existing_session
527570 stub_request ( :post , 'http://127.0.0.1:4723/session' )
528571 . to_return ( headers : HEADER , status : 200 , body : response )
529572
530- stub_request ( :post , 'http://localhost :8888/wd/hub/session/1234567890/timeouts' )
573+ stub_request ( :post , 'http://1.1.1.1 :8888/wd/hub/session/1234567890/timeouts' )
531574 . with ( body : { implicit : 30_000 } . to_json )
532575 . to_return ( headers : HEADER , status : 200 , body : { value : nil } . to_json )
533576
534577 driver = core . start_driver
535578
536579 assert_requested ( :post , 'http://127.0.0.1:4723/session' , times : 1 )
537- assert_requested ( :post , 'http://localhost :8888/wd/hub/session/1234567890/timeouts' ,
580+ assert_requested ( :post , 'http://1.1.1.1 :8888/wd/hub/session/1234567890/timeouts' ,
538581 body : { implicit : 30_000 } . to_json , times : 1 )
539582 driver
540583 end
0 commit comments