1313# limitations under the License.
1414from typing import Any , Dict , Union
1515
16- from selenium .common .exceptions import InvalidArgumentException , UnknownMethodException
1716from typing_extensions import Self
1817
1918from appium .protocols .webdriver .can_execute_commands import CanExecuteCommands
2019from appium .protocols .webdriver .can_execute_scripts import CanExecuteScripts
21- from appium .protocols .webdriver .can_remember_extension_presence import CanRememberExtensionPresence
2220
23- from ..mobilecommand import MobileCommand as Command
2421
25-
26- class Applications (CanExecuteCommands , CanExecuteScripts , CanRememberExtensionPresence ):
22+ class Applications (CanExecuteCommands , CanExecuteScripts ):
2723 def background_app (self , seconds : int ) -> Self :
2824 """Puts the application in the background on the device for a certain duration.
2925
@@ -37,11 +33,7 @@ def background_app(self, seconds: int) -> Self:
3733 """
3834 ext_name = 'mobile: backgroundApp'
3935 args = {'seconds' : seconds }
40- try :
41- self .assert_extension_exists (ext_name ).execute_script (ext_name , args )
42- except UnknownMethodException :
43- # TODO: Remove the fallback
44- self .mark_extension_absence (ext_name ).execute (Command .BACKGROUND , args )
36+ self .execute_script (ext_name , args )
4537 return self
4638
4739 def is_app_installed (self , bundle_id : str ) -> bool :
@@ -54,22 +46,13 @@ def is_app_installed(self, bundle_id: str) -> bool:
5446 `True` if app is installed
5547 """
5648 ext_name = 'mobile: isAppInstalled'
57- try :
58- return self .assert_extension_exists (ext_name ).execute_script (
59- ext_name ,
60- {
61- 'bundleId' : bundle_id ,
62- 'appId' : bundle_id ,
63- },
64- )
65- except (UnknownMethodException , InvalidArgumentException ):
66- # TODO: Remove the fallback
67- return self .mark_extension_absence (ext_name ).execute (
68- Command .IS_APP_INSTALLED ,
69- {
70- 'bundleId' : bundle_id ,
71- },
72- )['value' ]
49+ return self .execute_script (
50+ ext_name ,
51+ {
52+ 'bundleId' : bundle_id ,
53+ 'appId' : bundle_id ,
54+ },
55+ )
7356
7457 def install_app (self , app_path : str , ** options : Any ) -> Self :
7558 """Install the application found at `app_path` on the device.
@@ -91,22 +74,14 @@ def install_app(self, app_path: str, **options: Any) -> Self:
9174 Returns:
9275 Union['WebDriver', 'Applications']: Self instance
9376 """
94- ext_name = 'mobile: installApp'
95- try :
96- self .assert_extension_exists (ext_name ).execute_script (
97- 'mobile: installApp' ,
98- {
99- 'app' : app_path ,
100- 'appPath' : app_path ,
101- ** (options or {}),
102- },
103- )
104- except (UnknownMethodException , InvalidArgumentException ):
105- # TODO: Remove the fallback
106- data : Dict [str , Any ] = {'appPath' : app_path }
107- if options :
108- data .update ({'options' : options })
109- self .mark_extension_absence (ext_name ).execute (Command .INSTALL_APP , data )
77+ self .execute_script (
78+ 'mobile: installApp' ,
79+ {
80+ 'app' : app_path ,
81+ 'appPath' : app_path ,
82+ ** (options or {}),
83+ },
84+ )
11085 return self
11186
11287 def remove_app (self , app_id : str , ** options : Any ) -> Self :
@@ -125,21 +100,14 @@ def remove_app(self, app_id: str, **options: Any) -> Self:
125100 Union['WebDriver', 'Applications']: Self instance
126101 """
127102 ext_name = 'mobile: removeApp'
128- try :
129- self .assert_extension_exists (ext_name ).execute_script (
130- ext_name ,
131- {
132- 'appId' : app_id ,
133- 'bundleId' : app_id ,
134- ** (options or {}),
135- },
136- )
137- except (UnknownMethodException , InvalidArgumentException ):
138- # TODO: Remove the fallback
139- data : Dict [str , Any ] = {'appId' : app_id }
140- if options :
141- data .update ({'options' : options })
142- self .mark_extension_absence (ext_name ).execute (Command .REMOVE_APP , data )
103+ self .execute_script (
104+ ext_name ,
105+ {
106+ 'appId' : app_id ,
107+ 'bundleId' : app_id ,
108+ ** (options or {}),
109+ },
110+ )
143111 return self
144112
145113 def terminate_app (self , app_id : str , ** options : Any ) -> bool :
@@ -156,21 +124,14 @@ def terminate_app(self, app_id: str, **options: Any) -> bool:
156124 True if the app has been successfully terminated
157125 """
158126 ext_name = 'mobile: terminateApp'
159- try :
160- return self .assert_extension_exists (ext_name ).execute_script (
161- ext_name ,
162- {
163- 'appId' : app_id ,
164- 'bundleId' : app_id ,
165- ** (options or {}),
166- },
167- )
168- except (UnknownMethodException , InvalidArgumentException ):
169- # TODO: Remove the fallback
170- data : Dict [str , Any ] = {'appId' : app_id }
171- if options :
172- data .update ({'options' : options })
173- return self .mark_extension_absence (ext_name ).execute (Command .TERMINATE_APP , data )['value' ]
127+ return self .execute_script (
128+ ext_name ,
129+ {
130+ 'appId' : app_id ,
131+ 'bundleId' : app_id ,
132+ ** (options or {}),
133+ },
134+ )
174135
175136 def activate_app (self , app_id : str ) -> Self :
176137 """Activates the application if it is not running
@@ -183,17 +144,13 @@ def activate_app(self, app_id: str) -> Self:
183144 Union['WebDriver', 'Applications']: Self instance
184145 """
185146 ext_name = 'mobile: activateApp'
186- try :
187- self .assert_extension_exists (ext_name ).execute_script (
188- ext_name ,
189- {
190- 'appId' : app_id ,
191- 'bundleId' : app_id ,
192- },
193- )
194- except (UnknownMethodException , InvalidArgumentException ):
195- # TODO: Remove the fallback
196- self .mark_extension_absence (ext_name ).execute (Command .ACTIVATE_APP , {'appId' : app_id })
147+ self .execute_script (
148+ ext_name ,
149+ {
150+ 'appId' : app_id ,
151+ 'bundleId' : app_id ,
152+ },
153+ )
197154 return self
198155
199156 def query_app_state (self , app_id : str ) -> int :
@@ -207,22 +164,13 @@ def query_app_state(self, app_id: str) -> int:
207164 class for more details.
208165 """
209166 ext_name = 'mobile: queryAppState'
210- try :
211- return self .assert_extension_exists (ext_name ).execute_script (
212- ext_name ,
213- {
214- 'appId' : app_id ,
215- 'bundleId' : app_id ,
216- },
217- )
218- except (UnknownMethodException , InvalidArgumentException ):
219- # TODO: Remove the fallback
220- return self .mark_extension_absence (ext_name ).execute (
221- Command .QUERY_APP_STATE ,
222- {
223- 'appId' : app_id ,
224- },
225- )['value' ]
167+ return self .execute_script (
168+ ext_name ,
169+ {
170+ 'appId' : app_id ,
171+ 'bundleId' : app_id ,
172+ },
173+ )
226174
227175 def app_strings (self , language : Union [str , None ] = None , string_file : Union [str , None ] = None ) -> Dict [str , str ]:
228176 """Returns the application strings from the device for the specified
@@ -241,29 +189,7 @@ def app_strings(self, language: Union[str, None] = None, string_file: Union[str,
241189 data ['language' ] = language
242190 if string_file is not None :
243191 data ['stringFile' ] = string_file
244- return self .assert_extension_exists ( ext_name ). execute_script (ext_name , data )
192+ return self .execute_script (ext_name , data )
245193
246194 def _add_commands (self ) -> None :
247- self .command_executor .add_command (Command .BACKGROUND , 'POST' , '/session/$sessionId/appium/app/background' )
248- self .command_executor .add_command (
249- Command .IS_APP_INSTALLED ,
250- 'POST' ,
251- '/session/$sessionId/appium/device/app_installed' ,
252- )
253- self .command_executor .add_command (Command .INSTALL_APP , 'POST' , '/session/$sessionId/appium/device/install_app' )
254- self .command_executor .add_command (Command .REMOVE_APP , 'POST' , '/session/$sessionId/appium/device/remove_app' )
255- self .command_executor .add_command (
256- Command .TERMINATE_APP ,
257- 'POST' ,
258- '/session/$sessionId/appium/device/terminate_app' ,
259- )
260- self .command_executor .add_command (
261- Command .ACTIVATE_APP ,
262- 'POST' ,
263- '/session/$sessionId/appium/device/activate_app' ,
264- )
265- self .command_executor .add_command (
266- Command .QUERY_APP_STATE ,
267- 'POST' ,
268- '/session/$sessionId/appium/device/app_state' ,
269- )
195+ pass
0 commit comments