Skip to content

Commit f59403c

Browse files
committed
all 3 sub-tests pass locally
1 parent a7f3b49 commit f59403c

File tree

1 file changed

+81
-24
lines changed

1 file changed

+81
-24
lines changed

tests/tabs/test_move_multi_selected_tabs.py

Lines changed: 81 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,69 +9,126 @@
99
from modules.browser_object import ContextMenu, TabBar
1010

1111
# Title Constants
12-
EXPECTED_MOZILLA_TITLE = "Mozilla"
1312
EXPECTED_ROBOT_TITLE = "Gort!"
1413
EXPECTED_WELCOME_TITLE = "Welcome"
1514

15+
# Move options
1616
MOVE_TO_END = "context-menu-move-tab-to-end"
1717
MOVE_TO_START = "context-menu-move-tab-to-start"
1818
MOVE_TO_NEW_WINDOW = "context-menu-move-to-new-window"
1919

20+
# Expected Positions (4 tabs in total)
21+
FIRST_TAB_POSITION = 0
22+
SECOND_TAB_POSITION = 1
23+
THIRD_TAB_POSITION = 2
24+
LAST_TAB_POSITION = 3
25+
2026

2127
@pytest.fixture()
2228
def test_case():
2329
return "246989"
2430

2531

2632
@pytest.mark.parametrize(
27-
"move_option,expected_title,expected_position",
33+
"move_option,expected_titles,expected_positions",
2834
[
29-
(MOVE_TO_END, EXPECTED_ROBOT_TITLE, 2),
30-
(MOVE_TO_START, EXPECTED_ROBOT_TITLE, 0),
31-
# (MOVE_TO_NEW_WINDOW, EXPECTED_ROBOT_TITLE, 0),
35+
(
36+
MOVE_TO_END,
37+
(EXPECTED_ROBOT_TITLE, EXPECTED_WELCOME_TITLE),
38+
(THIRD_TAB_POSITION, LAST_TAB_POSITION),
39+
),
40+
(
41+
MOVE_TO_START,
42+
(EXPECTED_ROBOT_TITLE, EXPECTED_WELCOME_TITLE),
43+
(FIRST_TAB_POSITION, SECOND_TAB_POSITION),
44+
),
45+
(MOVE_TO_NEW_WINDOW, None, None),
3246
],
3347
)
3448
def test_move_multi_selected_tabs(
35-
driver: Firefox, sys_platform: str, move_option, expected_title, expected_position
49+
driver: Firefox, sys_platform: str, move_option, expected_titles, expected_positions
3650
):
3751
"""Test all tab movement operations in separate test runs"""
38-
tab_movements(driver, sys_platform, move_option, expected_title, expected_position)
52+
tab_movements(
53+
driver, sys_platform, move_option, expected_titles, expected_positions
54+
)
3955

4056

4157
def tab_movements(
42-
driver: Firefox, sys_platform: str, move_option, expected_title, expected_position
43-
): # expected_position starts at index 0
58+
driver: Firefox, sys_platform: str, move_option, expected_titles, expected_positions
59+
):
4460
tabs = TabBar(driver)
4561
tab_context_menu = ContextMenu(driver)
4662
original_windows = None
4763

4864
tab_titles = []
49-
url_list = ["https://mozilla.org", "about:robots", "about:welcome", "about:logo"]
65+
url_list = ["about:logo", "about:robots", "about:welcome", "https://mozilla.org"]
5066

67+
# Open 4 tabs
5168
driver.get(url_list[0])
5269
tab_titles.append(driver.title)
5370

54-
# Open 4 tabs
5571
for i in range(1, len(url_list)):
5672
tabs.new_tab_by_button()
5773
driver.switch_to.window(driver.window_handles[-1])
5874
driver.get(url_list[i])
5975
tab_titles.append(driver.title)
6076

61-
# Specific tabs we want to work with
62-
selected_tab_indices = [2, 3]
77+
# Specific tabs we want to move
78+
selected_tab_indices = [2, 3] # Here indices start from 1
6379
selected_tabs = tabs.select_multiple_tabs_by_indices(
6480
selected_tab_indices, sys_platform
6581
)
6682

67-
# move-to-- -repeated
68-
tabs.context_click(selected_tabs[1])
69-
tab_context_menu.click_and_hide_menu(move_option)
70-
tabs.hide_popup("tabContextMenu")
71-
72-
# Verify for move-to-end/move-to-start
73-
driver.switch_to.window(driver.window_handles[expected_position])
74-
actual_title = driver.title
75-
assert expected_title in actual_title, (
76-
f"Expected '{expected_title}' at position {expected_position}"
77-
)
83+
if move_option == MOVE_TO_NEW_WINDOW:
84+
# Tabs grouped in one window will all report the same window coordinates
85+
original_handles = driver.window_handles
86+
positions_before = set()
87+
88+
for handle in original_handles:
89+
driver.switch_to.window(handle)
90+
rect = driver.get_window_rect()
91+
positions_before.add((rect["x"], rect["y"]))
92+
93+
tabs.context_click(selected_tabs[1])
94+
tab_context_menu.click_and_hide_menu(move_option)
95+
tabs.hide_popup("tabContextMenu")
96+
97+
# Tabs that have been moved to a new window will report different coordinates
98+
positions_after = set()
99+
for handle in driver.window_handles:
100+
driver.switch_to.window(handle)
101+
rect = driver.get_window_rect()
102+
positions_after.add((rect["x"], rect["y"]))
103+
104+
# print(f"Unique positions before: {len(positions_before)}")
105+
# print(f"Unique positions after: {len(positions_after)}")
106+
107+
assert len(positions_before) == 1
108+
assert len(positions_after) > 1
109+
110+
elif move_option in (MOVE_TO_END, MOVE_TO_START):
111+
assert expected_positions is not None
112+
assert expected_titles is not None
113+
114+
# move-to-___
115+
tabs.context_click(selected_tabs[1])
116+
tab_context_menu.click_and_hide_menu(move_option)
117+
tabs.hide_popup("tabContextMenu")
118+
119+
# Verify for move-to-end/move-to-start
120+
121+
for expected_title, expected_position in zip(
122+
expected_titles, expected_positions
123+
):
124+
# Switch to the window handle at the expected index
125+
# NOTE: driver.window_handles are the HANDLES, the index is the order they APPEAR
126+
driver.switch_to.window(driver.window_handles[expected_position])
127+
128+
actual_title = driver.title
129+
130+
# Assert the title is correct
131+
assert expected_title in actual_title, (
132+
f"Verification failed for tab at index {expected_position}: "
133+
f"Expected title '{expected_title}' but found '{actual_title}'."
134+
)

0 commit comments

Comments
 (0)