Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions modules/browser_object_tabbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,3 +326,41 @@ def verify_tab_focus_cycle(self, num_tabs: int):
self.custom_wait(timeout=3).until(
lambda d: target_tab.get_attribute("visuallyselected") == ""
)

@BasePage.context_chrome
def select_multiple_tabs_by_indices(
self, indices: list[int], sys_platform: str
) -> list[WebElement]:
"""
Selects multiple tabs based on their indices and returns list of tabs.

Preconditions:
- len(indices) > 1
- max(indices) < number of open tabs
- min(indices) >= 1
Notes:
- Opens (clicks) the tab at the first index in indices
- the first tab in the window is denoted by index 1 (1-based indexing)
"""

start_tab = self.get_tab(indices[0])
selected_tabs = [start_tab]
start_tab.click()

actions = self.actions
if sys_platform == "Darwin":
actions.key_down(Keys.COMMAND).perform()
else:
actions.key_down(Keys.CONTROL).perform()

for i in range(1, len(indices)):
tab = self.get_tab(indices[i])
actions.click(tab).perform()
selected_tabs.append(tab)

if sys_platform == "Darwin":
actions.key_up(Keys.COMMAND).perform()
else:
actions.key_up(Keys.CONTROL).perform()

return selected_tabs
51 changes: 51 additions & 0 deletions tests/tabs/test_pin_unpin_selected_tabs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import pytest
from selenium.webdriver import Firefox

from modules.browser_object import ContextMenu, TabBar


@pytest.fixture()
def test_case():
return "246978"


URLS = [
"about:about",
"about:addons",
"about:cache",
"about:robots",
]


def test_pin_unpin_selected_tabs(driver: Firefox, sys_platform: str):
"""
C246978 - Verify that multiple tabs can be selected and pinned/unpinned from the context menu.
"""

tabs = TabBar(driver)
# Create 4 new tabs
for i in range(4):
tabs.new_tab_by_button()
driver.switch_to.window(driver.window_handles[-1])
driver.get(URLS[i])
assert len(driver.window_handles) == 5

select_indices = [1, 3, 5]
selected_tabs = tabs.select_multiple_tabs_by_indices(select_indices, sys_platform)
tab_context_menu = ContextMenu(driver)

# Pin
tab_context_menu.context_click(selected_tabs[1])
tab_context_menu.click_and_hide_menu(("css selector", "#context_pinSelectedTabs"))

# Verify pinned
for tab in selected_tabs:
assert tabs.is_pinned(tab)

# Unpin
tab_context_menu.context_click(selected_tabs[1])
tab_context_menu.click_and_hide_menu(("css selector", "#context_unpinSelectedTabs"))

# Verify unpinned
for tab in selected_tabs:
assert not tabs.is_pinned(tab)