1
- from time import sleep
2
-
3
1
import pytest
4
2
from selenium .webdriver import Firefox
5
3
9
7
10
8
# Constants
11
9
SEARCH_TERM_SPONSORED = "iphone"
12
- SEARCH_TERM_NON_SPONSORED = "wikimedia "
10
+ SEARCH_TERM_NON_SPONSORED = "wiki "
13
11
RETRY_LIMIT = 5
14
- SECONDS = 3
15
12
16
13
17
14
@pytest .fixture ()
@@ -45,17 +42,10 @@ def test_search_suggests_enabled(driver: Firefox):
45
42
)
46
43
47
44
# 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
54
45
found_sponsored = False
55
46
retries = 0
56
47
while not found_sponsored and retries < RETRY_LIMIT :
57
48
actions .search (SEARCH_TERM_SPONSORED , with_enter = False )
58
- sleep (SECONDS ) # Give Firefox time to populate suggests list
59
49
with driver .context (driver .CONTEXT_CHROME ):
60
50
found_sponsored = any (
61
51
item .get_attribute ("aria-label" ) == "Sponsored"
@@ -67,10 +57,19 @@ def test_search_suggests_enabled(driver: Firefox):
67
57
)
68
58
69
59
# 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