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.
@@ -92,21 +75,14 @@ def install_app(self, app_path: str, **options: Any) -> Self:
9275 Union['WebDriver', 'Applications']: Self instance
9376 """
9477 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 )
78+ self .execute_script (
79+ ext_name ,
80+ {
81+ 'app' : app_path ,
82+ 'appPath' : app_path ,
83+ ** (options or {}),
84+ },
85+ )
11086 return self
11187
11288 def remove_app (self , app_id : str , ** options : Any ) -> Self :
@@ -125,21 +101,14 @@ def remove_app(self, app_id: str, **options: Any) -> Self:
125101 Union['WebDriver', 'Applications']: Self instance
126102 """
127103 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 )
104+ self .execute_script (
105+ ext_name ,
106+ {
107+ 'appId' : app_id ,
108+ 'bundleId' : app_id ,
109+ ** (options or {}),
110+ },
111+ )
143112 return self
144113
145114 def terminate_app (self , app_id : str , ** options : Any ) -> bool :
@@ -156,21 +125,14 @@ def terminate_app(self, app_id: str, **options: Any) -> bool:
156125 True if the app has been successfully terminated
157126 """
158127 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' ]
128+ return self .execute_script (
129+ ext_name ,
130+ {
131+ 'appId' : app_id ,
132+ 'bundleId' : app_id ,
133+ ** (options or {}),
134+ },
135+ )
174136
175137 def activate_app (self , app_id : str ) -> Self :
176138 """Activates the application if it is not running
@@ -183,17 +145,13 @@ def activate_app(self, app_id: str) -> Self:
183145 Union['WebDriver', 'Applications']: Self instance
184146 """
185147 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 })
148+ self .execute_script (
149+ ext_name ,
150+ {
151+ 'appId' : app_id ,
152+ 'bundleId' : app_id ,
153+ },
154+ )
197155 return self
198156
199157 def query_app_state (self , app_id : str ) -> int :
@@ -207,22 +165,13 @@ def query_app_state(self, app_id: str) -> int:
207165 class for more details.
208166 """
209167 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' ]
168+ return self .execute_script (
169+ ext_name ,
170+ {
171+ 'appId' : app_id ,
172+ 'bundleId' : app_id ,
173+ },
174+ )
226175
227176 def app_strings (self , language : Union [str , None ] = None , string_file : Union [str , None ] = None ) -> Dict [str , str ]:
228177 """Returns the application strings from the device for the specified
@@ -241,29 +190,7 @@ def app_strings(self, language: Union[str, None] = None, string_file: Union[str,
241190 data ['language' ] = language
242191 if string_file is not None :
243192 data ['stringFile' ] = string_file
244- return self .assert_extension_exists ( ext_name ). execute_script (ext_name , data )
193+ return self .execute_script (ext_name , data )
245194
246195 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- )
196+ pass
0 commit comments