File tree Expand file tree Collapse file tree 4 files changed +44
-5
lines changed Expand file tree Collapse file tree 4 files changed +44
-5
lines changed Original file line number Diff line number Diff line change @@ -32,8 +32,8 @@ def test_start_activity_other_app(self) -> None:
32
32
self .driver .start_activity (APIDEMO_PKG_NAME , ".ApiDemos" )
33
33
self ._assert_activity_contains ('Demos' )
34
34
35
- self .driver .start_activity ("com.android.calculator2 " , ".Calculator " )
36
- self ._assert_activity_contains ('Calculator ' )
35
+ self .driver .start_activity ("com.google. android.deskclock " , "com.android.deskclock.DeskClock " )
36
+ self ._assert_activity_contains ('Clock ' )
37
37
38
38
def _assert_activity_contains (self , activity : str ) -> None :
39
39
current = self .driver .current_activity
Original file line number Diff line number Diff line change 14
14
15
15
from appium .webdriver .applicationstate import ApplicationState
16
16
from test .functional .ios .helper .test_helper import BaseTestCase
17
+ from test .functional .test_helper import wait_for_condition
17
18
18
19
from .helper import desired_capabilities
19
20
@@ -25,6 +26,8 @@ def test_app_management(self) -> None:
25
26
return
26
27
assert self .driver .query_app_state (desired_capabilities .BUNDLE_ID ) == ApplicationState .RUNNING_IN_FOREGROUND
27
28
self .driver .background_app (- 1 )
28
- assert self .driver .query_app_state (desired_capabilities .BUNDLE_ID ) < ApplicationState .RUNNING_IN_FOREGROUND
29
+ assert wait_for_condition (
30
+ lambda : self .driver .query_app_state (desired_capabilities .BUNDLE_ID ) < ApplicationState .RUNNING_IN_FOREGROUND
31
+ ), "The app didn't go to background."
29
32
self .driver .activate_app (desired_capabilities .BUNDLE_ID )
30
33
assert self .driver .query_app_state (desired_capabilities .BUNDLE_ID ) == ApplicationState .RUNNING_IN_FOREGROUND
Original file line number Diff line number Diff line change 20
20
from appium import webdriver
21
21
from appium .webdriver .applicationstate import ApplicationState
22
22
from test .functional .ios .helper .test_helper import BaseTestCase
23
- from test .functional .test_helper import get_available_from_port_range
23
+ from test .functional .test_helper import get_available_from_port_range , wait_for_condition
24
24
25
25
from ..test_helper import is_ci
26
26
from .helper import desired_capabilities
@@ -60,7 +60,11 @@ def test_app_management(self) -> None:
60
60
return
61
61
assert self .driver .query_app_state (desired_capabilities .BUNDLE_ID ) == ApplicationState .RUNNING_IN_FOREGROUND
62
62
self .driver .background_app (- 1 )
63
- assert self .driver .query_app_state (desired_capabilities .BUNDLE_ID ) < ApplicationState .RUNNING_IN_FOREGROUND
63
+ print (self .driver .query_app_state (desired_capabilities .BUNDLE_ID ) < ApplicationState .RUNNING_IN_FOREGROUND )
64
+ assert wait_for_condition (
65
+ lambda : self .driver .query_app_state (desired_capabilities .BUNDLE_ID )
66
+ < ApplicationState .RUNNING_IN_FOREGROUND ,
67
+ ), "The app didn't go to background."
64
68
self .driver .activate_app (desired_capabilities .BUNDLE_ID )
65
69
assert self .driver .query_app_state (desired_capabilities .BUNDLE_ID ) == ApplicationState .RUNNING_IN_FOREGROUND
66
70
Original file line number Diff line number Diff line change 1
1
import os
2
2
import socket
3
+ import time
4
+ from time import sleep
5
+ from typing import Any , Callable
3
6
4
7
5
8
class NoAvailablePortError (Exception ):
@@ -37,3 +40,32 @@ def is_ci() -> bool:
37
40
`True` if current executions is on CI
38
41
"""
39
42
return os .getenv ('CI' , 'false' ) == 'true'
43
+
44
+
45
+ def wait_for_condition (method : Callable , timeout_sec : float = 5 , interval_sec : float = 1 ) -> Any :
46
+ """Wait while `method` returns the built-in objects considered false
47
+
48
+ https://docs.python.org/3/library/stdtypes.html#truth-value-testing
49
+
50
+ Args:
51
+ method: The target method to be waited
52
+ timeout: The timeout to be waited (sec.)
53
+ interval_sec: The interval for wait (sec.)
54
+
55
+ Returns:
56
+ Any: value which `method` returns
57
+
58
+ Raises:
59
+ ValueError: When interval isn't more than 0
60
+
61
+ """
62
+ if interval_sec < 0 :
63
+ raise ValueError ('interval_sec needs to be not less than 0' )
64
+
65
+ started = time .time ()
66
+ while time .time () - started <= timeout_sec :
67
+ result = method ()
68
+ if result :
69
+ break
70
+ sleep (interval_sec )
71
+ return result
You can’t perform that action at this time.
0 commit comments