|
| 1 | +import logging |
| 2 | +import platform |
| 3 | +import time |
| 4 | + |
| 5 | +import pytest |
| 6 | +from selenium.webdriver import ActionChains, Firefox, Keys |
| 7 | +from selenium.webdriver.common.by import By |
| 8 | + |
| 9 | +from modules.browser_object import ContextMenu, TabBar |
| 10 | + |
| 11 | +# Title Constants |
| 12 | +EXPECTED_MOZILLA_TITLE = "Mozilla" |
| 13 | +EXPECTED_ROBOT_TITLE = "Gort!" |
| 14 | +EXPECTED_WELCOME_TITLE = "Welcome" |
| 15 | + |
| 16 | +MOVE_TO_END = "context-menu-move-tab-to-end" |
| 17 | +MOVE_TO_START = "context-menu-move-tab-to-start" |
| 18 | +MOVE_TO_NEW_WINDOW = "context-menu-move-to-new-window" |
| 19 | + |
| 20 | + |
| 21 | +@pytest.fixture() |
| 22 | +def test_case(): |
| 23 | + return "246989" |
| 24 | + |
| 25 | + |
| 26 | +@pytest.mark.parametrize( |
| 27 | + "move_option,expected_title,expected_position", |
| 28 | + [ |
| 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), |
| 32 | + ], |
| 33 | +) |
| 34 | +def test_move_multi_selected_tabs( |
| 35 | + driver: Firefox, sys_platform: str, move_option, expected_title, expected_position |
| 36 | +): |
| 37 | + """Test all tab movement operations in separate test runs""" |
| 38 | + tab_movements(driver, sys_platform, move_option, expected_title, expected_position) |
| 39 | + |
| 40 | + |
| 41 | +def tab_movements( |
| 42 | + driver: Firefox, sys_platform: str, move_option, expected_title, expected_position |
| 43 | +): # expected_position starts at index 0 |
| 44 | + tabs = TabBar(driver) |
| 45 | + tab_context_menu = ContextMenu(driver) |
| 46 | + original_windows = None |
| 47 | + |
| 48 | + tab_titles = [] |
| 49 | + url_list = ["https://mozilla.org", "about:robots", "about:welcome", "about:logo"] |
| 50 | + |
| 51 | + driver.get(url_list[0]) |
| 52 | + tab_titles.append(driver.title) |
| 53 | + |
| 54 | + # Open 4 tabs |
| 55 | + for i in range(1, len(url_list)): |
| 56 | + tabs.new_tab_by_button() |
| 57 | + driver.switch_to.window(driver.window_handles[-1]) |
| 58 | + driver.get(url_list[i]) |
| 59 | + tab_titles.append(driver.title) |
| 60 | + |
| 61 | + # Specific tabs we want to work with |
| 62 | + selected_tab_indices = [2, 3] |
| 63 | + selected_tabs = tabs.select_multiple_tabs_by_indices( |
| 64 | + selected_tab_indices, sys_platform |
| 65 | + ) |
| 66 | + |
| 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 | + ) |
0 commit comments