Skip to content

Commit 6e912ca

Browse files
Hani YacoubHani Yacoub
authored andcommitted
Batch 2
1 parent 699639a commit 6e912ca

File tree

6 files changed

+40
-19
lines changed

6 files changed

+40
-19
lines changed

modules/browser_object_tabbar.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,3 +316,13 @@ def open_multiple_tabs_with_pages(self, pages: list) -> "TabBar":
316316
else:
317317
page.open()
318318
return self
319+
320+
@BasePage.context_chrome
321+
def verify_tab_focus_cycle(self, num_tabs: int):
322+
"""Go through all the tabs and ensure the focus changes correctly."""
323+
for i in range(1, num_tabs + 2):
324+
target_tab = self.get_tab(i)
325+
self.click_on(target_tab)
326+
self.custom_wait(timeout=3).until(
327+
lambda d: target_tab.get_attribute("visuallyselected") == ""
328+
)

tests/tabs/test_active_tab.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
NUM_TABS = 5
88

9+
910
@pytest.fixture()
1011
def test_case():
1112
return "134646"
@@ -25,10 +26,4 @@ def test_active_tab(driver: Firefox):
2526
tabs.new_tab_by_button()
2627

2728
# Go through all the tabs and ensure the focus is correct
28-
for i in range(1, NUM_TABS + 2):
29-
with driver.context(driver.CONTEXT_CHROME):
30-
target_tab = tabs.get_tab(i)
31-
target_tab.click()
32-
tabs.custom_wait(timeout=3).until(
33-
lambda d: target_tab.get_attribute("visuallyselected") == ""
34-
)
29+
tabs.verify_tab_focus_cycle(NUM_TABS)

tests/tabs/test_navigation_multiple_tabs.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import logging
2-
32
import pytest
43
from selenium.webdriver import Firefox
5-
64
from modules.browser_object import TabBar
75

86
NUM_TABS = 20
97

8+
109
@pytest.fixture()
1110
def test_case():
1211
return "134654"

tests/tabs/test_open_bookmark_in_new_tab.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ def test_case():
1414

1515
BOOKMARK_URL = "https://www.youtube.com/"
1616
BOOKMARK_TITLE = "YouTube"
17+
EXPECTED_TEST = "youtube"
1718

1819

1920
def test_open_bookmark_in_new_tab(driver: Firefox):
21+
2022
"""
2123
C134460: Verify that New Tabs can be opened by right clicking and selecting new tab from the bookmarks.
2224
"""
@@ -39,6 +41,6 @@ def test_open_bookmark_in_new_tab(driver: Firefox):
3941
tabs.wait_for_num_tabs(3)
4042
driver.switch_to.window(driver.window_handles[-1])
4143

42-
WebDriverWait(driver, 5).until(EC.url_contains("youtube"))
43-
assert "youtube" in driver.current_url
44-
page.url_contains("youtube")
44+
WebDriverWait(driver, 5).until(EC.url_contains(EXPECTED_TEST))
45+
assert EXPECTED_TEST in driver.current_url
46+
page.url_contains(EXPECTED_TEST)

tests/tabs/test_open_new_tab.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
from modules.browser_object import TabBar
66

77

8+
URL = "about:robots"
9+
EXPECTED_TEXT = "Firefox"
10+
11+
812
@pytest.fixture()
913
def test_case():
1014
return "134453"
@@ -14,11 +18,15 @@ def test_open_new_tab_plus(driver: Firefox):
1418
"""
1519
C134453 - A new tab can be opened from the dedicated button ("+")
1620
"""
21+
22+
# Instantiate object
1723
browser = TabBar(driver)
18-
driver.get("about:robots")
24+
25+
# Open page and check a new tab can be opened from the dedicated button ("+")
26+
driver.get(URL)
1927
browser.set_chrome_context()
2028
browser.new_tab_by_button()
21-
browser.expect(EC.title_contains("Firefox"))
22-
assert "Firefox" in driver.title, (
29+
browser.expect(EC.title_contains(EXPECTED_TEXT))
30+
assert EXPECTED_TEXT in driver.title, (
2331
f"Expected title to contain 'Firefox', but got '{driver.title}'"
2432
)
Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import pytest
22
from selenium.webdriver import Firefox
33
from selenium.webdriver.support import expected_conditions as EC
4-
54
from modules.browser_object import TabBar
65

76

7+
URL = "about:robots"
8+
EXPECTED_TEXT = "Firefox"
9+
10+
811
@pytest.fixture()
912
def test_case():
1013
return "134442"
@@ -14,11 +17,15 @@ def test_open_new_tab_via_keyboard(driver: Firefox, sys_platform: str):
1417
"""
1518
C134442 - A new tab can be opened via keyboard combinations
1619
"""
20+
21+
# Instantiate object
1722
browser = TabBar(driver)
18-
driver.get("about:robots")
23+
24+
# Open page and check a new tab can be opened via keyboard combinations
25+
driver.get(URL)
1926
browser.set_chrome_context()
2027
browser.new_tab_by_keys(sys_platform)
21-
browser.expect(EC.title_contains("Firefox"))
22-
assert "Firefox" in driver.title, (
28+
browser.expect(EC.title_contains(EXPECTED_TEXT))
29+
assert EXPECTED_TEXT in driver.title, (
2330
f"Expected title to contain 'Firefox', but got '{driver.title}'"
2431
)

0 commit comments

Comments
 (0)