@@ -27,75 +27,64 @@ def add_to_prefs_list():
27
27
TEST_URL = "https://www.w3schools.com/html/html5_geolocation.asp"
28
28
29
29
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 ):
30
+ @pytest .fixture ()
31
+ def temp_selectors ():
32
+ return {
33
+ "accept-choices" : {
34
+ "selectorData" : "accept-choices" ,
35
+ "strategy" : "id" ,
36
+ "groups" : [],
37
+ },
38
+ "geolocation-button-selector" : {
39
+ "selectorData" : "button.w3-btn" ,
40
+ "strategy" : "css" ,
41
+ "groups" : ["doNotCache" ],
42
+ },
43
+ "location-marker" : {
44
+ "selectorData" : "mapholder" ,
45
+ "strategy" : "id" ,
46
+ "groups" : ["doNotCache" ],
47
+ },
48
+ }
49
+
50
+
51
+ def test_allow_permission_on_geolocation_via_w3c_api (driver : Firefox , temp_selectors ):
68
52
"""
69
53
C15186 - Verify that geolocation is successfully shared when the user allows permission via the W3C Geolocation API
70
54
"""
71
55
72
56
# Instantiate Objects
73
57
nav = Navigation (driver )
74
58
web_page = GenericPage (driver , url = TEST_URL ).open ()
59
+ web_page .elements |= temp_selectors
75
60
tabs = TabBar (driver )
76
61
77
62
# Wait for the page to fully load and manually address the cookie banner if appears
78
63
nav .wait_for_page_to_load ()
79
- handle_cookie_banner (driver , web_page )
64
+ cookie_element = web_page .get_elements ("accept-choices" )
65
+ if cookie_element :
66
+ cookie_element [0 ].click ()
80
67
81
68
# Click the 'Try It' button and Allow the location sharing
82
- click_geolocation_button_trigger ( web_page )
69
+ web_page . click_on ( "geolocation-button-selector" )
83
70
nav .handle_geolocation_prompt (button_type = "primary" )
84
71
85
- # Assert that the location marker is displayed
86
- assert is_location_marker_displayed (web_page )
72
+ # Check that the location marker is displayed
73
+ # if map is displayed, style attribute will be available
74
+ web_page .element_visible ("location-marker" )
75
+ assert web_page .get_element ("location-marker" ).get_attribute ("style" )
87
76
88
77
# Open a new tab, because refresh will keep the allow state of the location for one hour or until the tab is closed
89
78
tabs .open_web_page_in_new_tab (web_page , num_tabs = 2 )
90
79
91
80
# 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" )
81
+ web_page .click_on ("geolocation-button-selector" )
82
+ nav .handle_geolocation_prompt (button_type = "primary" , remember_this_decision = True )
96
83
97
- # Assert that the location marker is displayed again
98
- assert is_location_marker_displayed (web_page )
84
+ # Check that the location marker is displayed
85
+ # if map is displayed, style attribute will be available
86
+ web_page .element_visible ("location-marker" )
87
+ assert web_page .get_element ("location-marker" ).get_attribute ("style" )
99
88
100
89
# Assert that the permission icon is displayed in address bar when in a new tab
101
90
tabs .open_web_page_in_new_tab (web_page , num_tabs = 3 )
@@ -104,39 +93,42 @@ def test_allow_permission_on_geolocation_via_w3c_api(driver: Firefox):
104
93
assert permission_icon .is_displayed ()
105
94
106
95
107
- def test_block_permission_on_geolocation_via_w3c_api (driver : Firefox ):
96
+ def test_block_permission_on_geolocation_via_w3c_api (driver : Firefox , temp_selectors ):
108
97
"""
109
98
C15186 - Verify that geolocation is not shared when the user blocks permission via the W3C Geolocation API
110
99
"""
111
100
112
101
# Instantiate Objects
113
102
nav = Navigation (driver )
114
103
web_page = GenericPage (driver , url = TEST_URL ).open ()
104
+ web_page .elements |= temp_selectors
115
105
tabs = TabBar (driver )
116
106
117
107
# Wait for the page to fully load and manually address the cookie banner if appears
118
108
nav .wait_for_page_to_load ()
119
- handle_cookie_banner (driver , web_page )
109
+ cookie_element = web_page .get_elements ("accept-choices" )
110
+ if cookie_element :
111
+ cookie_element [0 ].click ()
120
112
121
113
# Click the 'Try It' button and Block the location sharing
122
- click_geolocation_button_trigger ( web_page )
114
+ web_page . click_on ( "geolocation-button-selector" )
123
115
nav .handle_geolocation_prompt (button_type = "secondary" )
124
116
125
- # Assert that the location marker is not displayed
126
- assert not is_location_marker_displayed (web_page )
117
+ # Check that the location marker is displayed
118
+ # if map is not displayed, style attribute will not be available
119
+ assert not web_page .get_element ("location-marker" ).get_attribute ("style" )
127
120
128
121
# 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" )
122
+ tabs .open_web_page_in_new_tab (web_page , num_tabs = 2 )
123
+ web_page .click_on ("geolocation-button-selector" )
124
+ nav .handle_geolocation_prompt (button_type = "secondary" , remember_this_decision = True )
134
125
135
- # Assert that the location marker is not displayed
136
- assert not is_location_marker_displayed (web_page )
126
+ # Check that the location marker is displayed
127
+ # if map is not displayed, style attribute will not be available
128
+ assert not web_page .get_element ("location-marker" ).get_attribute ("style" )
137
129
138
130
# 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 )
131
+ tabs .open_web_page_in_new_tab (web_page , num_tabs = 3 )
140
132
with driver .context (driver .CONTEXT_CHROME ):
141
133
permission_icon = nav .get_element ("permissions-location-icon" )
142
134
assert permission_icon .is_displayed ()
0 commit comments