Beispiel #1
0
 def configure(self, options, conf):
     '''
     Configure the plug-in.
     '''
     # Call super
     super(SeleniumDriverPlugin, self).configure(options, conf)
     # Check if enabled
     if self.enabled:
         # Check if an environment is provided
         if not options.env:
             # Not provided, raise
             raise ValueError('please provide a driver environment')
         # Get the environment
         self.env = DriverConfig(all_config_files(options, conf)).getenv(options.env)
Beispiel #2
0
class SeleniumDriverPlugin(plugins.Plugin):
    '''Provide a WebDriver to the tests.'''
    
    name = 'selenium-driver'

    def options(self, parser, env):
        '''
        Add plug-in options.
        '''
        # Call super
        super(SeleniumDriverPlugin, self).options(parser, env)
        # Add environment input
        parser.add_option('--selenium-driver', action='store', dest='env', help='Enable the provided environment.')

    def configure(self, options, conf):
        '''
        Configure the plug-in.
        '''
        # Call super
        super(SeleniumDriverPlugin, self).configure(options, conf)
        # Check if enabled
        if self.enabled:
            # Check if an environment is provided
            if not options.env:
                # Not provided, raise
                raise ValueError('please provide a driver environment')
            # Get the environment
            self.env = DriverConfig(all_config_files(options, conf)).getenv(options.env)

    def eligible(self, test):
        '''
        Check if this is a SELENIUM test.
        '''
        # Check if this test has a context and that the flag is available
        return hasattr(test, 'context') and getattr(test.context, 'enable_selenium_driver', False)

    def startTest(self, test):
        '''
        Before test starts, create a driver.
        '''
        # Check if this is a SELENIUM test
        if self.eligible(test):
            # If it is, inject a driver
            test.context.driver = self.env.create()

    def stopTest(self, test):
        '''
        After test, cleanup.
        '''
        # Check if was a SELENIUM test
        if self.eligible(test):
            # If quit already called in test, produces a URLError, so catch it
            try:
                # Quit
                test.context.driver.quit()
            # Ignore error if quit already
            except URLError: pass
            # Reset
            test.context.driver = None
Beispiel #3
0
 def configure(self, options, conf):
     '''
     Configure the plug-in.
     '''
     # Call super
     super(SeleniumDriverPlugin, self).configure(options, conf)
     # Check if enabled
     if self.enabled:
         # Check if an environment is provided
         if not options.env:
             # Not provided, raise
             raise ValueError('please provide a driver environment')
         # Get the environment
         self.env = DriverConfig(all_config_files(options, conf)).getenv(options.env)
Beispiel #4
0
 def __init__(self, test_labels, options):
     '''
     Store the environment configuration.
     '''
     # Call super
     super(Task, self).__init__(test_labels, options)
     # Get the environment
     selenium_driver = options.get('selenium_driver')
     # Check if an environment is provided
     if not selenium_driver:
         # Not provided, raise
         raise ValueError('please provide a driver environment with the --selenium-driver option')
     # Get the global environments variable containing the SELENIUM environment
     global env
     # Store the environment
     env = DriverConfig(all_config_files(options)).getenv(selenium_driver)
Beispiel #5
0
class SeleniumDriverPlugin(plugins.Plugin):
    '''Provide a WebDriver to the tests.'''

    name = 'selenium-driver'

    def options(self, parser, env):
        '''
        Add plug-in options.
        '''
        # Call super
        super(SeleniumDriverPlugin, self).options(parser, env)
        # Add environment input
        parser.add_option('--selenium-driver',
                          action='store',
                          dest='env',
                          help='Enable the provided environment.')

    def configure(self, options, conf):
        '''
        Configure the plug-in.
        '''
        # Call super
        super(SeleniumDriverPlugin, self).configure(options, conf)
        # Check if enabled
        if self.enabled:
            # Check if an environment is provided
            if not options.env:
                # Not provided, raise
                raise ValueError('please provide a driver environment')
            # Get the environment
            self.env = DriverConfig(all_config_files(options,
                                                     conf)).getenv(options.env)

    def eligible(self, test):
        '''
        Check if this is a SELENIUM test.
        '''
        # Check if this test has a context and that the flag is available
        return hasattr(test, 'context') and getattr(
            test.context, 'enable_selenium_driver', False)

    def startTest(self, test):
        '''
        Before test starts, create a driver.
        '''
        # Check if this is a SELENIUM test
        if self.eligible(test):
            # If it is, inject a driver
            test.context.driver = self.env.create()

    def stopTest(self, test):
        '''
        After test, cleanup.
        '''
        # Check if was a SELENIUM test
        if self.eligible(test):
            # If quit already called in test, produces a URLError, so catch it
            try:
                # Quit
                test.context.driver.quit()
            # Ignore error if quit already
            except URLError:
                pass
            # Reset
            test.context.driver = None
Beispiel #6
0
class SeleniumDriverPlugin(plugins.Plugin):
    '''Provide a WebDriver to the tests.'''
    
    name = 'selenium-driver'

    def options(self, parser, env):
        '''
        Add plug-in options.
        '''
        # Call super
        super(SeleniumDriverPlugin, self).options(parser, env)
        # Add environment input
        parser.add_option('--selenium-driver', action='store', dest='env', help='Enable the provided environment.')

    def configure(self, options, conf):
        '''
        Configure the plug-in.
        '''
        # Call super
        super(SeleniumDriverPlugin, self).configure(options, conf)
        # Check if enabled
        if self.enabled:
            # Check if an environment is provided
            if not options.env:
                # Not provided, raise
                raise ValueError('please provide a driver environment')
            # Get the environment
            self.env = DriverConfig(all_config_files(options, conf)).getenv(options.env)

    def eligible(self, test):
        '''
        Check if this is a SELENIUM test.
        '''
        # Check if this test has a context and that the flag is available
        return hasattr(test, 'context') and getattr(test.context, 'enable_selenium_driver', False)

    def startTest(self, test):
        '''
        Before test starts, create a driver.
        '''
        # Check if this is a SELENIUM test
        if self.eligible(test):
            # If it is, inject a driver
            if hasattr(self.env, 'set_test_name'):
                self.env.set_test_name(str(test))

            # handle situation where provider limits number of concurrent selenium
            # sessions.  If this error is returned, wait 30 seconds and then
            # try creating the session again.  This is better than if the tests
            # fail due to this condition.
            while True:
                try:
                    driver = self.env.create()
                except selenium.common.exceptions.WebDriverException, e:
                    if str(e).find('please wait for a test to finish') != -1:
                        print 'waiting for available selenium session...'
                        time.sleep(30)
                    else:
                        raise
                else:
                    # Success.  Store the driver and break out of loop.
                    test.context.driver = driver
                    break