@@ -124,19 +124,19 @@ def set_viewport_size(cls, width, height):
124124
125125 cls .driver .set_window_size (width + delta , height )
126126
127- def assertScreenshot (self , element_or_selector , file , whitelist = [], threshold = 0 ):
127+ def assertScreenshot (self , element_or_selector , file , ignore = [], threshold = 0 ):
128128 """assert-style variant of compareScreenshot context manager
129129
130130 compareScreenshot() can be considerably more efficient for recording baselines by avoiding the need
131131 to load pages before checking whether we're actually going to save them. This function allows you
132132 to continue using normal unittest-style assertions if you don't need the efficiency benefits
133133 """
134134
135- with self .compareScreenshot (element_or_selector , file , whitelist = whitelist , threshold = threshold ):
135+ with self .compareScreenshot (element_or_selector , file , ignore = ignore , threshold = threshold ):
136136 pass
137137
138138 @contextmanager
139- def compareScreenshot (self , element_or_selector , file , whitelist = [], threshold = 0 ):
139+ def compareScreenshot (self , element_or_selector , file , ignore = [], threshold = 0 ):
140140 """
141141 Assert that a screenshot of an element is the same as a screenshot on disk,
142142 within a given threshold.
@@ -149,18 +149,25 @@ def compareScreenshot(self, element_or_selector, file, whitelist = [], threshold
149149 If a string, then assumed to be the filename for the screenshot,
150150 which will be appended with ``.png``. Otherwise assumed to be
151151 a file object for the baseline image.
152- :param whitelist:
153- element found by this array of css selector will be set to visibility hidden in order avoid making test fails
152+ :param ignore:
153+ Either a CSS selector as a string or a
154+ :py:class:`~needle.driver.NeedleWebElement` object that represents
155+ the element to be ignored in the screenshot comparison (element will disappear from image).
154156 :param threshold:
155157 The threshold for triggering a test failure.
156158 """
157159
158160 yield # To allow using this method as a context manager
159161
160- if len (whitelist ) > 0 :
161- for whiteListThis in whitelist :
162- script = "document.querySelector('" + whiteListThis + "').style.visibility = 'hidden'"
163- self .driver .execute_script (script )
162+ # Hiding element to be ignored in screenshot comparisons
163+ if len (ignore ) > 0 :
164+ for element_to_be_ignored in ignore :
165+ if not isinstance (element_to_be_ignored , NeedleWebElement ):
166+ element = self .driver .find_element_by_css_selector (element_to_be_ignored )
167+ else :
168+ element = element_to_be_ignored
169+ self .driver .execute_script ('arguments[0].style.visibility="hidden";' , element )
170+
164171
165172 if not isinstance (element_or_selector , NeedleWebElement ):
166173 element = self .driver .find_element_by_css_selector (element_or_selector )
0 commit comments