<commit_before>"""
This is the Docker version of the Selenium plugin.
"""

import os
from nose.plugins import Plugin
from pyvirtualdisplay import Display
from selenium import webdriver
from seleniumbase.fixtures import constants


class SeleniumBrowser(Plugin):
    """
    The plugin for Selenium tests. Takes in key arguments and then
    creates a WebDriver object. All arguments are passed to the tests.

    The following variables are made to the tests:
    self.options.browser -- the browser to use (--browser)
    self.options.server -- the server used by the test (--server)
    self.options.port -- the port used by thest (--port)
    """
    name = 'selenium_docker'  # Usage: --with-selenium_docker

    def options(self, parser, env):
        super(SeleniumBrowser, self).options(parser, env=env)

        parser.add_option('--browser', action='store',
                          dest='browser',
                          choices=constants.Browser.VERSION.keys(),
                          default=constants.Browser.FIREFOX,
                          help="""Specifies the browser. Default: FireFox.
                               If you want to use Chrome, indicate that.""")
        parser.add_option('--browser_version', action='store',
                          dest='browser_version',
                          default="latest",
                          help="""The browser version to use. Explicitly select
                          a version number or use "latest".""")
        parser.add_option('--server', action='store', dest='servername',
                          default='localhost',
                          help="""Designates the server used by the test.
                               Default: localhost.""")
        parser.add_option('--port', action='store', dest='port',
                          default='4444',
                          help="""Designates the port used by the test.
                               Default: 4444.""")

    def configure(self, options, conf):
        super(SeleniumBrowser, self).configure(options, conf)
        self.display = Display(visible=0, size=(1200, 800))
        self.display.start()
        self.driver = self.__select_browser()
        self.options = options

    def beforeTest(self, test):
        """ Running Selenium locally will be handled differently
            from how Selenium is run remotely, such as from Jenkins. """

        try:
            self.driver = self.__select_browser()
            test.test.driver = self.driver
            test.test.browser = "firefox"
        except Exception as err:
            print "Error starting/connecting to Selenium:"
            print err
            os.kill(os.getpid(), 9)
        return self.driver

    def afterTest(self, test):
        try:
            self.driver.quit()
            self.display.stop()
        except:
            print "No driver to quit."

    def __select_browser(self):
        try:
            profile = webdriver.FirefoxProfile()
            profile.set_preference("reader.parse-on-load.enabled", False)<commit_msg>Demo Mode for the Docker Selenium plugin<commit_after>"""
This is the Docker version of the Selenium plugin.
"""

import os
from nose.plugins import Plugin
from pyvirtualdisplay import Display
from selenium import webdriver
from seleniumbase.fixtures import constants


class SeleniumBrowser(Plugin):
    """
    The plugin for Selenium tests. Takes in key arguments and then
    creates a WebDriver object. All arguments are passed to the tests.

    The following variables are made to the tests:
    self.options.browser -- the browser to use (--browser)
    self.options.server -- the server used by the test (--server)
    self.options.port -- the port used by thest (--port)
    """
    name = 'selenium_docker'  # Usage: --with-selenium_docker

    def options(self, parser, env):
        super(SeleniumBrowser, self).options(parser, env=env)

        parser.add_option('--browser', action='store',
                          dest='browser',
                          choices=constants.Browser.VERSION.keys(),
                          default=constants.Browser.FIREFOX,
                          help="""Specifies the browser. Default: FireFox.
                               If you want to use Chrome, indicate that.""")
        parser.add_option('--browser_version', action='store',
                          dest='browser_version',
                          default="latest",
                          help="""The browser version to use. Explicitly select
                          a version number or use "latest".""")
        parser.add_option('--server', action='store', dest='servername',
                          default='localhost',
                          help="""Designates the server used by the test.
                               Default: localhost.""")
        parser.add_option('--port', action='store', dest='port',
                          default='4444',
                          help="""Designates the port used by the test.
                               Default: 4444.""")
        parser.add_option('--demo_mode', action="store_true",
                          dest='demo_mode',
                          default=False,
                          help="""Using this slows down the automation so that
                               you can see what it's actually doing.""")
        parser.add_option('--demo_sleep', action='store', dest='demo_sleep',
                          default=None,
                          help="""Setting this overrides the Demo Mode sleep
                               time that happens after browser actions.""")

    def configure(self, options, conf):
        super(SeleniumBrowser, self).configure(options, conf)
        self.display = Display(visible=0, size=(1200, 800))
        self.display.start()
        self.driver = self.__select_browser()
        self.options = options

    def beforeTest(self, test):
        """ Running Selenium locally will be handled differently
            from how Selenium is run remotely, such as from Jenkins. """

        try:
            self.driver = self.__select_browser()
            test.test.driver = self.driver
            test.test.browser = "firefox"
            test.test.demo_mode = self.options.demo_mode
            test.test.demo_sleep = self.options.demo_sleep
        except Exception as err:
            print "Error starting/connecting to Selenium:"
            print err
            os.kill(os.getpid(), 9)
        return self.driver

    def afterTest(self, test):
        try:
            self.driver.quit()
            self.display.stop()
        except:
            print "No driver to quit."

    def __select_browser(self):
        try:
            profile = webdriver.FirefoxProfile()
            profile.set_preference("reader.parse-on-load.enabled", False)
{'fraction_non_alphanumeric': 0.09886429819452533, 'fraction_numerical': 0.0049504950495049506, 'mean_word_length': 1.7888753552578156, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '406074', 'n_tokens_mistral': 1742, 'n_tokens_neox': 1646, 'n_words': 505}