Skip to content

Commit eb94d77

Browse files
sv-hyacoubHani YacoubHani Yacoub
authored
Hani/refactor tabs (#820)
* Refactor 1 * Batch 2 --------- Co-authored-by: Hani Yacoub <[email protected]> Co-authored-by: Hani Yacoub <[email protected]>
1 parent 3aad3bf commit eb94d77

10 files changed

+74
-46
lines changed

modules/browser_object_tabbar.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,3 +316,13 @@ def open_multiple_tabs_with_pages(self, pages: list) -> "TabBar":
316316
else:
317317
page.open()
318318
return self
319+
320+
@BasePage.context_chrome
321+
def verify_tab_focus_cycle(self, num_tabs: int):
322+
"""Go through all the tabs and ensure the focus changes correctly."""
323+
for i in range(1, num_tabs + 2):
324+
target_tab = self.get_tab(i)
325+
self.click_on(target_tab)
326+
self.custom_wait(timeout=3).until(
327+
lambda d: target_tab.get_attribute("visuallyselected") == ""
328+
)

tests/tabs/test_active_tab.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
from modules.browser_object import TabBar
55

66

7+
NUM_TABS = 5
8+
9+
710
@pytest.fixture()
811
def test_case():
912
return "134646"
@@ -14,18 +17,13 @@ def test_active_tab(driver: Firefox):
1417
"""
1518
C134646, ensures that the selected tab is highlighted
1619
"""
20+
21+
# Instantiate objects
1722
tabs = TabBar(driver)
18-
num_tabs = 5
1923

2024
# Open 5 tabs
21-
for i in range(num_tabs):
25+
for i in range(NUM_TABS):
2226
tabs.new_tab_by_button()
2327

2428
# Go through all the tabs and ensure the focus is correct
25-
for i in range(1, num_tabs + 2):
26-
with driver.context(driver.CONTEXT_CHROME):
27-
target_tab = tabs.get_tab(i)
28-
target_tab.click()
29-
tabs.custom_wait(timeout=3).until(
30-
lambda d: target_tab.get_attribute("visuallyselected") == ""
31-
)
29+
tabs.verify_tab_focus_cycle(NUM_TABS)

tests/tabs/test_close_pinned_tab_via_mouse.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,25 @@ def test_close_pinned_tab_via_middle_click(driver: Firefox):
1616
C134726 - Verify middle-clicking pinned tab will close it
1717
"""
1818

19+
# Instantiate objects
1920
example = ExamplePage(driver)
20-
example.open()
2121
tabs = TabBar(driver)
2222
tab_menu = ContextMenu(driver)
2323

2424
# Open 2 new tabs
25+
example.open()
2526
for _ in range(2):
2627
tabs.new_tab_by_button()
2728
tabs.wait_for_num_tabs(3)
2829

2930
# Pin the first tab
30-
with driver.context(driver.CONTEXT_CHROME):
31-
first_tab = tabs.get_tab(1)
32-
tabs.context_click(first_tab)
33-
tab_menu.click_and_hide_menu("context-menu-pin-tab")
34-
assert tabs.is_pinned(first_tab), "Expected the first tab to be pinned"
35-
36-
# Middle-click the pinned tab to close it
37-
tabs.middle_click(first_tab)
31+
first_tab = tabs.get_tab(1)
32+
tabs.context_click(first_tab)
33+
tab_menu.click_and_hide_menu("context-menu-pin-tab")
34+
assert tabs.is_pinned(first_tab), "Expected the first tab to be pinned"
35+
36+
# Middle-click the pinned tab to close it
37+
tabs.middle_click(first_tab)
3838

3939
# Verify pinned tab was closed and 2 tabs remain
4040
tabs.wait_for_num_tabs(2)

tests/tabs/test_close_tab_through_middle_mouse_click.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@ def test_close_tab_through_middle_mouse_click(driver: Firefox):
1616
C134645 - Verify that middle clicking a tab will close it
1717
"""
1818

19+
# Instantiate objects
1920
example = ExamplePage(driver)
2021
tabs = TabBar(driver)
21-
example.open()
2222

2323
# Open 2 mnew tabs for a total of 3
24+
example.open()
2425
for _ in range(2):
2526
tabs.new_tab_by_button()
2627
tabs.wait_for_num_tabs(3)
2728

2829
# Ensure each tab exists and middle-click to close it
2930
for i in range(3, 1, -1):
30-
with driver.context(driver.CONTEXT_CHROME):
31-
tab_to_close = tabs.get_tab(i)
32-
assert tab_to_close is not None, f"Expected tab index {i} to exist"
33-
tabs.middle_click(tab_to_close)
31+
tab_to_close = tabs.get_tab(i)
32+
assert tab_to_close is not None, f"Expected tab index {i} to exist"
33+
tabs.middle_click(tab_to_close)
3434
tabs.wait_for_num_tabs(i - 1)

tests/tabs/test_display_customize_button.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@ def test_customize_button_displayed_in_tab_bar(driver: Firefox):
1818
and the Customize tab persists when switching tabs.
1919
"""
2020

21+
# Instantiate objects
2122
panel_ui = PanelUi(driver)
2223
tabs = TabBar(driver)
2324
custom_page = CustomizeFirefox(driver)
24-
25-
# Open an initial example page
2625
example = ExamplePage(driver)
27-
example.open()
2826

2927
# Open customize firefox toolbar tab
28+
example.open()
3029
panel_ui.open_panel_menu()
3130
panel_ui.navigate_to_customize_toolbar()
3231

tests/tabs/test_mute_tabs.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,17 @@ def add_to_prefs_list():
2828
@pytest.mark.audio
2929
def test_mute_unmute_tab(screenshot, driver: Firefox, video_url: str):
3030
"""C134719, test that tabs can be muted and unmuted"""
31+
32+
# Instantiate objects
3133
tabs = TabBar(driver)
34+
35+
# Open the video URL and verify the page title contains "mov_bbb.mp4"
3236
driver.get(video_url)
3337
tabs.expect(EC.title_contains("mov_bbb.mp4"))
3438

35-
with driver.context(driver.CONTEXT_CHROME):
36-
tabs.expect_tab_sound_status(1, tabs.MEDIA_STATUS.PLAYING)
37-
tabs.click_tab_mute_button(1)
38-
tabs.expect_tab_sound_status(1, tabs.MEDIA_STATUS.MUTED)
39-
tabs.click_tab_mute_button(1)
40-
tabs.expect_tab_sound_status(1, tabs.MEDIA_STATUS.PLAYING)
39+
# Check that the tab is currently playing audio and click on mute
40+
tabs.expect_tab_sound_status(1, tabs.MEDIA_STATUS.PLAYING)
41+
tabs.click_tab_mute_button(1)
42+
tabs.expect_tab_sound_status(1, tabs.MEDIA_STATUS.MUTED)
43+
tabs.click_tab_mute_button(1)
44+
tabs.expect_tab_sound_status(1, tabs.MEDIA_STATUS.PLAYING)

tests/tabs/test_navigation_multiple_tabs.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import logging
2-
32
import pytest
43
from selenium.webdriver import Firefox
5-
64
from modules.browser_object import TabBar
75

6+
NUM_TABS = 20
7+
88

99
@pytest.fixture()
1010
def test_case():
@@ -14,11 +14,11 @@ def test_case():
1414
def test_navigation_multiple_tabs(driver: Firefox):
1515
"""C134647 - Verify that navigation through multiple tabs is allowed"""
1616

17+
# Instantiate objects
1718
tabs = TabBar(driver)
18-
num_tabs = 20
1919

2020
# Open multiple tabs
21-
for _ in range(num_tabs):
21+
for _ in range(NUM_TABS):
2222
tabs.new_tab_by_button()
2323

2424
with driver.context(driver.CONTEXT_CHROME):

tests/tabs/test_open_bookmark_in_new_tab.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ def test_case():
1414

1515
BOOKMARK_URL = "https://www.youtube.com/"
1616
BOOKMARK_TITLE = "YouTube"
17+
EXPECTED_TEST = "youtube"
1718

1819

1920
def test_open_bookmark_in_new_tab(driver: Firefox):
21+
2022
"""
2123
C134460: Verify that New Tabs can be opened by right clicking and selecting new tab from the bookmarks.
2224
"""
@@ -39,6 +41,6 @@ def test_open_bookmark_in_new_tab(driver: Firefox):
3941
tabs.wait_for_num_tabs(3)
4042
driver.switch_to.window(driver.window_handles[-1])
4143

42-
WebDriverWait(driver, 5).until(EC.url_contains("youtube"))
43-
assert "youtube" in driver.current_url
44-
page.url_contains("youtube")
44+
WebDriverWait(driver, 5).until(EC.url_contains(EXPECTED_TEST))
45+
assert EXPECTED_TEST in driver.current_url
46+
page.url_contains(EXPECTED_TEST)

tests/tabs/test_open_new_tab.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
from modules.browser_object import TabBar
66

77

8+
URL = "about:robots"
9+
EXPECTED_TEXT = "Firefox"
10+
11+
812
@pytest.fixture()
913
def test_case():
1014
return "134453"
@@ -14,11 +18,15 @@ def test_open_new_tab_plus(driver: Firefox):
1418
"""
1519
C134453 - A new tab can be opened from the dedicated button ("+")
1620
"""
21+
22+
# Instantiate object
1723
browser = TabBar(driver)
18-
driver.get("about:robots")
24+
25+
# Open page and check a new tab can be opened from the dedicated button ("+")
26+
driver.get(URL)
1927
browser.set_chrome_context()
2028
browser.new_tab_by_button()
21-
browser.expect(EC.title_contains("Firefox"))
22-
assert "Firefox" in driver.title, (
29+
browser.expect(EC.title_contains(EXPECTED_TEXT))
30+
assert EXPECTED_TEXT in driver.title, (
2331
f"Expected title to contain 'Firefox', but got '{driver.title}'"
2432
)
Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import pytest
22
from selenium.webdriver import Firefox
33
from selenium.webdriver.support import expected_conditions as EC
4-
54
from modules.browser_object import TabBar
65

76

7+
URL = "about:robots"
8+
EXPECTED_TEXT = "Firefox"
9+
10+
811
@pytest.fixture()
912
def test_case():
1013
return "134442"
@@ -14,11 +17,15 @@ def test_open_new_tab_via_keyboard(driver: Firefox, sys_platform: str):
1417
"""
1518
C134442 - A new tab can be opened via keyboard combinations
1619
"""
20+
21+
# Instantiate object
1722
browser = TabBar(driver)
18-
driver.get("about:robots")
23+
24+
# Open page and check a new tab can be opened via keyboard combinations
25+
driver.get(URL)
1926
browser.set_chrome_context()
2027
browser.new_tab_by_keys(sys_platform)
21-
browser.expect(EC.title_contains("Firefox"))
22-
assert "Firefox" in driver.title, (
28+
browser.expect(EC.title_contains(EXPECTED_TEXT))
29+
assert EXPECTED_TEXT in driver.title, (
2330
f"Expected title to contain 'Firefox', but got '{driver.title}'"
2431
)

0 commit comments

Comments
 (0)