Skip to content

Commit 6b0143c

Browse files
committed
finish undo close tab
1 parent 3155ff4 commit 6b0143c

File tree

2 files changed

+43
-31
lines changed

2 files changed

+43
-31
lines changed

modules/browser_object_tabbar.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,29 @@ def new_tab_by_keys(self, sys_platform: str) -> BasePage:
5353
).perform()
5454
return self
5555

56+
def reopen_closed_tab_by_keys(self, sys_platform: str) -> BasePage:
57+
"""Use keyboard shortcut to reopen a last closed tab"""
58+
if sys_platform == "Darwin":
59+
self.actions.key_down(Keys.COMMAND).key_down(Keys.SHIFT).send_keys(
60+
"t"
61+
).key_up(Keys.SHIFT).key_up(Keys.COMMAND).perform()
62+
else:
63+
self.actions.key_down(Keys.CONTROL).key_down(Keys.SHIFT).send_keys(
64+
"t"
65+
).key_up(Keys.SHIFT).key_up(Keys.CONTROL).perform()
66+
return self
67+
5668
def click_tab_by_title(self, title: str) -> BasePage:
5769
"""Given a full page title, click the corresponding tab"""
5870
with self.driver.context(self.driver.CONTEXT_CHROME):
5971
self.get_element("tab-by-title", labels=[title]).click()
6072
return self
6173

74+
def get_tab_by_title(self, title: str) -> BasePage:
75+
"""Given a full page title, return the corresponding tab"""
76+
with self.driver.context(self.driver.CONTEXT_CHROME):
77+
return self.get_element("tab-by-title", labels=[title])
78+
6279
def click_tab_by_index(self, index: int) -> BasePage:
6380
"""Given a tab index (int), click the corresponding tab"""
6481
with self.driver.context(self.driver.CONTEXT_CHROME):
@@ -245,11 +262,11 @@ def get_bar_y():
245262
self.actions.release()
246263
self.actions.perform()
247264

248-
def close_tab_of_index(self, index: int) -> BasePage:
265+
def close_tab(self, tab: WebElement) -> BasePage:
249266
"""
250267
Given the index of the tab, it closes that tab.
251268
"""
252-
cur_tab = self.click_tab_by_index(index)
269+
# cur_tab = self.click_tab_by_index(index)
253270
with self.driver.context(self.driver.CONTEXT_CHROME):
254-
self.get_element("tab-x-icon", parent_element=cur_tab).click()
271+
self.get_element("tab-x-icon", parent_element=tab).click()
255272
return self
Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,26 @@
1-
from time import sleep
2-
31
import pytest
42
from selenium.webdriver import Firefox
5-
from selenium.webdriver.common.keys import Keys
63

74
from modules.browser_object import Navigation, PanelUi, TabBar
5+
from modules.page_object import GenericPage
86

97
VISIT_URL = "about:about"
108

11-
links = [
12-
"about:about",
13-
"about:addons",
14-
"about:cache",
15-
"about:config",
16-
"about:buildconfig",
17-
"about:robots",
18-
"about:blank",
19-
]
20-
21-
link_set = set(links)
22-
239

2410
@pytest.fixture()
2511
def add_prefs():
2612
return []
2713

2814

29-
def test_undo_close_tab_private_browsing(driver: Firefox):
15+
def test_undo_close_tab_private_browsing(driver: Firefox, sys_platform: str):
3016
"""
3117
C120118: ensure that you can close a tab in private browsing window
3218
"""
3319
# instantiate objs
34-
panel_ui = PanelUi(driver)
35-
nav = Navigation(driver).open()
20+
panel_ui = PanelUi(driver).open()
21+
nav = Navigation(driver)
3622
tabs = TabBar(driver)
23+
generic_page = GenericPage(driver, url="about:about")
3724

3825
# open a new private window and open a new tab
3926
panel_ui.open_private_window()
@@ -43,16 +30,24 @@ def test_undo_close_tab_private_browsing(driver: Firefox):
4330
tabs.new_tab_by_button()
4431
tabs.switch_to_new_tab()
4532

46-
# navigate to the URL NOTE: TEMPORARY GET AWESOME BAR PRIVATE. ADD SUPPORT FOR IT IN NAVIGATION
33+
# navigate to the URL
4734
with driver.context(driver.CONTEXT_CHROME):
48-
search_bar = nav.get_element("awesome-bar-private")
49-
search_bar.send_keys(VISIT_URL + Keys.ENTER)
50-
tabs.wait_for_num_tabs(3)
51-
# tabs.switch_to_new_tab()
52-
# for _ in range(100):
53-
# print(len(driver.window_handles))
54-
# sleep(0.5)
35+
nav.search(VISIT_URL)
5536

56-
tabs.close_tab_of_index(0)
37+
# ensure its loaded
38+
generic_page.url_contains("about:about")
5739

58-
sleep(40)
40+
# close the most recent window
41+
with driver.context(driver.CONTEXT_CHROME):
42+
cur_tab = tabs.get_tab_by_title("About About")
43+
tabs.close_tab(cur_tab)
44+
45+
# ensuring that one of the tabs was closed properly
46+
tabs.wait_for_num_tabs(2)
47+
assert len(driver.window_handles) == 2
48+
49+
# ensure the last tab can be reopened
50+
with driver.context(driver.CONTEXT_CHROME):
51+
tabs.reopen_closed_tab_by_keys(sys_platform)
52+
tabs.wait_for_num_tabs(2)
53+
assert driver.title == "About About — Private Browsing"

0 commit comments

Comments
 (0)