@@ -20,82 +20,74 @@ def add_to_prefs_list():
20
20
"geo.provider.network.url" ,
21
21
"https://www.googleapis.com/geolocation/v1/geolocate?key"
22
22
"=%GOOGLE_LOCATION_SERVICE_API_KEY%" ,
23
- )
23
+ ),
24
+ ("devtools.debugger.remote-enabled" , True ),
25
+ ("devtools.chrome.enabled" , True ),
26
+ ("ui.popup.disable_autohide" , True ),
24
27
]
25
28
26
29
27
30
TEST_URL = "https://www.w3schools.com/html/html5_geolocation.asp"
28
31
29
32
30
- def handle_cookie_banner (driver , web_page ):
31
- """
32
- Address the cookie banner manually if appears, as the cookie banner dismissal preference is not effective in this
33
- context
34
- """
35
- try :
36
- driver .switch_to .window (driver .window_handles [- 1 ])
37
- web_page .find_element (By .ID , "accept-choices" ).click ()
38
- except NoSuchElementException :
39
- # If the cookie banner is not found, continue with the test
40
- pass
41
-
42
-
43
- def click_geolocation_button_trigger (web_page ):
44
- """
45
- Clicks the 'Try It' button inside the webpage to trigger the geolocation prompt
46
- """
47
- geolocation_button_selector = (
48
- "button.w3-btn.w3-blue.w3-round[onclick='getLocation()']"
49
- )
50
- web_page .find_element (By .CSS_SELECTOR , geolocation_button_selector ).click ()
51
-
52
-
53
- def is_location_marker_displayed (web_page ):
54
- """
55
- Checks if the location marker ('You are here!') is displayed on the web page inside the map.
56
- """
57
- location_marker = web_page .find_elements (
58
- By .CSS_SELECTOR , "div[aria-label='You are here!'][role='img']"
59
- )
60
-
61
- if location_marker : # Check if the marker exists
62
- return location_marker [0 ].is_displayed ()
63
- else :
64
- return False
65
-
66
-
67
- def test_allow_permission_on_geolocation_via_w3c_api (driver : Firefox ):
33
+ @pytest .fixture ()
34
+ def temp_selectors ():
35
+ return {
36
+ "accept-choices" : {
37
+ "selectorData" : "accept-choices" ,
38
+ "strategy" : "id" ,
39
+ "groups" : [],
40
+ },
41
+ "geolocation-button-selector" : {
42
+ "selectorData" : "button.w3-btn" ,
43
+ "strategy" : "css" ,
44
+ "groups" : ["doNotCache" ],
45
+ },
46
+ "location-marker" : {
47
+ "selectorData" : "mapholder" ,
48
+ "strategy" : "id" ,
49
+ "groups" : ["doNotCache" ],
50
+ },
51
+ }
52
+
53
+
54
+ def test_allow_permission_on_geolocation_via_w3c_api (driver : Firefox , temp_selectors ):
68
55
"""
69
56
C15186 - Verify that geolocation is successfully shared when the user allows permission via the W3C Geolocation API
70
57
"""
71
58
72
59
# Instantiate Objects
73
60
nav = Navigation (driver )
74
61
web_page = GenericPage (driver , url = TEST_URL ).open ()
62
+ web_page .elements |= temp_selectors
75
63
tabs = TabBar (driver )
76
64
77
65
# Wait for the page to fully load and manually address the cookie banner if appears
78
66
nav .wait_for_page_to_load ()
79
- handle_cookie_banner (driver , web_page )
67
+ cookie_element = web_page .get_elements ("accept-choices" )
68
+ if cookie_element :
69
+ cookie_element [0 ].click ()
80
70
81
71
# Click the 'Try It' button and Allow the location sharing
82
- click_geolocation_button_trigger ( web_page )
72
+ web_page . click_on ( "geolocation-button-selector" )
83
73
nav .handle_geolocation_prompt (button_type = "primary" )
84
74
85
- # Assert that the location marker is displayed
86
- assert is_location_marker_displayed (web_page )
75
+ # Check that the location marker is displayed
76
+ # if map is displayed, style attribute will be available
77
+ web_page .element_visible ("location-marker" )
78
+ assert web_page .get_element ("location-marker" ).get_attribute ("style" )
87
79
88
80
# Open a new tab, because refresh will keep the allow state of the location for one hour or until the tab is closed
89
81
tabs .open_web_page_in_new_tab (web_page , num_tabs = 2 )
90
82
91
83
# Click the 'Try It' button and Allow the location sharing while choose the option Remember this decision
92
- click_geolocation_button_trigger (web_page )
93
- nav .element_clickable ("checkbox-remember-this-decision" )
94
- nav .click_on ("checkbox-remember-this-decision" )
95
- nav .handle_geolocation_prompt (button_type = "primary" )
84
+ web_page .click_on ("geolocation-button-selector" )
85
+ nav .handle_geolocation_prompt (button_type = "primary" , remember_this_decision = True )
96
86
97
- # Assert that the location marker is displayed again
98
- assert is_location_marker_displayed (web_page )
87
+ # Check that the location marker is displayed
88
+ # if map is displayed, style attribute will be available
89
+ web_page .element_visible ("location-marker" )
90
+ assert web_page .get_element ("location-marker" ).get_attribute ("style" )
99
91
100
92
# Assert that the permission icon is displayed in address bar when in a new tab
101
93
tabs .open_web_page_in_new_tab (web_page , num_tabs = 3 )
@@ -104,39 +96,42 @@ def test_allow_permission_on_geolocation_via_w3c_api(driver: Firefox):
104
96
assert permission_icon .is_displayed ()
105
97
106
98
107
- def test_block_permission_on_geolocation_via_w3c_api (driver : Firefox ):
99
+ def test_block_permission_on_geolocation_via_w3c_api (driver : Firefox , temp_selectors ):
108
100
"""
109
101
C15186 - Verify that geolocation is not shared when the user blocks permission via the W3C Geolocation API
110
102
"""
111
103
112
104
# Instantiate Objects
113
105
nav = Navigation (driver )
114
106
web_page = GenericPage (driver , url = TEST_URL ).open ()
107
+ web_page .elements |= temp_selectors
115
108
tabs = TabBar (driver )
116
109
117
110
# Wait for the page to fully load and manually address the cookie banner if appears
118
111
nav .wait_for_page_to_load ()
119
- handle_cookie_banner (driver , web_page )
112
+ cookie_element = web_page .get_elements ("accept-choices" )
113
+ if cookie_element :
114
+ cookie_element [0 ].click ()
120
115
121
116
# Click the 'Try It' button and Block the location sharing
122
- click_geolocation_button_trigger ( web_page )
117
+ web_page . click_on ( "geolocation-button-selector" )
123
118
nav .handle_geolocation_prompt (button_type = "secondary" )
124
119
125
- # Assert that the location marker is not displayed
126
- assert not is_location_marker_displayed (web_page )
120
+ # Check that the location marker is displayed
121
+ # if map is not displayed, style attribute will not be available
122
+ assert not web_page .get_element ("location-marker" ).get_attribute ("style" )
127
123
128
124
# Click the 'Try It' button and Block the location sharing while choose the option Remember this decision
129
- nav .refresh_page ()
130
- click_geolocation_button_trigger (web_page )
131
- nav .element_clickable ("checkbox-remember-this-decision" )
132
- nav .click_on ("checkbox-remember-this-decision" )
133
- nav .handle_geolocation_prompt (button_type = "secondary" )
125
+ tabs .open_web_page_in_new_tab (web_page , num_tabs = 2 )
126
+ web_page .click_on ("geolocation-button-selector" )
127
+ nav .handle_geolocation_prompt (button_type = "secondary" , remember_this_decision = True )
134
128
135
- # Assert that the location marker is not displayed
136
- assert not is_location_marker_displayed (web_page )
129
+ # Check that the location marker is displayed
130
+ # if map is not displayed, style attribute will not be available
131
+ assert not web_page .get_element ("location-marker" ).get_attribute ("style" )
137
132
138
133
# Assert that the permission icon is displayed in address bar when in a new tab
139
- tabs .open_web_page_in_new_tab (web_page , num_tabs = 2 )
134
+ tabs .open_web_page_in_new_tab (web_page , num_tabs = 3 )
140
135
with driver .context (driver .CONTEXT_CHROME ):
141
136
permission_icon = nav .get_element ("permissions-location-icon" )
142
137
assert permission_icon .is_displayed ()
0 commit comments