Skip to content

Commit c5653a0

Browse files
authored
Merge pull request #481 from mozilla/tracy/bug1949884-switch-to-window
Figured out switch to new window consistently.
2 parents 5d676e0 + 76375fa commit c5653a0

11 files changed

+20
-28
lines changed

modules/page_base.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -681,24 +681,17 @@ def switch_to_new_tab(self) -> Page:
681681
self.driver.switch_to.window(self.driver.window_handles[-1])
682682
return self
683683

684+
def switch_to_new_window(self) -> Page:
685+
"""Switch to the most recently opened window. Can be a standard or private window"""
686+
all_window_handles = self.driver.window_handles
687+
self.driver.switch_to.window(all_window_handles[-1])
688+
return self
689+
684690
def wait_for_num_windows(self, num: int) -> Page:
685691
"""Wait for the number of open tabs + windows to equal given int"""
686692
with self.driver.context(self.driver.CONTEXT_CONTENT):
687693
return self.wait_for_num_tabs(num)
688694

689-
def switch_to_new_window(self) -> Page:
690-
"""Switch to newest window"""
691-
with self.driver.context(self.driver.CONTEXT_CONTENT):
692-
return self.switch_to_new_tab()
693-
694-
def switch_to_new_private_window(self) -> Page:
695-
"Switch to new private window"
696-
non_private_window = self.driver.current_window_handle
697-
original_window_idx = self.driver.window_handles.index(non_private_window)
698-
private_window = self.driver.window_handles[1 - original_window_idx]
699-
self.driver.switch_to.window(private_window)
700-
return self
701-
702695
def switch_to_frame(self, frame: str, labels=[]) -> Page:
703696
"""Switch to inline document frame"""
704697
with self.driver.context(self.driver.CONTEXT_CHROME):

tests/security_and_privacy/test_cookies_not_saved_private_browsing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def test_cookies_not_saved_private_browsing(driver: Firefox):
2424

2525
# Open new private window
2626
panel_ui.open_private_window()
27-
nav.switch_to_new_private_window()
27+
nav.switch_to_new_window()
2828

2929
# Open the Google page and perform a search
3030
google_search.open()

tests/security_and_privacy/test_downloads_from_private_not_leaked.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ def test_downloads_from_private_not_leaked(driver: Firefox, delete_files, screen
3535

3636
# We've deleted relevant downloads_file just to be safe
3737
non_private_window = driver.current_window_handle
38-
panelui = PanelUi(driver).open_panel_menu()
38+
panelui = PanelUi(driver)
39+
panelui.open_panel_menu()
3940
panelui.select_panel_setting("new-private-window-option")
40-
panelui.wait_for_num_windows(2)
4141

4242
nav = Navigation(driver)
43-
nav.switch_to_new_private_window()
43+
nav.switch_to_new_window()
4444

4545
about_downloads = AboutDownloads(driver)
4646
about_downloads.open()

tests/security_and_privacy/test_https_enabled_private_browsing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def test_https_first_mode_in_private_browsing(driver: Firefox):
2727
hamburger.open_private_window()
2828

2929
nav = Navigation(driver)
30-
nav.switch_to_new_private_window()
30+
nav.switch_to_new_window()
3131
driver.get(HTTP_SITE)
3232

3333
# Wait for the URL to be redirected to HTTPS

tests/security_and_privacy/test_open_link_in_private_window.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ def test_open_link_in_private_window(driver: Firefox):
2424
sleep(1)
2525
context_menu.click_and_hide_menu("context-menu-open-link-in-new-private-window")
2626

27-
nav.wait_for_num_windows(2)
28-
nav.switch_to_new_private_window()
27+
nav.switch_to_new_window()
2928
sleep(1)
3029
with driver.context(driver.CONTEXT_CHROME):
3130
nav.title_contains("Private Browsing")

tests/security_and_privacy/test_private_browser_password_doorhanger.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def test_no_password_doorhanger_private_browsing(driver: Firefox):
3030

3131
# Open Private Window
3232
panel_ui.open_private_window()
33-
nav.switch_to_new_private_window()
33+
nav.switch_to_new_window()
3434

3535
# Open the form, fill the user and password
3636
login_auto_fill.open()

tests/security_and_privacy/test_private_session_awesome_bar_exclusion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def test_websites_visited_in_private_browser_not_displayed_in_awesome_bar(
3030
panel_ui = PanelUi(driver)
3131

3232
panel_ui.open_private_window()
33-
panel_ui.switch_to_new_private_window()
33+
panel_ui.switch_to_new_window()
3434

3535
for url in WEBSITES:
3636
driver.get(url)

tests/security_and_privacy/test_private_session_history_exclusion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test_websites_visited_in_private_browser_not_displayed_in_history(driver: Fi
2929

3030
panel_ui = PanelUi(driver).open()
3131
panel_ui.open_private_window()
32-
panel_ui.switch_to_new_private_window()
32+
panel_ui.switch_to_new_window()
3333

3434
driver.get(YOUTUBE_URL)
3535
driver.get(FACEBOOK_URL)

tests/security_and_privacy/test_private_window_from_panelui.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ def test_case():
1212

1313
def test_private_window_from_panelui(driver: Firefox):
1414
"""C101660 - Private Browsing can be successfully opened via the Hamburger menu"""
15-
panelui = PanelUi(driver).open_panel_menu()
15+
panelui = PanelUi(driver)
16+
panelui.open_panel_menu()
1617
panelui.select_panel_setting("new-private-window-option")
17-
panelui.wait_for_num_windows(2)
18-
panelui.switch_to_new_private_window()
18+
panelui.switch_to_new_window()
1919
AboutPrivatebrowsing(driver).wait_for_page_to_load()

tests/security_and_privacy/test_third_party_content_blocked_private_browsing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def test_third_party_content_blocked_private_browsing_cross_site(driver: Firefox
3636

3737
# open the new window
3838
panel_ui.open_private_window()
39-
nav.switch_to_new_private_window()
39+
nav.switch_to_new_window()
4040

4141
# open the website, ensure the blocking is taking place by continuously refreshing website until indicated
4242
tracker_website.open()

0 commit comments

Comments
 (0)