9
9
from gui .elements .button import Button
10
10
from gui .elements .object import QObject
11
11
from gui .elements .scroll import Scroll
12
- from gui .objects_map import names
12
+ from gui .objects_map import names , activity_center_names
13
13
from scripts .tools .image import Image
14
14
15
15
16
16
class ContactRequest :
17
17
18
18
def __init__ (self , obj ):
19
19
self .object = obj
20
- self .contact_request : typing .Optional [Image ] = None
21
- self ._accept_button : typing .Optional [Button ] = None
22
- self ._decline_button : typing .Optional [Button ] = None
23
- self ._notification_request_state : typing .Optional [Image ] = None
20
+ self .contact_request : typing .Optional [str ] = None
21
+ self .accept_button : typing .Optional [Button ] = None
22
+ self .decline_button : typing .Optional [Button ] = None
23
+ self .more_button : typing .Optional [Button ] = None
24
+ self .notification_request_state : typing .Optional [str ] = None
24
25
self .init_ui ()
25
26
26
27
def __repr__ (self ):
27
28
return self .contact_request
28
29
29
30
def init_ui (self ):
31
+ self .accept_button = Button (activity_center_names .activityCenterContactRequestAcceptButton )
32
+ self .decline_button = Button (activity_center_names .activityCenterContactRequestDeclineButton )
33
+ self .more_button = Button (activity_center_names .activityCenterContactRequestMoreButton )
34
+
35
+ # get header text
36
+ try :
37
+ header_obj = QObject (activity_center_names .activityCenterContactRequestHeader )
38
+ self .contact_request = str (header_obj .object .primaryText ) if hasattr (header_obj .object , 'primaryText' ) else None
39
+ except Exception :
40
+ self .contact_request = None
41
+
30
42
for child in walk_children (self .object ):
31
- if str (getattr (child , 'objectName' , '' )) == 'acceptBtn' :
32
- self ._accept_button = Button (real_name = driver .objectMap .realName (child ))
33
- elif str (getattr (child , 'objectName' , '' )) == 'declineBtn' :
34
- self ._decline_button = Button (real_name = driver .objectMap .realName (child ))
35
- elif str (getattr (child , 'objectName' , '' )) == 'StatusMessageHeader_DisplayName' :
36
- self .contact_request = str (child .text )
37
- elif str (getattr (child , 'id' , '' )) == 'textItem' :
38
- self ._notification_request_state = str (child .text )
43
+ if str (getattr (child , 'id' , '' )) == 'textItem' :
44
+ self .notification_request_state = str (child .text )
45
+ break
39
46
40
47
@allure .step ('Accept request' )
41
48
def accept (self ):
42
- assert self ._accept_button is not None , 'Button not found'
43
- self ._accept_button .click ()
49
+ assert self .accept_button is not None , 'Button not found'
50
+ self .accept_button .click ()
44
51
45
52
@allure .step ('Decline request' )
46
53
def decline (self ):
47
- assert self ._decline_button is not None , 'Button not found'
48
- self ._decline_button .click ()
54
+ assert self .decline_button is not None , 'Button not found'
55
+ self .decline_button .click ()
49
56
50
57
51
58
class ActivityCenter (QObject ):
52
59
53
60
def __init__ (self ):
54
- super (ActivityCenter , self ).__init__ (names . activityCenterPopup )
61
+ super ().__init__ (activity_center_names . activityCenterLeftPanel )
55
62
self .activity_center_button = Scroll (names .activityCenterStatusFlatButton )
56
- self .notification_contact_request = QObject (names . o_ActivityNotificationContactRequest )
57
- self .activity_center_panel = QObject ( names . activityCenterTopBar_ActivityCenterPopupTopBarPanel )
58
- self .activity_center_contact_request = QObject ( names . activityCenterContactRequest )
63
+ self .activity_center_contact_request = QObject (activity_center_names . activityCenterContactRequest )
64
+ self .scroll = Scroll ( activity_center_names . activityCenterScrollView )
65
+ self .navigation_button = Button ( activity_center_names . activityCenterNavigationButton )
59
66
60
67
@property
61
68
@allure .step ('Get contact items' )
62
69
def contact_items (self ) -> typing .List [ContactRequest ]:
63
70
return [ContactRequest (item ) for item in driver .findAllObjects (self .activity_center_contact_request .real_name )]
64
71
65
- @allure .step ('Wait until appears {0}' )
66
- def wait_until_appears (self , timeout_msec : int = configs .timeouts .UI_LOAD_TIMEOUT_MSEC ):
67
- self .activity_center_panel .wait_until_appears (timeout_msec )
68
- return self
69
-
72
+ # TODO: navigation buttons are the same so its hard to click a certain button
70
73
@allure .step ('Click activity center button' )
71
74
def click_activity_center_button (self , text : str ):
72
- for button in driver .findAllObjects (self .activity_center_button .real_name ):
73
- if str (getattr (button , 'text' , '' )) == str (text ):
74
- driver .mouseClick (button )
75
- break
75
+ started_at = time .monotonic ()
76
+ self .activity_center_button .real_name ['text' ] = text
77
+
78
+ while not self .activity_center_button .is_visible :
79
+ if time .monotonic () - started_at > 5 :
80
+ raise TimeoutError (f'Activity center button with text "{ text } " not found after { 5 } seconds' )
81
+ self .navigation_button .click ()
82
+ self .activity_center_button .click ()
76
83
return self
77
84
78
85
@allure .step ('Find contact request' )
@@ -89,3 +96,24 @@ def find_contact_request_in_list(
89
96
@allure .step ('Accept contact request' )
90
97
def accept_contact_request (self , request ):
91
98
return request .accept ()
99
+
100
+ def vertical_scroll_down (self , element : QObject , timeout_sec : int = 5 ):
101
+ started_at = time .monotonic ()
102
+ while not element .is_visible :
103
+ driver .mouse .scroll (self .object , self .object .width / 2 , self .object .height / 2 , 0 , - 30 , 1 , 0.1 )
104
+ if time .monotonic () - started_at > timeout_sec :
105
+ raise LookupError (f'Object not found: { element } ' )
106
+
107
+ def horizontal_scroll_right (self , element : QObject , timeout_sec : int = 5 ):
108
+ started_at = time .monotonic ()
109
+ while not element .is_visible :
110
+ driver .mouse .scroll (self .object , self .object .width / 2 , self .object .height / 2 , 30 , 0 , 1 , 0.1 )
111
+ if time .monotonic () - started_at > timeout_sec :
112
+ raise LookupError (f'Object not found: { element } ' )
113
+
114
+ def horizontal_scroll_left (self , element : QObject , timeout_sec : int = 5 ):
115
+ started_at = time .monotonic ()
116
+ while not element .is_visible :
117
+ driver .mouse .scroll (self .object , self .object .width / 2 , self .object .height / 2 , - 30 , 0 , 1 , 0.1 )
118
+ if time .monotonic () - started_at > timeout_sec :
119
+ raise LookupError (f'Object not found: { element } ' )
0 commit comments