@@ -35,10 +35,10 @@ def __init__(self):
35
35
36
36
SCROLL_DIRECTION = ScrollDirection ()
37
37
38
+ @BasePage .context_chrome
38
39
def new_tab_by_button (self ) -> BasePage :
39
40
"""Use the New Tab button (+) to open a new tab"""
40
- with self .driver .context (self .driver .CONTEXT_CHROME ):
41
- self .get_element ("newtab-button" ).click ()
41
+ self .get_element ("newtab-button" ).click ()
42
42
return self
43
43
44
44
def new_tab_by_keys (self , sys_platform : str ) -> BasePage :
@@ -77,60 +77,59 @@ def reopen_closed_tab_by_keys(self, sys_platform: str) -> BasePage:
77
77
).key_up (Keys .SHIFT ).key_up (Keys .CONTROL ).perform ()
78
78
return self
79
79
80
+ @BasePage .context_chrome
80
81
def click_tab_by_title (self , title : str ) -> BasePage :
81
82
"""Given a full page title, click the corresponding tab"""
82
- with self .driver .context (self .driver .CONTEXT_CHROME ):
83
- self .get_element ("tab-by-title" , labels = [title ]).click ()
83
+ self .get_element ("tab-by-title" , labels = [title ]).click ()
84
84
return self
85
85
86
- def get_tab_by_title (self , title : str ) -> BasePage :
86
+ @BasePage .context_chrome
87
+ def get_tab_by_title (self , title : str ) -> WebElement :
87
88
"""Given a full page title, return the corresponding tab"""
88
- with self .driver .context (self .driver .CONTEXT_CHROME ):
89
- return self .get_element ("tab-by-title" , labels = [title ])
89
+ return self .get_element ("tab-by-title" , labels = [title ])
90
90
91
+ @BasePage .context_chrome
91
92
def click_tab_by_index (self , index : int ) -> BasePage :
92
93
"""Given a tab index (int), click the corresponding tab"""
93
- with self .driver .context (self .driver .CONTEXT_CHROME ):
94
- self .get_element ("tab-by-index" , labels = [str (index )]).click ()
94
+ self .get_element ("tab-by-index" , labels = [str (index )]).click ()
95
95
return self
96
96
97
+ @BasePage .context_chrome
97
98
def get_tab (self , identifier : Union [str , int ]) -> Union [WebElement , None ]:
98
99
"""Return a tab root based on either a title or an index"""
99
- with self .driver .context (self .driver .CONTEXT_CHROME ):
100
- if isinstance (identifier , int ):
101
- tab = self .get_element ("tab-by-index" , labels = [str (identifier )])
102
- elif isinstance (identifier , str ):
103
- tab = self .get_element ("tab-by-title" , labels = [identifier ])
104
- else :
105
- # if we get an unexpected type, we shouldn't assume that the user wants sys exit
106
- # but we have to cause problems for them nonetheless
107
- assert False , "Error getting tab root"
108
- tab = None
109
- return tab
100
+ if isinstance (identifier , int ):
101
+ tab = self .get_element ("tab-by-index" , labels = [str (identifier )])
102
+ elif isinstance (identifier , str ):
103
+ tab = self .get_element ("tab-by-title" , labels = [identifier ])
104
+ else :
105
+ # if we get an unexpected type, we shouldn't assume that the user wants sys exit,
106
+ # but we have to cause problems for them nonetheless
107
+ assert False , "Error getting tab root"
108
+ return tab
110
109
110
+ @BasePage .context_chrome
111
111
def is_pinned (self , tab_root : WebElement ) -> bool :
112
112
"""Is this tab pinned?"""
113
- with self .driver .context (self .driver .CONTEXT_CHROME ):
114
- pinned = tab_root .get_attribute ("pinned" )
115
- if pinned in ["true" , "false" ]:
116
- return pinned == "true"
117
- else :
118
- assert False , "Error checking tab pinned status"
113
+ pinned = tab_root .get_attribute ("pinned" )
114
+ if pinned in ["true" , "false" ]:
115
+ return pinned == "true"
116
+ else :
117
+ assert False , "Error checking tab pinned status"
119
118
119
+ @BasePage .context_chrome
120
120
def click_tab_mute_button (self , identifier : Union [str , int ]) -> BasePage :
121
121
"""Click the tab icon overlay, no matter what's happening with media"""
122
122
logging .info (f"toggling tab mute for { identifier } " )
123
123
tab = self .get_tab (identifier )
124
- with self .driver .context (self .driver .CONTEXT_CHROME ):
125
- self .actions .move_to_element (tab ).perform ()
126
- self .get_element ("tab-icon-overlay" ).click ()
124
+ self .actions .move_to_element (tab ).perform ()
125
+ self .get_element ("tab-icon-overlay" ).click ()
127
126
return self
128
127
128
+ @BasePage .context_chrome
129
129
def get_tab_title (self , tab_element : WebElement ) -> str :
130
130
"""Given a tab root element, get the title text of the tab"""
131
- with self .driver .context (self .driver .CONTEXT_CHROME ):
132
- tab_label = tab_element .find_element (* self .get_selector ("tab-title" ))
133
- return tab_label .text
131
+ tab_label = tab_element .find_element (* self .get_selector ("tab-title" ))
132
+ return tab_label .text
134
133
135
134
def expect_tab_sound_status (
136
135
self , identifier : Union [str , int ], status : MediaStatus
@@ -147,35 +146,35 @@ def expect_title_contains(self, text: str) -> BasePage:
147
146
self .expect (EC .title_contains (text ))
148
147
return self
149
148
149
+ @BasePage .context_chrome
150
150
def open_all_tabs_list (self ) -> BasePage :
151
151
"""Click the Tab Visibility / List All Tabs button"""
152
- with self .driver .context (self .driver .CONTEXT_CHROME ):
153
- self .get_element ("list-all-tabs-button" ).click ()
154
- self .expect (
155
- EC .text_to_be_present_in_element_attribute (
156
- self .get_selector ("list-all-tabs-button" ), "open" , "true"
157
- )
152
+ self .get_element ("list-all-tabs-button" ).click ()
153
+ self .expect (
154
+ EC .text_to_be_present_in_element_attribute (
155
+ self .get_selector ("list-all-tabs-button" ), "open" , "true"
158
156
)
157
+ )
159
158
return self
160
159
160
+ @BasePage .context_chrome
161
161
def count_tabs_in_all_tabs_menu (self ) -> int :
162
162
"""Return the number of entries in the all tabs menu"""
163
- with self .driver .context (self .driver .CONTEXT_CHROME ):
164
- all_tabs_menu = self .get_element ("all-tabs-menu" )
165
- all_tabs_entries = all_tabs_menu .find_elements (
166
- self .get_selector ("all-tabs-entry" )
167
- )
163
+ all_tabs_menu = self .get_element ("all-tabs-menu" )
164
+ all_tabs_entries = all_tabs_menu .find_elements (
165
+ self .get_selector ("all-tabs-entry" )
166
+ )
168
167
return len (all_tabs_entries )
169
168
169
+ @BasePage .context_chrome
170
170
def scroll_tabs (self , direction : ScrollDirection ) -> BasePage :
171
171
"""Scroll tabs in tab bar using the < and > scroll buttons"""
172
172
logging .info (f"Scrolling tabs { direction } " )
173
- with self .driver .context (self .driver .CONTEXT_CHROME ):
174
- try :
175
- scroll_button = self .get_element (f"tab-scrollbox-{ direction } -button" )
176
- scroll_button .click ()
177
- except NoSuchElementException :
178
- logging .info ("Could not scroll any further!" )
173
+ try :
174
+ scroll_button = self .get_element (f"tab-scrollbox-{ direction } -button" )
175
+ scroll_button .click ()
176
+ except NoSuchElementException :
177
+ logging .info ("Could not scroll any further!" )
179
178
return self
180
179
181
180
def get_text_of_all_tabs_entry (self , selected = False , index = 0 ) -> str :
@@ -238,6 +237,7 @@ def get_location_of_all_tabs_entry(self, selected=False, index=0) -> dict:
238
237
entry = entries [index ]
239
238
return entry .find_element (By .CLASS_NAME , "all-tabs-button" ).location
240
239
240
+ @BasePage .context_chrome
241
241
def scroll_on_all_tabs_menu (self , down = True , pixels = 200 ) -> BasePage :
242
242
"""
243
243
Scroll the List All Tabs menu down or up.
@@ -253,30 +253,29 @@ def scroll_on_all_tabs_menu(self, down=True, pixels=200) -> BasePage:
253
253
pixels: int
254
254
The number of pixels to scroll the bar
255
255
"""
256
- with self .driver . context ( self . driver . CONTEXT_CHROME ):
257
- menu = self . get_element ( "all-tabs- menu" )
258
- logging .info (f"menu location : { menu .location } " )
259
- logging . info ( f"menu size: { menu . size } " )
260
-
261
- # HACK: Can't figure out what the scrollbox selector is, but it's ~4 pixels
262
- # off the edge of the menu.
263
- x_start = ( menu . size [ "width" ] / 2.0 ) - 4.0
264
- # +Y is down, -Y is up
265
- sign = 1 if down else - 1
266
-
267
- self .actions .move_to_element_with_offset ( menu , x_start , 0 )
268
- self .actions .click_and_hold ( )
269
- self .actions .move_by_offset ( 0 , ( sign * pixels ) )
270
- self .actions .release ()
271
- self . actions . perform ()
272
-
256
+ menu = self .get_element ( "all-tabs-menu" )
257
+ logging . info ( f" menu location: { menu . location } " )
258
+ logging .info (f"menu size : { menu .size } " )
259
+
260
+ # HACK: Can't figure out what the scrollbox selector is, but it's ~4 pixels
261
+ # off the edge of the menu.
262
+ x_start = ( menu . size [ "width" ] / 2.0 ) - 4.0
263
+ # +Y is down, -Y is up
264
+ sign = 1 if down else - 1
265
+
266
+ self . actions . move_to_element_with_offset ( menu , x_start , 0 )
267
+ self .actions .click_and_hold ( )
268
+ self .actions .move_by_offset ( 0 , ( sign * pixels ) )
269
+ self .actions .release ( )
270
+ self .actions .perform ()
271
+
272
+ @ BasePage . context_chrome
273
273
def close_tab (self , tab : WebElement ) -> BasePage :
274
274
"""
275
275
Given the index of the tab, it closes that tab.
276
276
"""
277
277
# cur_tab = self.click_tab_by_index(index)
278
- with self .driver .context (self .driver .CONTEXT_CHROME ):
279
- self .get_element ("tab-x-icon" , parent_element = tab ).click ()
278
+ self .get_element ("tab-x-icon" , parent_element = tab ).click ()
280
279
return self
281
280
282
281
def open_web_page_in_new_tab (self , web_page : BasePage , num_tabs : int ) -> BasePage :
0 commit comments