Skip to content

Commit 27d2008

Browse files
authored
Merge pull request #87 from mozilla/sl/intervention-card-refresh
Intervention Card Firefox
2 parents a321bdf + ed878ef commit 27d2008

File tree

7 files changed

+115
-15
lines changed

7 files changed

+115
-15
lines changed

modules/browser_object_autofill_popup.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,6 @@ def verify_no_popup_panel(self):
2626
element = self.get_element("autofill-panel")
2727
self.expect_not(EC.element_to_be_clickable(element))
2828

29-
def hover_over_element(self, element: str):
30-
"""
31-
Hover over the specified element.
32-
Parameters: element (str): The element to hover over.
33-
"""
34-
with self.driver.context(self.driver.CONTEXT_CHROME):
35-
self.actions.move_to_element(element).perform()
36-
return self
37-
3829
def get_nth_element(self, index: str) -> WebElement:
3930
"""
4031
Get the nth element from the autocomplete list.

modules/data/navigation.components.json

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@
5252
"refresh-intervention-card": {
5353
"selectorData": "div[tip-type=\"intervention_refresh\"]",
5454
"strategy": "css",
55-
"groups": []
55+
"groups": [
56+
"doNotCache"
57+
]
5658
},
5759

5860
"fx-refresh-text": {
@@ -79,6 +81,12 @@
7981
"groups": []
8082
},
8183

84+
"fx-refresh-menu-get-help-item-get-help": {
85+
"selectorData": "urlbarView-result-menuitem",
86+
"strategy": "class",
87+
"groups": []
88+
},
89+
8290
"search-engine-suggestion-row": {
8391
"selectorData": "div[class=\"urlbarView-row\"][type=\"search_engine\"]",
8492
"strategy": "css",
@@ -134,7 +142,13 @@
134142
"groups": []
135143
},
136144

137-
"addon-suggestion": {
145+
"search-results-container": {
146+
"selectorData": "urlbar-results",
147+
"strategy": "id",
148+
"groups": []
149+
},
150+
151+
"addon-suggestion": {
138152
"selectorData": "div.urlbarView-row[type='rust_amo'] span.urlbarView-title.urlbarView-overflowable",
139153
"strategy": "css",
140154
"groups": []

modules/page_base.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import re
66
from copy import deepcopy
77
from pathlib import Path
8-
from typing import Union
8+
from typing import List, Union
99

1010
from pypom import Page
1111
from selenium.common.exceptions import NoSuchElementException, TimeoutException
@@ -454,6 +454,32 @@ def hide_popup_by_child_node(self, node: WebElement, chrome=False) -> Page:
454454
else:
455455
self.driver.execute_script(script, node)
456456

457+
def hover_over_element(self, element: WebElement, chrome=False):
458+
"""
459+
Hover over the specified element.
460+
Parameters: element (str): The element to hover over.
461+
462+
Default tries to hover something in the chrome context
463+
"""
464+
if chrome:
465+
with self.driver.context(self.driver.CONTEXT_CHROME):
466+
self.actions.move_to_element(element).perform()
467+
else:
468+
self.actions.move_to_element(element).perform()
469+
return self
470+
471+
def get_all_children(self, element: WebElement, chrome=False) -> List[WebElement]:
472+
"""
473+
Gets all the children of a webelement
474+
"""
475+
children = None
476+
if chrome:
477+
with self.driver.context(self.driver.CONTEXT_CHROME):
478+
children = element.find_elements(By.XPATH, "./*")
479+
else:
480+
children = element.find_elements(By.XPATH, "./*")
481+
return children
482+
457483
@property
458484
def loaded(self):
459485
"""
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import pytest
2+
from selenium.webdriver import Firefox
3+
4+
from modules.browser_object import Navigation
5+
6+
ALLOWED_RGB_BEFORE_VALUES = set(
7+
["rgba(207, 207, 216, 0.33)", "color(srgb 0 0 0 / 0.13)", "rgba(0, 0, 0, 0.33)"]
8+
)
9+
ALLOWED_RGB_AFTER_VALUES = set(
10+
["color(srgb 0 0 0 / 0.6)", "color(srgb 0.984314 0.984314 0.996078 / 0.6)"]
11+
)
12+
13+
14+
# Set search region
15+
@pytest.fixture()
16+
def add_prefs():
17+
return [
18+
("browser.search.region", "US"),
19+
]
20+
21+
22+
def test_intervention_card_refresh(driver: Firefox):
23+
"""
24+
C1365204.1: regular firefox, check the intervention card
25+
"""
26+
# instantiate objects and type in search bar
27+
nav = Navigation(driver).open()
28+
nav.set_awesome_bar()
29+
nav.type_in_awesome_bar("refresh firefox")
30+
31+
# get relevant items
32+
refresh_text = nav.get_element("fx-refresh-text")
33+
refresh_button = nav.get_element("fx-refresh-button")
34+
help_menu_button = nav.get_element("fx-refresh-menu")
35+
36+
# ensure the text is correct
37+
assert (
38+
refresh_text.get_attribute("innerHTML")
39+
== "Restore default settings and remove old add-ons for optimal performance."
40+
)
41+
42+
# ensure the color before hover
43+
button_background = refresh_button.value_of_css_property("background-color")
44+
assert button_background in ALLOWED_RGB_BEFORE_VALUES
45+
nav.hover_over_element(refresh_button, chrome=True)
46+
47+
# ensure there is a hover state
48+
new_button_background = refresh_button.value_of_css_property("background-color")
49+
assert new_button_background in ALLOWED_RGB_AFTER_VALUES
50+
# repeated from before but with the 3 dots menu button
51+
help_menu_background = help_menu_button.value_of_css_property("background-color")
52+
assert help_menu_background in ALLOWED_RGB_BEFORE_VALUES
53+
assert help_menu_button.get_attribute("open") is None
54+
nav.hover_over_element(help_menu_button, chrome=True)
55+
56+
new_help_menu_background = help_menu_button.value_of_css_property(
57+
"background-color"
58+
)
59+
assert new_help_menu_background in ALLOWED_RGB_AFTER_VALUES
60+
61+
# ensure the popup appears
62+
help_menu_button.click()
63+
assert help_menu_button.get_attribute("open") == "true"
64+
assert nav.get_element("fx-refresh-menu-get-help-item-get-help") is not None
65+
66+
# get the number of options (search results)
67+
search_results_container = nav.get_element("search-results-container")
68+
search_results = nav.get_all_children(search_results_container, chrome=True)
69+
assert len(search_results) == 2

tests/form_autofill/test_address_autofill_attribute.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def test_address_attribute_selection(driver: Firefox, country_code: str):
3232
# Get the first element from the autocomplete dropdown
3333
first_item = autofill_popup_panel.get_nth_element(1)
3434
actual_value = autofill_popup_panel.hover_over_element(
35-
first_item
35+
first_item, chrome=True
3636
).get_primary_value(first_item)
3737

3838
# Get the primary value (street address) from the first item in the dropdown and assert that the actual value

tests/form_autofill/test_name_autofill_attribute.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def test_address_attribute_selection(driver: Firefox, country_code: str):
3232
# Get the first element from the autocomplete dropdown
3333
first_item = autofill_popup_panel.get_nth_element(1)
3434
actual_value = autofill_popup_panel.hover_over_element(
35-
first_item
35+
first_item, chrome=True
3636
).get_primary_value(first_item)
3737

3838
# Get the primary value (street address) from the first item in the dropdown and assert that the actual value

tests/form_autofill/test_telephone_autofill_attribute.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def test_telephone_attribute_autofill(driver: Firefox, country_code: str):
3333
first_item = autofill_popup_obj.get_nth_element("1")
3434

3535
# get relevant fields
36-
autofill_popup_obj.hover_over_element(first_item)
36+
autofill_popup_obj.hover_over_element(first_item, chrome=True)
3737
actual_value = autofill_popup_obj.get_primary_value(first_item)
3838
normalized_number = util.normalize_phone_number(actual_value)
3939
original_number = util.normalize_phone_number(autofill_sample_data.telephone)

0 commit comments

Comments
 (0)