From 5ffbb5fadd4c38cac260d46c0f286982e62040d0 Mon Sep 17 00:00:00 2001 From: Andrea Bisello Date: Mon, 30 May 2016 16:42:05 +0200 Subject: [PATCH 1/4] added whitelist --- needle/cases.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/needle/cases.py b/needle/cases.py index d7ecca1..90ddd00 100644 --- a/needle/cases.py +++ b/needle/cases.py @@ -124,7 +124,7 @@ def set_viewport_size(cls, width, height): cls.driver.set_window_size(width + delta, height) - def assertScreenshot(self, element_or_selector, file, threshold=0): + def assertScreenshot(self, element_or_selector, file, whitelist=[], threshold=0): """assert-style variant of compareScreenshot context manager compareScreenshot() can be considerably more efficient for recording baselines by avoiding the need @@ -132,11 +132,11 @@ def assertScreenshot(self, element_or_selector, file, threshold=0): to continue using normal unittest-style assertions if you don't need the efficiency benefits """ - with self.compareScreenshot(element_or_selector, file, threshold=threshold): + with self.compareScreenshot(element_or_selector, file, whitelist=whitelist, threshold=threshold): pass @contextmanager - def compareScreenshot(self, element_or_selector, file, threshold=0): + def compareScreenshot(self, element_or_selector, file, whitelist = [], threshold=0): """ Assert that a screenshot of an element is the same as a screenshot on disk, within a given threshold. @@ -149,12 +149,19 @@ def compareScreenshot(self, element_or_selector, file, threshold=0): If a string, then assumed to be the filename for the screenshot, which will be appended with ``.png``. Otherwise assumed to be a file object for the baseline image. + :param whitelist: + element found by this array of css selector will be set to visibility hidden in order avoid making test fails :param threshold: The threshold for triggering a test failure. """ yield # To allow using this method as a context manager + if len(whitelist) > 0: + for whiteListThis in whitelist: + script = "document.querySelector('"+whiteListThis+"').style.visibility = 'hidden'" + self.driver.execute_script(script) + if not isinstance(element_or_selector, NeedleWebElement): element = self.driver.find_element_by_css_selector(element_or_selector) else: From 8887618cc61864c3407c22fc3a13b90cc6dde33b Mon Sep 17 00:00:00 2001 From: Andrea Bisello Date: Mon, 6 Jun 2016 17:18:43 +0200 Subject: [PATCH 2/4] 1)whitelist becomes ignore 2)element to be ignored now can be css selector or needle web element 3)querySelector is not used anymore in order to find the element --- needle/cases.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/needle/cases.py b/needle/cases.py index 90ddd00..2c3719a 100644 --- a/needle/cases.py +++ b/needle/cases.py @@ -124,7 +124,7 @@ def set_viewport_size(cls, width, height): cls.driver.set_window_size(width + delta, height) - def assertScreenshot(self, element_or_selector, file, whitelist=[], threshold=0): + def assertScreenshot(self, element_or_selector, file, ignore=[], threshold=0): """assert-style variant of compareScreenshot context manager compareScreenshot() can be considerably more efficient for recording baselines by avoiding the need @@ -132,11 +132,11 @@ def assertScreenshot(self, element_or_selector, file, whitelist=[], threshold=0) to continue using normal unittest-style assertions if you don't need the efficiency benefits """ - with self.compareScreenshot(element_or_selector, file, whitelist=whitelist, threshold=threshold): + with self.compareScreenshot(element_or_selector, file, ignore=ignore, threshold=threshold): pass @contextmanager - def compareScreenshot(self, element_or_selector, file, whitelist = [], threshold=0): + def compareScreenshot(self, element_or_selector, file, ignore = [], threshold=0): """ Assert that a screenshot of an element is the same as a screenshot on disk, within a given threshold. @@ -149,18 +149,25 @@ def compareScreenshot(self, element_or_selector, file, whitelist = [], threshold If a string, then assumed to be the filename for the screenshot, which will be appended with ``.png``. Otherwise assumed to be a file object for the baseline image. - :param whitelist: - element found by this array of css selector will be set to visibility hidden in order avoid making test fails + :param ignore: + Either a CSS selector as a string or a + :py:class:`~needle.driver.NeedleWebElement` object that represents + the element to be ignored in the screenshot comparison (element will disappear from image). :param threshold: The threshold for triggering a test failure. """ yield # To allow using this method as a context manager - if len(whitelist) > 0: - for whiteListThis in whitelist: - script = "document.querySelector('"+whiteListThis+"').style.visibility = 'hidden'" - self.driver.execute_script(script) + # Hiding element to be ignored in screenshot comparisons + if len(ignore) > 0: + for element_to_be_ignored in ignore: + if not isinstance(element_to_be_ignored, NeedleWebElement): + element = self.driver.find_element_by_css_selector(element_to_be_ignored) + else: + element = element_to_be_ignored + self.driver.execute_script('arguments[0].style.visibility="hidden";', element) + if not isinstance(element_or_selector, NeedleWebElement): element = self.driver.find_element_by_css_selector(element_or_selector) From 615f3212eaa2b4c7ed8f0d65d914291977030fbe Mon Sep 17 00:00:00 2001 From: Andrea Bisello Date: Mon, 13 Jun 2016 11:59:42 +0200 Subject: [PATCH 3/4] page for https://github.com/bfirsh/needle/issues/51 --- demo/viewport.html | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 demo/viewport.html diff --git a/demo/viewport.html b/demo/viewport.html new file mode 100644 index 0000000..d052b98 --- /dev/null +++ b/demo/viewport.html @@ -0,0 +1,15 @@ + + + + + Black Viewport Demo + + +
+ +
+
+ +
+ + \ No newline at end of file From cf8a079f09a2c08519d079104bc3bc5e2728c7ed Mon Sep 17 00:00:00 2001 From: Andrea Bisello Date: Mon, 13 Jun 2016 15:14:09 +0200 Subject: [PATCH 4/4] demo page for scrollable div --- demo/scroll.html | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 demo/scroll.html diff --git a/demo/scroll.html b/demo/scroll.html new file mode 100644 index 0000000..4aa2010 --- /dev/null +++ b/demo/scroll.html @@ -0,0 +1,14 @@ + + + + + Black Viewport Demo + + +
+
+
+
+
+ + \ No newline at end of file