class WebDriverTestCase(TestCase, WebPage):
    def __init__(self, config):
        logger.debug("Initializing Test Case:: %s" % self.__class__.__name__)
        super(WebDriverTestCase, self).__init__(config)
        self.browser = None
        self.current_test_method = None
        self.current_test_id = None
        self.current_screen_shots = {}

    def start_browser(self):
        self.browser = Browser(self.config.options.browser.lower())

    def take_screenshot(self):
        try:
            if self.browser is not None:
                logger.debug("Taking snapshot")
                counter = 1
                if self.current_screen_shots.has_key(self.current_test_method):
                    counter = len(self.current_screen_shots[
                        self.current_test_method]) + 1
                file_name = "%s_%s_%s_%d.png" % (
                    self.current_test_id, self.__class__.__name__,
                    self.current_test_method, counter)
                screenshot_file = os.path.join(self.config.screenshots_dir,
                                               file_name)
                logger.debug("Snapshot file: %s" % screenshot_file)
                self.browser.get_screenshot_as_file(screenshot_file)
                logger.debug("Snapshot taken")
                if not self.current_screen_shots.has_key(
                        self.current_test_method):
                    self.current_screen_shots[self.current_test_method] = [
                        file_name
                    ]
                else:
                    self.current_screen_shots[self.current_test_method].append(
                        file_name)
            else:
                logger.debug(
                    "Browser is not set. No screenshot would be taken.")
        except Exception, e:
            logger.error("Error while taking snapshot: %s" % str(e))
            import traceback
            logger.debug(traceback.format_exc())
class WebDriverTestCase(TestCase, WebPage):
    def __init__(self, config):
        logger.debug("Initializing Test Case:: %s" % self.__class__.__name__)
        super(WebDriverTestCase, self).__init__(config)
        self.browser = None
        self.current_test_method = None
        self.current_test_id = None
        self.current_screen_shots = {}

    def start_browser(self):
        self.browser = Browser(self.config.options.browser.lower())

    def take_screenshot(self):
        try:
            if self.browser is not None:
                logger.debug("Taking snapshot")
                counter = 1
                if self.current_screen_shots.has_key(self.current_test_method):
                    counter = len(self.current_screen_shots[self.current_test_method]) + 1
                file_name = "%s_%s_%s_%d.png" % (
                    self.current_test_id,
                    self.__class__.__name__,
                    self.current_test_method,
                    counter,
                )
                screenshot_file = os.path.join(self.config.screenshots_dir, file_name)
                logger.debug("Snapshot file: %s" % screenshot_file)
                self.browser.get_screenshot_as_file(screenshot_file)
                logger.debug("Snapshot taken")
                if not self.current_screen_shots.has_key(self.current_test_method):
                    self.current_screen_shots[self.current_test_method] = [file_name]
                else:
                    self.current_screen_shots[self.current_test_method].append(file_name)
            else:
                logger.debug("Browser is not set. No screenshot would be taken.")
        except Exception, e:
            logger.error("Error while taking snapshot: %s" % str(e))
            import traceback

            logger.debug(traceback.format_exc())
 def start_browser(self):
     self.browser = Browser(self.config.options.browser.lower())
 def start_browser(self):
     self.browser = Browser(self.config.options.browser.lower())