Beispiel #1
0
    def setUpClass(cls):
        """
        Override NeedleTestCase's setUpClass method so that it does not
        start up the browser once for each testcase class.
        Instead we start up the browser once per TestCase instance,
        in the setUp method.
        """
        if hasattr(cls, 'engine_class'):
            # Instantiate the diff engine.
            # This will allow Needle's flexibility for choosing which you want to use.
            # These lines are copied over from Needle's setUpClass method.
            klass = import_from_string(cls.engine_class)
            cls.engine = klass()

            # Needle's setUpClass method set up the driver (thus starting up the browser),
            # and set the initial window position and viewport size.
            # Those lines are not copied here into WebAppTest's setUpClass method,
            # but instead into our setUp method. This follows our paradigm of starting
            # up a new browser session for each TestCase.

            # Now call the super of the NeedleTestCase class, so that we get everything
            # from the setUpClass method of its parent (unittest.TestCase).
            super(BaseTestCase, cls).setUpClass()  # pylint: disable=bad-super-call
        else:
            super(WebAppTest, cls).setUpClass()
Beispiel #2
0
    def engine(self):
        """Return image processing engine

        :return:
        """

        return import_from_string(self.engine_class)()
Beispiel #3
0
    def setUpClass(cls):
        """
        Override NeedleTestCase's setUpClass method so that it does not
        start up the browser once for each testcase class.
        Instead we start up the browser once per TestCase instance,
        in the setUp method.
        """
        if hasattr(cls, 'engine_class'):
            # Instantiate the diff engine.
            # This will allow Needle's flexibility for choosing which you want to use.
            # These lines are copied over from Needle's setUpClass method.
            klass = import_from_string(cls.engine_class)
            cls.engine = klass()

            # Needle's setUpClass method set up the driver (thus starting up the browser),
            # and set the initial window position and viewport size.
            # Those lines are not copied here into WebAppTest's setUpClass method,
            # but instead into our setUp method. This follows our paradigm of starting
            # up a new browser session for each TestCase.

            # Now call the super of the NeedleTestCase class, so that we get everything
            # from the setUpClass method of its parent (unittest.TestCase).
            super(BaseTestCase, cls).setUpClass()  # pylint: disable=bad-super-call
        else:
            super(WebAppTest, cls).setUpClass()
Beispiel #4
0
    def __init__(self, driver, **kwargs):

        self.options = kwargs
        self.driver = driver

        self.save_baseline = kwargs.get('save_baseline', False)
        self.cleanup_on_success = kwargs.get('cleanup_on_success', False)

        self.baseline_dir = kwargs.get('baseline_dir', DEFAULT_BASELINE_DIR)
        self.output_dir = kwargs.get('output_dir', DEFAULT_OUTPUT_DIR)

        # Create the output and baseline directories if they do not yet exist.
        for directory in (self.baseline_dir, self.output_dir):
            self._create_dir(directory)

        dimensions = kwargs.get('viewport_size', DEFAULT_VIEWPORT_SIZE)
        viewport_size = re.match(r'(?P<width>\d+)\s?[xX]\s?(?P<height>\d+)',
                                 dimensions)

        # Set viewport position, size
        self.driver.set_window_position(0, 0)
        viewport_dimensions = (int(viewport_size.group('width')), int(viewport_size.group('height'))) if viewport_size \
            else (int(DEFAULT_VIEWPORT_SIZE.split('x')[0]), int(DEFAULT_VIEWPORT_SIZE.split('x')[1]))

        self.driver.set_window_size(*viewport_dimensions)

        # Instantiate the diff engine
        engine_config = kwargs.get('needle_engine', 'pil').lower()
        self.engine_class = self.ENGINES.get(engine_config, DEFAULT_ENGINE)

        klass = import_from_string(self.engine_class)
        self.engine = klass()