Skip to content

Commit ea65735

Browse files
committed
local changes before merging
1 parent c9c437b commit ea65735

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed

modules/page_base.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,22 @@ def get_element(
305305
cache_name = f"{name}{labelscode}"
306306
if cache_name not in self.elements:
307307
self.elements[cache_name] = deepcopy(self.elements[name])
308+
# FIX: Check for doNotCache BEFORE trying to use cached elements
309+
if (
310+
not multiple
311+
and "doNotCache"
312+
not in self.elements[cache_name]["groups"] # ADD THIS CHECK
313+
and "seleniumObject" in self.elements[cache_name]
314+
):
315+
# no caching for multiples
316+
cached_element = self.elements[cache_name]["seleniumObject"]
317+
try:
318+
self.instawait.until_not(EC.staleness_of(cached_element))
319+
logging.info(f"Returned {cache_name} from object cache!")
320+
return self.elements[cache_name]["seleniumObject"]
321+
except (TimeoutError, TimeoutException):
322+
# Because we have a timeout of 0, this should not cause delays
323+
pass
308324
if multiple:
309325
logging.info(f"Multiples: Not caching {cache_name}...")
310326
if not multiple and "seleniumObject" in self.elements[cache_name]:
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import logging
2+
import time
3+
4+
import pytest
5+
from selenium.webdriver import Firefox
6+
from selenium.webdriver.common.action_chains import ActionChains
7+
from selenium.webdriver.common.by import By
8+
9+
from modules.browser_object import ContextMenu, Navigation, TabBar
10+
11+
12+
@pytest.fixture()
13+
def test_case():
14+
return "134723"
15+
16+
17+
def test_change_position_of_pinned_tabs(driver: Firefox):
18+
tabs = TabBar(driver)
19+
nav = Navigation(driver)
20+
tabs_context_menu = ContextMenu(driver)
21+
num_tabs = 5
22+
23+
tab_titles = []
24+
url_list = [
25+
"https://www.google.com",
26+
"https://www.youtube.com",
27+
"https://www.mozilla.org",
28+
"https://www.wikipedia.org",
29+
"https://www.github.com",
30+
]
31+
32+
driver.get(url_list[0])
33+
tab_titles.append(driver.title)
34+
35+
# Open 5 tabs
36+
for i in range(1, len(url_list)):
37+
tabs.new_tab_by_button()
38+
driver.switch_to.window(driver.window_handles[-1])
39+
driver.get(url_list[i])
40+
tab_titles.append(driver.title)
41+
time.sleep(2)
42+
43+
# specific tabs we want to work with
44+
google_title = tab_titles[0]
45+
mozilla_title = tab_titles[2]
46+
47+
# Pin the 'Google' tab by its title
48+
driver.switch_to.window(driver.window_handles[0])
49+
google_tab = tabs.get_tab(google_title)
50+
assert google_tab is not None, "Google tab should exist"
51+
tabs.context_click(google_tab)
52+
tabs_context_menu.click_context_item("context-menu-pin-tab")
53+
time.sleep(1)
54+
55+
# FIX: Re-initialize the context menu object after the DOM has changed.
56+
# FIX: Force a "context reset" by switching to a neutral tab.
57+
driver.switch_to.window(driver.window_handles[1]) # Switch to YouTube
58+
time.sleep(0.5) # A brief pause to ensure the context switch completes
59+
tabs_context_menu = ContextMenu(driver)
60+
61+
# Pin the 'Mozilla' tab by its title
62+
driver.switch_to.window(driver.window_handles[2])
63+
mozilla_tab = tabs.get_tab(mozilla_title)
64+
assert mozilla_tab is not None, "Mozilla tab should exist"
65+
tabs.context_click(mozilla_tab)
66+
tabs_context_menu.click_context_item("context-menu-pin-tab")
67+
time.sleep(1)
68+
69+
driver.switch_to.window(driver.window_handles[0])
70+
pinned_tab_one = tabs.get_tab(google_title)
71+
assert tabs.is_pinned(pinned_tab_one)
72+
73+
# ERROR
74+
# pinned_tab_two = tabs.get_tab(mozilla_title)
75+
# assert tabs.is_pinned(pinned_tab_two)
76+
77+
# -----------------------after pinned error is fixed ------------------------------------
78+
# actions = ActionChains(driver)
79+
# # A more robust, manual way to perform a drag-and-drop
80+
# actions.drag_and_drop(pinned_tab_one, pinned_tab_two).perform()
81+
82+
# assert tab_titles[0] in new_pinned_tab_one.text, "Google should now be the first pinned tab"
83+
# assert tab_titles[2] in new_pinned_tab_two.text, "Mozilla should now be the second pinned tab"

0 commit comments

Comments
 (0)