Skip to content

Commit 8b67205

Browse files
authored
Add knock knock to non_sponsored check (#673)
1 parent 2fc042d commit 8b67205

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

tests/address_bar_and_search/test_search_suggestions.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from time import sleep
2-
31
import pytest
42
from selenium.webdriver import Firefox
53

@@ -9,9 +7,8 @@
97

108
# Constants
119
SEARCH_TERM_SPONSORED = "iphone"
12-
SEARCH_TERM_NON_SPONSORED = "wikimedia"
10+
SEARCH_TERM_NON_SPONSORED = "wiki"
1311
RETRY_LIMIT = 5
14-
SECONDS = 3
1512

1613

1714
@pytest.fixture()
@@ -45,17 +42,10 @@ def test_search_suggests_enabled(driver: Firefox):
4542
)
4643

4744
# Check for sponsored suggestion
48-
# Trigger the suggests once. First time, it's not populated correctly in automation
49-
with driver.context(driver.CONTEXT_CHROME):
50-
actions.search(SEARCH_TERM_SPONSORED, with_enter=False)
51-
sleep(SECONDS)
52-
53-
# Then load up suggests again and check for sponsored suggestion
5445
found_sponsored = False
5546
retries = 0
5647
while not found_sponsored and retries < RETRY_LIMIT:
5748
actions.search(SEARCH_TERM_SPONSORED, with_enter=False)
58-
sleep(SECONDS) # Give Firefox time to populate suggests list
5949
with driver.context(driver.CONTEXT_CHROME):
6050
found_sponsored = any(
6151
item.get_attribute("aria-label") == "Sponsored"
@@ -67,10 +57,19 @@ def test_search_suggests_enabled(driver: Firefox):
6757
)
6858

6959
# Check for non-sponsored suggestion
70-
actions.search(SEARCH_TERM_NON_SPONSORED, with_enter=False)
71-
sleep(SECONDS) # Give Firefox time to populate suggests list
72-
with driver.context(driver.CONTEXT_CHROME):
73-
nav.get_element("firefox-suggest")
74-
titles = nav.get_elements("suggestion-titles")
75-
found_non_sponsored = any("Wikipedia" in title.text for title in titles)
76-
assert found_non_sponsored, "Non-sponsored suggestion not found"
60+
found_non_sponsored = False
61+
retries = 0
62+
while not found_non_sponsored and retries < RETRY_LIMIT:
63+
actions.search(SEARCH_TERM_NON_SPONSORED, with_enter=False)
64+
with driver.context(driver.CONTEXT_CHROME):
65+
try:
66+
nav.get_element("firefox-suggest")
67+
titles = nav.get_elements("suggestion-titles")
68+
found_non_sponsored = any("Wikipedia" in title.text for title in titles)
69+
break
70+
finally:
71+
retries = +1
72+
continue
73+
assert found_non_sponsored, (
74+
f"Non-sponsored suggestion not found after {RETRY_LIMIT} retries."
75+
)

0 commit comments

Comments
 (0)