|
9 | 9 | from modules.browser_object import ContextMenu, TabBar |
10 | 10 |
|
11 | 11 | # Title Constants |
12 | | -EXPECTED_MOZILLA_TITLE = "Mozilla" |
13 | 12 | EXPECTED_ROBOT_TITLE = "Gort!" |
14 | 13 | EXPECTED_WELCOME_TITLE = "Welcome" |
15 | 14 |
|
| 15 | +# Move options |
16 | 16 | MOVE_TO_END = "context-menu-move-tab-to-end" |
17 | 17 | MOVE_TO_START = "context-menu-move-tab-to-start" |
18 | 18 | MOVE_TO_NEW_WINDOW = "context-menu-move-to-new-window" |
19 | 19 |
|
| 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 | + |
20 | 26 |
|
21 | 27 | @pytest.fixture() |
22 | 28 | def test_case(): |
23 | 29 | return "246989" |
24 | 30 |
|
25 | 31 |
|
26 | 32 | @pytest.mark.parametrize( |
27 | | - "move_option,expected_title,expected_position", |
| 33 | + "move_option,expected_titles,expected_positions", |
28 | 34 | [ |
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), |
32 | 46 | ], |
33 | 47 | ) |
34 | 48 | 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 |
36 | 50 | ): |
37 | 51 | """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 | + ) |
39 | 55 |
|
40 | 56 |
|
41 | 57 | 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 | +): |
44 | 60 | tabs = TabBar(driver) |
45 | 61 | tab_context_menu = ContextMenu(driver) |
46 | 62 | original_windows = None |
47 | 63 |
|
48 | 64 | 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"] |
50 | 66 |
|
| 67 | + # Open 4 tabs |
51 | 68 | driver.get(url_list[0]) |
52 | 69 | tab_titles.append(driver.title) |
53 | 70 |
|
54 | | - # Open 4 tabs |
55 | 71 | for i in range(1, len(url_list)): |
56 | 72 | tabs.new_tab_by_button() |
57 | 73 | driver.switch_to.window(driver.window_handles[-1]) |
58 | 74 | driver.get(url_list[i]) |
59 | 75 | tab_titles.append(driver.title) |
60 | 76 |
|
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 |
63 | 79 | selected_tabs = tabs.select_multiple_tabs_by_indices( |
64 | 80 | selected_tab_indices, sys_platform |
65 | 81 | ) |
66 | 82 |
|
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