Ejemplo n.º 1
0
    def scroll_pages(self, height):
        """
        Take screenshots and scroll down between them.
        """
        good_offset = height / 2 - 40  # Constant browser chrome
        filename = self.page_filename(1)
        pixels_per_line = 100
        scroll_lines = max(1, good_offset / pixels_per_line)
        offsets = []
        top_pages = self.max_pages
        if top_pages > 2:
            top_pages -= 1  # enable jump to last page
        for page in range(2, top_pages + 1):
            if hasattr(self, 'scroll_down'):
                self.scroll_down(good_offset)
            else:
                for dummy in range(scroll_lines):
                    self.down()
            time.sleep(0.5)

            previous = filename
            filename = self.page_filename(page)
            self.screenshot(filename)
            self.check_screenshot(filename)
            offset = hashmatch.find_offset(previous, filename)

            if not offset:
                break
            offsets.append(offset)

            apparently = offset / scroll_lines
            if apparently == 0:
                if self.verbose:
                    print "Apparently no offset per keypress: %d/%d=%d" % (
                        offset, scroll_lines, apparently)
            elif apparently != pixels_per_line:
                pixels_per_line = apparently
                scroll_lines = max(1, min(good_offset / pixels_per_line, 40))
                if self.verbose:
                    print "%d pixels/keypress, %d keypresses/scroll" % (
                        pixels_per_line, scroll_lines)
        else:
            if top_pages == self.max_pages:
                return offsets
            self.scroll_bottom()
            time.sleep(0.5)
            previous2 = previous
            previous = filename
            filename = self.page_filename(self.max_pages)
            self.screenshot(filename)
            self.check_screenshot(filename)
            offset = hashmatch.find_offset(previous, filename)
            if offset:
                # Need enough overlap to avoid browser chrome between pages.
                offset = min(offset, height - 200)
                # Just another page.
                offsets.append(offset)
            else:
                # Check that it's not the same bottom page as before.
                if not hashmatch.find_offset(previous2, filename):
                    # Bottom page, just tack it on.
                    offsets.append(height - 200)
        return offsets
Ejemplo n.º 2
0
#!/usr/bin/env python
# browsershots.org - Test your web design in different browsers
# Copyright (C) 2007 Johann C. Rocholl <*****@*****.**>
#
# Browsershots is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Browsershots is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

"""
Find vertical offset between two PPM files.
"""

__revision__ = "$Rev: 2006 $"
__date__ = "$Date: 2007-08-19 19:32:52 -0500 (Sun, 19 Aug 2007) $"
__author__ = "$Author: johann $"

import sys
from shotfactory04.image import hashmatch

arg0, filename1, filename2 = sys.argv
print hashmatch.find_offset(filename1, filename2)
Ejemplo n.º 3
0
    def scroll_pages(self, height):
        """
        Take screenshots and scroll down between them.
        """
        good_offset = height / 2 - 40 # Constant browser chrome
        filename = self.page_filename(1)
        pixels_per_line = 100
        scroll_lines = max(1, good_offset / pixels_per_line)
        offsets = []
        top_pages = self.max_pages
        if top_pages > 2:
            top_pages -= 1 # enable jump to last page
        for page in range(2, top_pages + 1):
            previous = filename
            filename = self.page_filename(page)
            attempts = 1
            if hasattr(self, 'scroll_attempts'):
                attempts = self.scroll_attempts
            for attempt in range(attempts):
                if hasattr(self, 'scroll_down'):
                    self.scroll_down(good_offset)
                else:
                    for dummy in range(scroll_lines):
                        self.down()
                time.sleep(0.5)
                self.screenshot(filename)
                self.check_screenshot(filename)
                offset = hashmatch.find_offset(previous, filename)
                if offset:
                    break
                if attempt + 1 < attempts:
                    os.rename(filename, previous)
            if not offset:
                break
            offsets.append(offset)

            apparently = offset / scroll_lines
            if apparently == 0:
                if self.verbose:
                    print "Apparently no offset per keypress: %d/%d=%d" % (
                        offset, scroll_lines, apparently)
            elif apparently != pixels_per_line:
                pixels_per_line = apparently
                scroll_lines = max(1, min(good_offset / pixels_per_line, 40))
                if self.verbose:
                    print "%d pixels/keypress, %d keypresses/scroll" % (
                        pixels_per_line, scroll_lines)
        else:
            if top_pages == self.max_pages:
                return offsets
            self.scroll_bottom()
            time.sleep(0.5)
            previous2 = previous
            previous = filename
            filename = self.page_filename(self.max_pages)
            self.screenshot(filename)
            self.check_screenshot(filename)
            offset = hashmatch.find_offset(previous, filename)
            if offset:
                # Need enough overlap to avoid browser chrome between pages.
                offset = min(offset, height - 200)
                # Just another page.
                offsets.append(offset)
            else:
                # Check that it's not the same bottom page as before.
                if not hashmatch.find_offset(previous2, filename):
                    # Bottom page, just tack it on.
                    offsets.append(height - 200)
        return offsets
Ejemplo n.º 4
0
#!/usr/bin/env python
# browsershots.org - Test your web design in different browsers
# Copyright (C) 2007 Johann C. Rocholl <*****@*****.**>
#
# Browsershots is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Browsershots is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
Find vertical offset between two PPM files.
"""

__revision__ = "$Rev: 2006 $"
__date__ = "$Date: 2007-08-20 02:32:52 +0200 (Mon, 20 Aug 2007) $"
__author__ = "$Author: johann $"

import sys
from shotfactory04.image import hashmatch

arg0, filename1, filename2 = sys.argv
print hashmatch.find_offset(filename1, filename2)