11import time
22from typing import Union
3- from pywinauto import Desktop
43from pywinauto .timings import TimeoutError
5- from pywinauto .findwindows import ElementNotFoundError , WindowNotFoundError
4+ from pywinauto .findwindows import ElementNotFoundError
65from pywinauto .application import Application , WindowSpecification
76from .utils import Backend
87from .. import config
98
109
11- def connect (backend = Backend .WIN_32 , timeout = 60000 ,
12- ** connection_selectors ) -> Union [Application , WindowSpecification ]:
10+ def connect (backend = Backend .WIN_32 , timeout = 60000 , ** connection_selectors ) -> Application :
1311 """
1412 Connects to an instance of an open application.
1513 Use this method to be able to access application windows and elements.
@@ -24,34 +22,23 @@ def connect(backend=Backend.WIN_32, timeout=60000,
2422 ](https://documentation.botcity.dev/frameworks/desktop/windows-apps/).
2523
2624 Returns
27- app (Application | WindowSpecification ): The Application/Window instance.
25+ app (Application): The Application/Window instance.
2826 """
2927 connect_exception = None
3028 start_time = time .time ()
3129 while True :
3230 elapsed_time = (time .time () - start_time ) * 1000
3331 if elapsed_time > timeout :
34- break
32+ if connect_exception :
33+ raise connect_exception
34+ return None
3535 try :
3636 app = Application (backend = backend ).connect (** connection_selectors )
3737 return app
3838 except Exception as e :
3939 connect_exception = e
4040 time .sleep (config .DEFAULT_SLEEP_AFTER_ACTION / 1000.0 )
4141
42- if "path" in connection_selectors .keys ():
43- connection_selectors .pop ("path" )
44-
45- if not connection_selectors :
46- if connect_exception :
47- raise connect_exception
48- return None
49-
50- app = Desktop (backend = backend ).window (** connection_selectors )
51- if not app .exists ():
52- raise WindowNotFoundError (f"Unable to find an app using these criteria: { connection_selectors } " )
53- return app
54-
5542
5643def find_window (app : Union [Application , WindowSpecification ],
5744 waiting_time = 10000 , ** selectors ) -> WindowSpecification :
0 commit comments