Take a screenshot

        Use the screenshot_name args when you want to take a
            screenshot for reference

        If the `runner:cache_screenshot` config is set to True then
            screenshot sharing all the same name will be saved only once

        The screenshot_path args is exclusively used by the
            proxy_driver:create_test_result function

        Args:
            screenshot_name (str) the name of the screenshot
            screenshot_path (str) the path of the screenshot

def take_screenshot(self, screenshot_name=None, screenshot_path=None):
        """Take a screenshot

        Use the screenshot_name args when you want to take a
            screenshot for reference

        If the `runner:cache_screenshot` config is set to True then
            screenshot sharing all the same name will be saved only once

        The screenshot_path args is exclusively used by the
            proxy_driver:create_test_result function

        Args:
            screenshot_name (str) the name of the screenshot
            screenshot_path (str) the path of the screenshot
        """
        self.info_log("Taking a screenshot...")

        save_to_db = False
        if screenshot_path:
            self._driver.save_screenshot(screenshot_path)
            self.debug_log("Screenshot taken (%s)" % screenshot_path)

        elif screenshot_name:
            take_screenshot = True
            if hasattr(self.runner, "screenshot_cache"):
                if self.runner.screenshot_cache.get(screenshot_name):
                    self.debug_log(
                        "screenshot(%s) found in cache" % screenshot_name
                    )
                    take_screenshot = False

            if take_screenshot:
                if self.test_instance._runner_dir:
                    _screenshot_name = '%s.png' % \
                        string_to_filename(screenshot_name)

                    relative_path = os.path.join(
                            self.test_instance._screenshot_relative_dir,
                            _screenshot_name
                    )

                    full_path = os.path.join(
                            self.test_instance._screenshot_dir,
                            _screenshot_name
                    )

                    self._driver.save_screenshot(
                        full_path
                    )
                    self.debug_log("Screenshot taken (%s)" % full_path)
                    save_to_db = True
        else:
            if self.test_instance._runner_dir:
                screenshot_name = get_timestamp()
                _screenshot_name = '%s.png' % screenshot_name

                relative_path = os.path.join(
                        self.test_instance._screenshot_relative_dir,
                        _screenshot_name
                )

                full_path = os.path.join(
                        self.test_instance._screenshot_dir,
                        _screenshot_name
                )

                self._driver.save_screenshot(
                    full_path
                )
                self.debug_log("Screenshot taken (%s)" % full_path)
                save_to_db = True

        if save_to_db:
            with DbSessionContext(BROME_CONFIG['database']['mongo_database_name']) as session:  # noqa
                capabilities = {
                    'browserName': self.capabilities['browserName'],
                    'platform': self.capabilities['platform'],
                    'version': self.capabilities['version']
                }
                screenshot = Testscreenshot()
                screenshot.browser_capabilities = capabilities
                screenshot.browser_id = self.get_id()
                # TODO support s3
                screenshot.location = 'local_file_system'
                screenshot.root_path = self.test_instance._runner.root_test_result_dir  # noqa
                screenshot.file_path = relative_path
                screenshot.extra_data = {}
                screenshot.title = screenshot_name
                screenshot.test_instance_id = self.test_instance._test_instance_id  # noqa
                screenshot.test_batch_id = self.test_instance._test_batch_id  # noqa

                session.save(screenshot, safe=True)