diff --git a/modules/browser_object_tabbar.py b/modules/browser_object_tabbar.py index 370be901c..b8ba3556c 100644 --- a/modules/browser_object_tabbar.py +++ b/modules/browser_object_tabbar.py @@ -316,3 +316,13 @@ def open_multiple_tabs_with_pages(self, pages: list) -> "TabBar": else: page.open() return self + + @BasePage.context_chrome + def verify_tab_focus_cycle(self, num_tabs: int): + """Go through all the tabs and ensure the focus changes correctly.""" + for i in range(1, num_tabs + 2): + target_tab = self.get_tab(i) + self.click_on(target_tab) + self.custom_wait(timeout=3).until( + lambda d: target_tab.get_attribute("visuallyselected") == "" + ) diff --git a/tests/tabs/test_active_tab.py b/tests/tabs/test_active_tab.py index 382c89b14..818227626 100644 --- a/tests/tabs/test_active_tab.py +++ b/tests/tabs/test_active_tab.py @@ -4,6 +4,9 @@ from modules.browser_object import TabBar +NUM_TABS = 5 + + @pytest.fixture() def test_case(): return "134646" @@ -14,18 +17,13 @@ def test_active_tab(driver: Firefox): """ C134646, ensures that the selected tab is highlighted """ + + # Instantiate objects tabs = TabBar(driver) - num_tabs = 5 # Open 5 tabs - for i in range(num_tabs): + for i in range(NUM_TABS): tabs.new_tab_by_button() # Go through all the tabs and ensure the focus is correct - for i in range(1, num_tabs + 2): - with driver.context(driver.CONTEXT_CHROME): - target_tab = tabs.get_tab(i) - target_tab.click() - tabs.custom_wait(timeout=3).until( - lambda d: target_tab.get_attribute("visuallyselected") == "" - ) + tabs.verify_tab_focus_cycle(NUM_TABS) diff --git a/tests/tabs/test_close_pinned_tab_via_mouse.py b/tests/tabs/test_close_pinned_tab_via_mouse.py index 0fe428b73..4fd077d29 100644 --- a/tests/tabs/test_close_pinned_tab_via_mouse.py +++ b/tests/tabs/test_close_pinned_tab_via_mouse.py @@ -16,25 +16,25 @@ def test_close_pinned_tab_via_middle_click(driver: Firefox): C134726 - Verify middle-clicking pinned tab will close it """ + # Instantiate objects example = ExamplePage(driver) - example.open() tabs = TabBar(driver) tab_menu = ContextMenu(driver) # Open 2 new tabs + example.open() for _ in range(2): tabs.new_tab_by_button() tabs.wait_for_num_tabs(3) # Pin the first tab - with driver.context(driver.CONTEXT_CHROME): - first_tab = tabs.get_tab(1) - tabs.context_click(first_tab) - tab_menu.click_and_hide_menu("context-menu-pin-tab") - assert tabs.is_pinned(first_tab), "Expected the first tab to be pinned" - - # Middle-click the pinned tab to close it - tabs.middle_click(first_tab) + first_tab = tabs.get_tab(1) + tabs.context_click(first_tab) + tab_menu.click_and_hide_menu("context-menu-pin-tab") + assert tabs.is_pinned(first_tab), "Expected the first tab to be pinned" + + # Middle-click the pinned tab to close it + tabs.middle_click(first_tab) # Verify pinned tab was closed and 2 tabs remain tabs.wait_for_num_tabs(2) diff --git a/tests/tabs/test_close_tab_through_middle_mouse_click.py b/tests/tabs/test_close_tab_through_middle_mouse_click.py index 574155d96..657ab0062 100644 --- a/tests/tabs/test_close_tab_through_middle_mouse_click.py +++ b/tests/tabs/test_close_tab_through_middle_mouse_click.py @@ -16,19 +16,19 @@ def test_close_tab_through_middle_mouse_click(driver: Firefox): C134645 - Verify that middle clicking a tab will close it """ + # Instantiate objects example = ExamplePage(driver) tabs = TabBar(driver) - example.open() # Open 2 mnew tabs for a total of 3 + example.open() for _ in range(2): tabs.new_tab_by_button() tabs.wait_for_num_tabs(3) # Ensure each tab exists and middle-click to close it for i in range(3, 1, -1): - with driver.context(driver.CONTEXT_CHROME): - tab_to_close = tabs.get_tab(i) - assert tab_to_close is not None, f"Expected tab index {i} to exist" - tabs.middle_click(tab_to_close) + tab_to_close = tabs.get_tab(i) + assert tab_to_close is not None, f"Expected tab index {i} to exist" + tabs.middle_click(tab_to_close) tabs.wait_for_num_tabs(i - 1) diff --git a/tests/tabs/test_display_customize_button.py b/tests/tabs/test_display_customize_button.py index 38e14fdae..6b47e5b4c 100644 --- a/tests/tabs/test_display_customize_button.py +++ b/tests/tabs/test_display_customize_button.py @@ -18,15 +18,14 @@ def test_customize_button_displayed_in_tab_bar(driver: Firefox): and the Customize tab persists when switching tabs. """ + # Instantiate objects panel_ui = PanelUi(driver) tabs = TabBar(driver) custom_page = CustomizeFirefox(driver) - - # Open an initial example page example = ExamplePage(driver) - example.open() # Open customize firefox toolbar tab + example.open() panel_ui.open_panel_menu() panel_ui.navigate_to_customize_toolbar() diff --git a/tests/tabs/test_mute_tabs.py b/tests/tabs/test_mute_tabs.py index 5e6083354..80aa03f9c 100644 --- a/tests/tabs/test_mute_tabs.py +++ b/tests/tabs/test_mute_tabs.py @@ -28,13 +28,17 @@ def add_to_prefs_list(): @pytest.mark.audio def test_mute_unmute_tab(screenshot, driver: Firefox, video_url: str): """C134719, test that tabs can be muted and unmuted""" + + # Instantiate objects tabs = TabBar(driver) + + # Open the video URL and verify the page title contains "mov_bbb.mp4" driver.get(video_url) tabs.expect(EC.title_contains("mov_bbb.mp4")) - with driver.context(driver.CONTEXT_CHROME): - tabs.expect_tab_sound_status(1, tabs.MEDIA_STATUS.PLAYING) - tabs.click_tab_mute_button(1) - tabs.expect_tab_sound_status(1, tabs.MEDIA_STATUS.MUTED) - tabs.click_tab_mute_button(1) - tabs.expect_tab_sound_status(1, tabs.MEDIA_STATUS.PLAYING) + # Check that the tab is currently playing audio and click on mute + tabs.expect_tab_sound_status(1, tabs.MEDIA_STATUS.PLAYING) + tabs.click_tab_mute_button(1) + tabs.expect_tab_sound_status(1, tabs.MEDIA_STATUS.MUTED) + tabs.click_tab_mute_button(1) + tabs.expect_tab_sound_status(1, tabs.MEDIA_STATUS.PLAYING) diff --git a/tests/tabs/test_navigation_multiple_tabs.py b/tests/tabs/test_navigation_multiple_tabs.py index 5040e9bdc..1e01d3d90 100644 --- a/tests/tabs/test_navigation_multiple_tabs.py +++ b/tests/tabs/test_navigation_multiple_tabs.py @@ -1,10 +1,10 @@ import logging - import pytest from selenium.webdriver import Firefox - from modules.browser_object import TabBar +NUM_TABS = 20 + @pytest.fixture() def test_case(): @@ -14,11 +14,11 @@ def test_case(): def test_navigation_multiple_tabs(driver: Firefox): """C134647 - Verify that navigation through multiple tabs is allowed""" + # Instantiate objects tabs = TabBar(driver) - num_tabs = 20 # Open multiple tabs - for _ in range(num_tabs): + for _ in range(NUM_TABS): tabs.new_tab_by_button() with driver.context(driver.CONTEXT_CHROME): diff --git a/tests/tabs/test_open_bookmark_in_new_tab.py b/tests/tabs/test_open_bookmark_in_new_tab.py index 791296211..70faab519 100644 --- a/tests/tabs/test_open_bookmark_in_new_tab.py +++ b/tests/tabs/test_open_bookmark_in_new_tab.py @@ -14,9 +14,11 @@ def test_case(): BOOKMARK_URL = "https://www.youtube.com/" BOOKMARK_TITLE = "YouTube" +EXPECTED_TEST = "youtube" def test_open_bookmark_in_new_tab(driver: Firefox): + """ C134460: Verify that New Tabs can be opened by right clicking and selecting new tab from the bookmarks. """ @@ -39,6 +41,6 @@ def test_open_bookmark_in_new_tab(driver: Firefox): tabs.wait_for_num_tabs(3) driver.switch_to.window(driver.window_handles[-1]) - WebDriverWait(driver, 5).until(EC.url_contains("youtube")) - assert "youtube" in driver.current_url - page.url_contains("youtube") + WebDriverWait(driver, 5).until(EC.url_contains(EXPECTED_TEST)) + assert EXPECTED_TEST in driver.current_url + page.url_contains(EXPECTED_TEST) diff --git a/tests/tabs/test_open_new_tab.py b/tests/tabs/test_open_new_tab.py index 4e3a6af66..5da428fee 100644 --- a/tests/tabs/test_open_new_tab.py +++ b/tests/tabs/test_open_new_tab.py @@ -5,6 +5,10 @@ from modules.browser_object import TabBar +URL = "about:robots" +EXPECTED_TEXT = "Firefox" + + @pytest.fixture() def test_case(): return "134453" @@ -14,11 +18,15 @@ def test_open_new_tab_plus(driver: Firefox): """ C134453 - A new tab can be opened from the dedicated button ("+") """ + + # Instantiate object browser = TabBar(driver) - driver.get("about:robots") + + # Open page and check a new tab can be opened from the dedicated button ("+") + driver.get(URL) browser.set_chrome_context() browser.new_tab_by_button() - browser.expect(EC.title_contains("Firefox")) - assert "Firefox" in driver.title, ( + browser.expect(EC.title_contains(EXPECTED_TEXT)) + assert EXPECTED_TEXT in driver.title, ( f"Expected title to contain 'Firefox', but got '{driver.title}'" ) diff --git a/tests/tabs/test_open_new_tab_keys.py b/tests/tabs/test_open_new_tab_keys.py index f2c2aaf58..4b01735e4 100644 --- a/tests/tabs/test_open_new_tab_keys.py +++ b/tests/tabs/test_open_new_tab_keys.py @@ -1,10 +1,13 @@ import pytest from selenium.webdriver import Firefox from selenium.webdriver.support import expected_conditions as EC - from modules.browser_object import TabBar +URL = "about:robots" +EXPECTED_TEXT = "Firefox" + + @pytest.fixture() def test_case(): return "134442" @@ -14,11 +17,15 @@ def test_open_new_tab_via_keyboard(driver: Firefox, sys_platform: str): """ C134442 - A new tab can be opened via keyboard combinations """ + + # Instantiate object browser = TabBar(driver) - driver.get("about:robots") + + # Open page and check a new tab can be opened via keyboard combinations + driver.get(URL) browser.set_chrome_context() browser.new_tab_by_keys(sys_platform) - browser.expect(EC.title_contains("Firefox")) - assert "Firefox" in driver.title, ( + browser.expect(EC.title_contains(EXPECTED_TEXT)) + assert EXPECTED_TEXT in driver.title, ( f"Expected title to contain 'Firefox', but got '{driver.title}'" )