Skip to content

Commit b1b3940

Browse files
authored
Bc/ergo menus and tabs (#126)
* write test * fix broken context split in menus * stop hiding by child * click and hide * finish test * change click_and_hide to basepage * skip new fxa for now * clean up ergo for context menu clicking
1 parent 8c6c388 commit b1b3940

15 files changed

+101
-212
lines changed

modules/browser_object.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from modules.browser_object_credit_card_popup import *
44
from modules.browser_object_devtools import *
55
from modules.browser_object_find_toolbar import *
6+
from modules.browser_object_hyperlink_context_menu import *
67
from modules.browser_object_image_context_menu import *
78
from modules.browser_object_navigation import *
89
from modules.browser_object_panel_ui import *

modules/browser_object_context_menu.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,7 @@ class ContextMenu(BasePage):
1212

1313
URL_TEMPLATE = ""
1414

15-
def get_context_item(self, item: str) -> WebElement:
16-
"""
17-
Gets the context menu item from the context menu
18-
"""
19-
with self.driver.context(self.driver.CONTEXT_CHROME):
20-
return self.get_element(item)
21-
15+
2216
def click_context_item(
2317
self, reference: Union[str, tuple, WebElement], labels=[]
2418
) -> BasePage:
@@ -27,12 +21,4 @@ def click_context_item(
2721
"""
2822
with self.driver.context(self.driver.CONTEXT_CHROME):
2923
self.fetch(reference, labels=labels).click()
30-
return self
31-
32-
def click_and_hide(
33-
self, reference: Union[str, tuple, WebElement], labels=[]
34-
) -> BasePage:
35-
with self.driver.context(self.driver.CONTEXT_CHROME):
36-
self.fetch(reference, labels=labels).click()
37-
self.hide_popup_by_child_node(reference, labels=labels)
38-
return self
24+
return self

modules/browser_object_tabbar.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,19 @@ def get_tab(self, identifier: Union[str, int]) -> Union[WebElement, None]:
104104
else:
105105
# if we get an unexpected type, we shouldn't assume that the user wants sys exit
106106
# but we have to cause problems for them nonetheless
107-
assert False
107+
assert False, "Error getting tab root"
108108
tab = None
109109
return tab
110110

111+
def is_pinned(self, tab_root: WebElement) -> bool:
112+
"""Is this tab pinned?"""
113+
with self.driver.context(self.driver.CONTEXT_CHROME):
114+
pinned = tab_root.get_attribute("pinned")
115+
if pinned in ["true", "false"]:
116+
return pinned == "true"
117+
else:
118+
assert False, "Error checking tab pinned status"
119+
111120
def click_tab_mute_button(self, identifier: Union[str, int]) -> BasePage:
112121
"""Click the tab icon overlay, no matter what's happening with media"""
113122
logging.info(f"toggling tab mute for {identifier}")

modules/data/hyperlink_context_menu.components.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"context": "chrome",
23
"do-not-cache": true,
34
"context-menu-open-in-new-window": {
45
"selectorData": "context-openlink",

modules/page_base.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,15 @@ def context_click(
508508
self.actions.context_click(el).perform()
509509
return self
510510

511+
def click_and_hide_menu(
512+
self, reference: Union[str, tuple, WebElement], labels=[]
513+
) -> Page:
514+
"""Click an option in a context menu, then hide it"""
515+
with self.driver.context(self.driver.CONTEXT_CHROME):
516+
self.fetch(reference, labels=labels).click()
517+
self.hide_popup_by_child_node(reference, labels=labels)
518+
return self
519+
511520
def hover(self, reference: Union[str, tuple, WebElement], labels=[]):
512521
"""
513522
Hover over the specified element.

tests/address_bar_and_search/test_search_code_google_non_us.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ def search_code_assert():
6161
h1_tag = (By.TAG_NAME, "h1")
6262
example.triple_click(h1_tag)
6363
example.context_click(h1_tag)
64-
context_menu.get_context_item("context-menu-search-selected-text").click()
65-
nav.hide_popup("contentAreaContextMenu")
64+
context_menu.click_and_hide_menu("context-menu-search-selected-text")
6665

6766
# Switch to the newly opened tab and run the code check
6867
window_handles = driver.window_handles

tests/address_bar_and_search/test_search_code_google_us.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ def search_code_assert():
5151
h1_tag = (By.TAG_NAME, "h1")
5252
example.triple_click(h1_tag)
5353
example.context_click(h1_tag)
54-
context_menu.get_context_item("context-menu-search-selected-text").click()
55-
nav.hide_popup("contentAreaContextMenu")
54+
context_menu.click_and_hide_menu("context-menu-search-selected-text")
5655

5756
# Switch to the newly opened tab and run the code check
5857
window_handles = driver.window_handles

tests/menus/test_copy_paste_actions.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,14 @@ def test_login_form_copy_paste(driver: Firefox):
2727
# triple click and copy text
2828
login_fill.triple_click("login-input-field", labels=["current-password"])
2929
login_fill.context_click(password_field)
30-
with driver.context(driver.CONTEXT_CHROME):
31-
context_menu.get_context_item("context-menu-copy").click()
32-
login_fill.hide_popup("contentAreaContextMenu")
30+
context_menu.click_and_hide_menu("context-menu-copy")
3331

3432
# delete all text
3533
password_field.send_keys(Keys.BACK_SPACE)
3634
assert password_field.get_attribute("value") == ""
3735

3836
login_fill.context_click(password_field)
39-
with driver.context(driver.CONTEXT_CHROME):
40-
context_menu.get_context_item("context-menu-paste").click()
41-
login_fill.hide_popup("contentAreaContextMenu")
37+
context_menu.click_and_hide_menu("context-menu-paste")
4238

4339
# final assertion
4440
assert password_field.get_attribute("value") != random_text
@@ -59,18 +55,14 @@ def test_text_area_copy_paste(driver: Firefox):
5955
# copy the text
6056
text_area_fill.triple_click("street-address-textarea")
6157
text_area_fill.context_click(text_area)
62-
with driver.context(driver.CONTEXT_CHROME):
63-
context_menu.get_context_item("context-menu-copy").click()
64-
text_area_fill.hide_popup("contentAreaContextMenu")
58+
context_menu.click_and_hide_menu("context-menu-copy")
6559

6660
# delete all the text and paste
6761
text_area.send_keys(Keys.BACK_SPACE)
6862
assert text_area.get_attribute("value") == ""
6963

7064
text_area_fill.context_click(text_area)
71-
with driver.context(driver.CONTEXT_CHROME):
72-
context_menu.get_context_item("context-menu-paste").click()
73-
text_area_fill.hide_popup("contentAreaContextMenu")
65+
context_menu.click_and_hide_menu("context-menu-paste")
7466

7567
# check value
7668
assert text_area.get_attribute("value") == random_text
@@ -93,19 +85,15 @@ def test_search_field_copy_paste(driver: Firefox):
9385

9486
# context click
9587
google_search.context_click(search_bar)
96-
with driver.context(driver.CONTEXT_CHROME):
97-
context_menu.get_context_item("context-menu-copy").click()
98-
google_search.hide_popup("contentAreaContextMenu")
88+
context_menu.click_and_hide_menu("context-menu-copy")
9989

10090
# delete the current text
10191
search_bar.send_keys(Keys.BACK_SPACE)
10292
assert search_bar.get_attribute("value") == ""
10393

10494
# context click and paste the text back
10595
google_search.context_click(search_bar)
106-
with driver.context(driver.CONTEXT_CHROME):
107-
context_menu.get_context_item("context-menu-paste").click()
108-
google_search.hide_popup("contentAreaContextMenu")
96+
context_menu.click_and_hide_menu("context-menu-paste")
10997

11098
# assert the value is correct
11199
assert search_bar.get_attribute("value") == random_text

tests/menus/test_frequently_used_context_menu.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ def test_save_page_as(driver: Firefox):
3030
title_header = example_page.get_element("title-header")
3131
example_page.context_click(title_header)
3232

33-
save_page_as = context_menu.get_context_item("context-menu-save-page-as")
34-
context_menu.click_context_item(save_page_as)
35-
context_menu.hide_popup_by_child_node(save_page_as)
33+
context_menu.click_and_hide_menu("context-menu-save-page-as")
3634

3735
downloads_button = nav.get_download_button()
3836

@@ -85,9 +83,7 @@ def test_take_screenshot(driver: Firefox):
8583
example_page.context_click(title_header)
8684

8785
# context click the screenshot option and verify its not hidden
88-
take_screenshot = context_menu.get_context_item("context-menu-take-screenshot")
89-
context_menu.click_context_item(take_screenshot)
90-
context_menu.hide_popup_by_child_node(take_screenshot)
86+
context_menu.click_and_hide_menu("context-menu-take-screenshot")
9187

9288
with driver.context(driver.CONTEXT_CHROME):
9389
screenshot_box = example_page.get_element("take-screenshot-box")
@@ -108,7 +104,6 @@ def test_inspect(driver: Firefox):
108104
title_header = example_page.get_element("title-header")
109105
example_page.context_click(title_header)
110106

111-
inspect_option = context_menu.get_context_item("context-menu-inspect")
112-
context_menu.click_context_item(inspect_option)
113-
context_menu.hide_popup_by_child_node(inspect_option)
107+
context_menu.click_and_hide_menu("context-menu-inspect")
108+
114109
devtools.check_opened()
Lines changed: 19 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,51 @@
11
from selenium.webdriver import Firefox
2-
from selenium.webdriver.common.by import By
3-
from selenium.webdriver.support import expected_conditions as EC
42

5-
from modules.browser_object import Navigation, TabBar
6-
from modules.browser_object_hyperlink_context_menu import HyperlinkContextMenu
3+
from modules.browser_object import HyperlinkContextMenu, Navigation, TabBar
4+
from modules.page_object import ExamplePage
75

86

97
def test_open_link_in_new_window(driver: Firefox):
108
"""
119
C2637621.2: open link in new window
1210
"""
13-
nav = Navigation(driver).open()
1411
hyperlink_context = HyperlinkContextMenu(driver)
1512
tabs = TabBar(driver)
13+
example = ExamplePage(driver)
14+
example.open()
1615

1716
# right click the hyperlink
18-
nav.open()
19-
driver.get("https://example.com")
20-
hyperlink = driver.find_element(By.LINK_TEXT, "More information...")
21-
hyperlink_context.context_click(hyperlink)
17+
example.context_click("more-information")
2218

2319
# click on the open in new window option
24-
25-
open_in_new_window = hyperlink_context.get_context_item(
26-
"context-menu-open-in-new-window"
27-
)
28-
hyperlink_context.click_context_item(open_in_new_window)
29-
hyperlink_context.hide_popup("contentAreaContextMenu", chrome=True)
20+
hyperlink_context.click_and_hide_menu("context-menu-open-in-new-window")
3021

3122
# verify there are two instances (two windows)
3223
tabs.wait_for_num_tabs(2)
3324
driver.switch_to.window(driver.window_handles[1])
3425

35-
with driver.context(driver.CONTEXT_CONTENT):
36-
nav.expect(EC.title_contains("Example Domains"))
37-
assert driver.current_url == "https://www.iana.org/help/example-domains"
38-
39-
40-
def test_open_link_in_private_window(driver: Firefox):
41-
"""
42-
C2637621.3: open link in new window (private)
43-
"""
44-
nav = Navigation(driver).open()
45-
hyperlink_context = HyperlinkContextMenu(driver)
46-
tabs = TabBar(driver)
47-
48-
# right click the hyperlink
49-
nav.open()
50-
driver.get("https://example.com")
51-
hyperlink = driver.find_element(By.LINK_TEXT, "More information...")
52-
hyperlink_context.context_click(hyperlink)
53-
54-
# click on the open in new window option
55-
open_in_new_window = hyperlink_context.get_context_item(
56-
"context-menu-open-in-private-window"
57-
)
58-
hyperlink_context.click_context_item(open_in_new_window)
59-
hyperlink_context.hide_popup("contentAreaContextMenu", chrome=True)
60-
61-
# verify there are two instances (two windows)
62-
tabs.wait_for_num_tabs(2)
63-
driver.switch_to.window(driver.window_handles[1])
26+
example.title_contains(example.MORE_INFO_TITLE)
27+
example.url_contains(example.MORE_INFO_URL)
6428

65-
with driver.context(driver.CONTEXT_CONTENT):
66-
nav.expect(EC.title_contains("Example Domains"))
67-
assert driver.current_url == "https://www.iana.org/help/example-domains"
6829

69-
# verify its in private mode
70-
with driver.context(driver.CONTEXT_CHROME):
71-
nav.element_exists("private-browsing-icon")
30+
"""
31+
C2637621.3: open link in new window (private) already covered
32+
"""
7233

7334

7435
def test_copy_link(driver: Firefox):
7536
"""
7637
C2264627.4: Copy the link and verify it was copied
7738
"""
78-
nav = Navigation(driver).open()
39+
nav = Navigation(driver)
7940
hyperlink_context = HyperlinkContextMenu(driver)
8041
tabs = TabBar(driver)
42+
example = ExamplePage(driver).open()
8143

8244
# right click the hyperlink
83-
nav.open()
84-
driver.get("https://example.com")
85-
hyperlink = driver.find_element(By.LINK_TEXT, "More information...")
86-
hyperlink_context.context_click(hyperlink)
45+
example.context_click("more-information")
8746

8847
# click on the open in new window option
89-
open_in_new_window = hyperlink_context.get_context_item("context-menu-copy-link")
90-
hyperlink_context.click_context_item(open_in_new_window)
91-
hyperlink_context.hide_popup("contentAreaContextMenu", chrome=True)
48+
hyperlink_context.click_and_hide_menu("context-menu-copy-link")
9249

9350
# open a new tab
9451
tabs.new_tab_by_button()
@@ -100,11 +57,7 @@ def test_copy_link(driver: Firefox):
10057
nav.context_click(search_bar)
10158

10259
# paste and go
103-
with driver.context(driver.CONTEXT_CHROME):
104-
paste_and_go = nav.get_element("context-menu-paste-and-go")
105-
paste_and_go.click()
106-
nav.hide_popup_by_child_node(paste_and_go)
107-
108-
with driver.context(driver.CONTEXT_CONTENT):
109-
nav.expect(EC.title_contains("Example Domains"))
110-
assert driver.current_url == "https://www.iana.org/help/example-domains"
60+
nav.click_and_hide_menu("context-menu-paste-and-go")
61+
62+
example.title_contains(example.MORE_INFO_TITLE)
63+
example.url_contains(example.MORE_INFO_URL)

0 commit comments

Comments
 (0)