File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1616class MobileCommand (object ):
1717 # Common
1818 GET_SESSION = 'getSession'
19+ GET_ALL_SESSIONS = 'getAllSessions'
1920
2021 GET_LOCATION = 'getLocation'
2122 SET_LOCATION = 'setLocation'
Original file line number Diff line number Diff line change @@ -701,6 +701,16 @@ def session(self):
701701 """
702702 return self .execute (Command .GET_SESSION )['value' ]
703703
704+ @property
705+ def all_sessions (self ):
706+ """ Retrieves all sessions that are open
707+ Usage:
708+ sessions = driver.allSessions
709+ Returns:
710+ `dict containing all open sessions`
711+ """
712+ return self .execute (Command .GET_ALL_SESSIONS )['value' ]
713+
704714 @property
705715 def events (self ):
706716 """ Retrieves events information from the current session
Original file line number Diff line number Diff line change @@ -24,10 +24,21 @@ class WebDriverTests(unittest.TestCase):
2424 def setUp (self ):
2525 desired_caps = desired_capabilities .get_desired_capabilities ('UICatalog.app.zip' )
2626 self .driver = webdriver .Remote ('http://localhost:4723/wd/hub' , desired_caps )
27+ desired_caps ['deviceName' ] = 'iPhone Xs Max'
28+ desired_caps ['wdaLocalPort' ] = '8102'
2729
2830 def tearDown (self ):
2931 self .driver .quit ()
3032
33+ def testAllSessions (self ):
34+ desired_caps = desired_capabilities .get_desired_capabilities ('UICatalog.app.zip' )
35+ desired_caps ['deviceName' ] = 'iPhone Xs Max'
36+ desired_caps ['wdaLocalPort' ] = '8102'
37+ self .driver1 = webdriver .Remote ('http://localhost:4723/wd/hub' , desired_caps )
38+ self .assertEqual (2 , len (self .driver .all_sessions ))
39+ if self .driver1 :
40+ self .driver1 .quit ()
41+
3142 def test_app_management (self ):
3243 # this only works in Xcode9+
3344 if float (desired_capabilities .get_desired_capabilities (
Original file line number Diff line number Diff line change @@ -257,6 +257,17 @@ def test_create_session_register_uridirect_no_direct_connect_path(self):
257257 assert 'http://localhost:4723/wd/hub' == driver .command_executor ._url
258258 assert ['NATIVE_APP' , 'CHROMIUM' ] == driver .contexts
259259
260+ @httpretty .activate
261+ def test_get_all_sessions (self ):
262+ driver = ios_w3c_driver ()
263+ httpretty .register_uri (
264+ httpretty .GET ,
265+ appium_command ('/sessions' ),
266+ body = json .dumps ({'value' : {'deviceName' : 'iPhone Simulator' , 'events' : {'simStarted' : [1234567891 ]}}})
267+ )
268+ session = driver .all_sessions
269+ assert len (session ) != 1
270+
260271 @httpretty .activate
261272 def test_get_session (self ):
262273 driver = ios_w3c_driver ()
You can’t perform that action at this time.
0 commit comments