|
| 1 | +import logging |
| 2 | + |
| 3 | +import pytest |
| 4 | +from selenium.webdriver import Firefox |
| 5 | + |
| 6 | +from modules.browser_object import TabBar |
| 7 | +from modules.page_object import Navigation |
| 8 | +from modules.util import Utilities |
| 9 | + |
| 10 | +ALLOWED_RGB_BEFORE_VALUES_CARD = set(["rgba(0, 0, 0, 0)"]) |
| 11 | +ALLOWED_RGB_AFTER_VALUES_CARD = set( |
| 12 | + ["color(srgb 0.878824 0.878824 0.885882)", "color(srgb 0.334902 0.331765 0.36)"] |
| 13 | +) |
| 14 | +ALLOWED_RGB_VALUES_BEFORE_THREE_DOTS = set( |
| 15 | + [ |
| 16 | + "color(srgb 0.356863 0.356863 0.4 / 0.07)", |
| 17 | + "color(srgb 0.984314 0.984314 0.996078 / 0.07)", |
| 18 | + ] |
| 19 | +) |
| 20 | +ALLOWED_RGB_AFTER_VALUES_THREE_DOTS = set( |
| 21 | + [ |
| 22 | + "color(srgb 0.356863 0.356863 0.4 / 0.14)", |
| 23 | + "color(srgb 0.984314 0.984314 0.996078 / 0.14)", |
| 24 | + ] |
| 25 | +) |
| 26 | + |
| 27 | +REQUIRED_CONTEXT_MENU_ACTIONS_REGULAR_TILE = set( |
| 28 | + ["Pin", "Edit", "Open in a New Window", "Open in a New Private Window", "Dismiss"] |
| 29 | +) |
| 30 | + |
| 31 | +REQUIRED_CONTEXT_MENU_ACTIONS_SPONSORED_TILE = set( |
| 32 | + [ |
| 33 | + "Open in a New Window", |
| 34 | + "Open in a New Private Window", |
| 35 | + "Dismiss", |
| 36 | + "Our sponsors & your privacy", |
| 37 | + ] |
| 38 | +) |
| 39 | + |
| 40 | +# first value in a tuple is the index of the card, second is the status of sponsorship |
| 41 | +card_indices = [(3, False), (0, True)] |
| 42 | + |
| 43 | + |
| 44 | +@pytest.fixture() |
| 45 | +def add_prefs(): |
| 46 | + return [ |
| 47 | + ("browser.search.region", "US"), |
| 48 | + ] |
| 49 | + |
| 50 | + |
| 51 | +def test_default_tile_hover_states(driver: Firefox): |
| 52 | + """ |
| 53 | + C1533798.1: Ensure that hover states work correctly |
| 54 | + """ |
| 55 | + # instantiate objects |
| 56 | + nav = Navigation(driver).open() |
| 57 | + tabs = TabBar(driver) |
| 58 | + |
| 59 | + # open a new tab and switch to it |
| 60 | + tabs.new_tab_by_button() |
| 61 | + tabs.wait_for_num_tabs(2) |
| 62 | + driver.switch_to.window(driver.window_handles[-1]) |
| 63 | + top_card = nav.get_element("sponsored-site-card") |
| 64 | + |
| 65 | + # assert the hover state |
| 66 | + assert ( |
| 67 | + top_card.value_of_css_property("background-color") |
| 68 | + in ALLOWED_RGB_BEFORE_VALUES_CARD |
| 69 | + ) |
| 70 | + tabs.hover_over_element(top_card) |
| 71 | + assert ( |
| 72 | + top_card.value_of_css_property("background-color") |
| 73 | + in ALLOWED_RGB_AFTER_VALUES_CARD |
| 74 | + ) |
| 75 | + |
| 76 | + three_dot_menu = nav.get_element("sponsored-site-card-menu-button") |
| 77 | + |
| 78 | + # assert the hover state again for the three dots |
| 79 | + assert ( |
| 80 | + three_dot_menu.value_of_css_property("background-color") |
| 81 | + in ALLOWED_RGB_VALUES_BEFORE_THREE_DOTS |
| 82 | + ) |
| 83 | + tabs.hover_over_element(three_dot_menu) |
| 84 | + assert ( |
| 85 | + three_dot_menu.value_of_css_property("background-color") |
| 86 | + in ALLOWED_RGB_AFTER_VALUES_THREE_DOTS |
| 87 | + ) |
| 88 | + |
| 89 | + |
| 90 | +@pytest.mark.parametrize("index, sponsored", card_indices) |
| 91 | +def test_tile_context_menu_options(driver: Firefox, index: int, sponsored: bool): |
| 92 | + """ |
| 93 | + C1533798.2: Ensure that a website has the appropriate context menu actions in the tile. |
| 94 | + """ |
| 95 | + # initialize objects |
| 96 | + nav = Navigation(driver).open() |
| 97 | + tabs = TabBar(driver) |
| 98 | + util = Utilities() |
| 99 | + |
| 100 | + # open a new tab, switch to it and get the sponsored card |
| 101 | + tabs.new_tab_by_button() |
| 102 | + tabs.wait_for_num_tabs(2) |
| 103 | + driver.switch_to.window(driver.window_handles[-1]) |
| 104 | + suggested_cards = nav.get_element("sponsored-site-card", multiple=True) |
| 105 | + |
| 106 | + # pick the fourth card since it is not a sponsored tile |
| 107 | + card = suggested_cards[index] |
| 108 | + nav.hover_over_element(card) |
| 109 | + |
| 110 | + # press the three dots option |
| 111 | + three_dot_menu = nav.get_element( |
| 112 | + "sponsored-site-card-menu-button", parent_element=card |
| 113 | + ) |
| 114 | + three_dot_menu.click() |
| 115 | + |
| 116 | + # get all of the context menu actions |
| 117 | + context_menu_list = nav.get_element("sponsored-site-context-menu-list") |
| 118 | + child_options = nav.get_all_children(context_menu_list) |
| 119 | + logging.info(f"There are {len(child_options)} context options") |
| 120 | + |
| 121 | + # match appropriate regex to extract the word of the context menu option |
| 122 | + option_html_logs = [ |
| 123 | + option.get_attribute("innerHTML") |
| 124 | + for option in child_options |
| 125 | + if option.get_attribute("innerHTML") != "" |
| 126 | + ] |
| 127 | + |
| 128 | + matched_regex = util.match_regex( |
| 129 | + r"<button[^>]*><span[^>]*>([^<]*)</span></button>", option_html_logs |
| 130 | + ) |
| 131 | + |
| 132 | + # according to the status of sponsored, look at different context menu actions |
| 133 | + set_in_use = set() |
| 134 | + if sponsored: |
| 135 | + set_in_use = REQUIRED_CONTEXT_MENU_ACTIONS_SPONSORED_TILE |
| 136 | + else: |
| 137 | + set_in_use = REQUIRED_CONTEXT_MENU_ACTIONS_REGULAR_TILE |
| 138 | + |
| 139 | + # ensure we match each option |
| 140 | + for match in matched_regex: |
| 141 | + if match in set_in_use: |
| 142 | + set_in_use.remove(match) |
| 143 | + logging.info(f"Detected the context item: {match}") |
| 144 | + |
| 145 | + assert ( |
| 146 | + len(set_in_use) == 0 |
| 147 | + ), "Did not find all of the required context menu actions." |
0 commit comments