Skip to content

Commit a16baee

Browse files
Hani YacoubHani Yacoub
authored andcommitted
Refactor tabs batch 2
1 parent eb94d77 commit a16baee

File tree

7 files changed

+49
-35
lines changed

7 files changed

+49
-35
lines changed

SELECTOR_INFO.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3203,7 +3203,7 @@ Path to .json: modules/data/panel_ui.components.json
32033203
```
32043204
```
32053205
Selector name: panel-ui-history-recently-closed-reopen-tabs
3206-
Selector Data: toolbarbutton[class='restoreallitem subviewbutton panel-subview-footer-button']
3206+
Selector Data: toolbarbutton[class='subviewbutton subviewbutton-nav'][label='Recently closed tabs']
32073207
Description: Recently closed reopen tabs
32083208
Location: On the hamburger menu > History
32093209
Path to .json: modules/data/panel_ui.components.json

modules/browser_object_panel_ui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def reopen_recently_closed_tabs(self) -> BasePage:
171171
self.click_on("panel-ui-history")
172172

173173
self.click_on("panel-ui-history-recently-closed")
174-
if self.sys_platform() == "Linux":
174+
if self.sys_platform() in ("Linux", "Darwin"):
175175
sleep(2)
176176

177177
self.click_on("panel-ui-history-recently-closed-reopen-tabs")

modules/data/panel_ui.components.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
},
134134

135135
"panel-ui-history-recently-closed-reopen-tabs": {
136-
"selectorData": "toolbarbutton[class='restoreallitem subviewbutton panel-subview-footer-button']",
136+
"selectorData": "toolbarbutton[class='subviewbutton subviewbutton-nav'][label='Recently closed tabs']",
137137
"strategy": "css",
138138
"groups": []
139139
},

tests/tabs/test_open_new_tab_via_hyperlink.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
from modules.page_object import ExamplePage
66

77

8+
URL = "https://www.iana.org/help/example-domains"
9+
10+
811
@pytest.fixture()
912
def test_case():
1013
return "134444"
@@ -14,15 +17,17 @@ def test_open_new_via_hyperlink(driver: Firefox):
1417
"""
1518
C134444 - A hyperlink can be opened in a new tab
1619
"""
17-
example = ExamplePage(driver).open()
20+
21+
# Instantiate objects
22+
example = ExamplePage(driver)
23+
context_menu = ContextMenu(driver)
1824

1925
# Use context menu option to open link in new tab
26+
example.open()
2027
example.context_click("more-information")
21-
context_menu = ContextMenu(driver)
22-
with driver.context(driver.CONTEXT_CHROME):
23-
context_menu.click_and_hide_menu("context-menu-open-link-in-tab")
28+
context_menu.click_and_hide_menu("context-menu-open-link-in-tab")
2429

2530
# Get the title of the new tab
2631
example.wait_for_num_tabs(2)
2732
example.switch_to_new_tab()
28-
example.url_contains("https://www.iana.org/help/example-domains")
33+
example.url_contains(URL)

tests/tabs/test_pin_tab.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
from modules.browser_object import ContextMenu, TabBar
55

66

7+
NUM_TABS = 5
8+
79
@pytest.fixture()
810
def test_case():
911
return "134722"
@@ -13,28 +15,28 @@ def test_pin_tab(driver: Firefox):
1315
"""
1416
C134722, ensures that tabs can be pinned
1517
"""
18+
19+
# Instantiate objects
1620
tabs = TabBar(driver)
1721
tab_context_menu = ContextMenu(driver)
1822

19-
num_tabs = 5
20-
21-
# opening some tabs
22-
for _ in range(num_tabs):
23+
# Opening some tabs
24+
for _ in range(NUM_TABS):
2325
tabs.new_tab_by_button()
2426

25-
# pin the 1st tab
27+
# Pin the 1st tab
2628
first_tab = tabs.get_tab(1)
2729
tabs.context_click(first_tab)
2830
tab_context_menu.click_and_hide_menu("context-menu-pin-tab")
2931

3032
assert tabs.is_pinned(first_tab)
3133

3234
# ensuring all the other tabs are not pinned
33-
for i in range(2, num_tabs + 2):
35+
for i in range(2, NUM_TABS + 2):
3436
tab = tabs.get_tab(i)
3537
assert not tabs.is_pinned(tab)
3638

37-
# unpinning the tab and ensuring it is no longer pinned
39+
# Unpinning the tab and ensuring it is no longer pinned
3840
tabs.context_click(first_tab)
3941
tab_context_menu.click_and_hide_menu("context-menu-unpin-tab")
4042

tests/tabs/test_reopen_tab_through_context_menu.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,39 @@
44
from modules.browser_object import ContextMenu, TabBar
55

66

7+
TABS_TO_OPEN = 4
8+
FIRST_URL = "about:about"
9+
SECOND_URL = "about:robots"
10+
711
@pytest.fixture()
812
def test_case():
913
return "134648"
1014

1115

1216
def test_reopen_tab_through_context_menu(driver: Firefox):
1317
"""C134648: Reopen tab through context menu"""
18+
19+
# Instantiate objects
1420
tabs = TabBar(driver)
1521
tab_context_menu = ContextMenu(driver)
1622

17-
tabs_to_open = 4
18-
19-
driver.get("about:about")
20-
for _ in range(1, tabs_to_open):
23+
# Open several different tabs and close them
24+
driver.get(FIRST_URL)
25+
for _ in range(1, TABS_TO_OPEN):
2126
tabs.new_tab_by_button()
2227
driver.switch_to.window(driver.window_handles[-1])
23-
driver.get("about:robots")
28+
driver.get(SECOND_URL)
2429
remaining_tab = tabs.get_tab(1)
25-
closing_tab = tabs.get_tab(tabs_to_open)
30+
closing_tab = tabs.get_tab(TABS_TO_OPEN)
2631

27-
with driver.context(driver.CONTEXT_CHROME):
28-
assert tabs.get_tab_title(closing_tab).startswith("Gort")
32+
assert tabs.get_tab_title(closing_tab).startswith("Gort")
2933

3034
driver.close()
3135
driver.switch_to.window(driver.window_handles[0])
3236

37+
# Right click on the remaining tab and reopen previously closed tab
3338
tabs.context_click(remaining_tab)
3439
tab_context_menu.click_and_hide_menu("context-menu-reopen-closed-tab")
3540

36-
reopened_tab = tabs.get_tab(tabs_to_open + 1)
41+
reopened_tab = tabs.get_tab(TABS_TO_OPEN + 1)
3742
assert tabs.get_tab_title(reopened_tab).startswith("Gort")

tests/tabs/test_reopen_tab_through_history_menu.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def test_case():
1212
return "134650"
1313

1414

15-
links = [
15+
LINKS = [
1616
"about:about",
1717
"about:addons",
1818
"about:cache",
@@ -22,35 +22,37 @@ def test_case():
2222
"about:blank",
2323
]
2424

25-
link_set = set(links)
25+
LINK_SET = set(LINKS)
26+
NUM_TABS = 6
2627

2728

2829
@pytest.mark.skipif(
2930
system().lower().startswith("linux"), reason="Currently unstable in linux"
3031
)
3132
def test_reopen_tab_through_history_menu(driver: Firefox):
3233
"""C134650 - Verify that the recently closed tab can be reopened from the history menu"""
33-
# open 6 tabs
34+
35+
# Instantiate objects
3436
tabs = TabBar(driver)
3537
panel = PanelUi(driver)
36-
num_tabs = 6
3738

38-
for i in range(num_tabs):
39-
driver.get(links[i])
39+
# open 6 tabs
40+
for i in range(NUM_TABS):
41+
driver.get(LINKS[i])
4042
tabs.new_tab_by_button()
4143
driver.switch_to.window(driver.window_handles[i + 1])
4244

4345
# close the first 6 tabs
44-
for i in range(num_tabs):
45-
tabs.close_tab(tabs.get_tab(num_tabs - i))
46+
for i in range(NUM_TABS):
47+
tabs.close_tab(tabs.get_tab(NUM_TABS - i))
4648

4749
# open menu bar and reopen recently closed tabs
4850
panel.open()
4951
panel.reopen_recently_closed_tabs()
5052

5153
# go through all the tabs and ensure they were the ones that were opened previously
52-
for i in range(num_tabs):
53-
driver.switch_to.window(driver.window_handles[i + 1])
54+
for i in range(NUM_TABS):
55+
driver.switch_to.window(driver.window_handles[-1])
5456
current_page = driver.current_url
5557
logging.info(f"The current URL is: {current_page}")
56-
assert current_page in link_set
58+
assert current_page in LINK_SET

0 commit comments

Comments
 (0)