def __init__(self, *args, seleniumwire_options=None, **kwargs): """Initialise a new Chrome WebDriver instance. Args: seleniumwire_options: The seleniumwire options dictionary. """ if seleniumwire_options is None: seleniumwire_options = {} self.proxy = backend.create(port=seleniumwire_options.get('port', 0), options=seleniumwire_options) if seleniumwire_options.get('auto_config', True): capabilities = kwargs.get('desired_capabilities') if capabilities is None: capabilities = DesiredCapabilities.CHROME capabilities = self._configure(capabilities, seleniumwire_options) kwargs['desired_capabilities'] = capabilities try: chrome_options = kwargs['options'] except KeyError: chrome_options = ChromeOptions() # Prevent Chrome from bypassing the Selenium Wire proxy # for localhost addresses. chrome_options.add_argument('proxy-bypass-list=<-loopback>') kwargs['options'] = chrome_options super().__init__(*args, **kwargs)
def _setup_backend(self, seleniumwire_options: Dict[str, Any]) -> Dict[str, Any]: """Create the backend proxy server and return its configuration in a dictionary. """ self.backend = backend.create( addr=seleniumwire_options.pop('addr', '127.0.0.1'), port=seleniumwire_options.get('port', 0), options=seleniumwire_options, ) addr, port = utils.urlsafe_address(self.backend.address()) config = { 'proxy': { 'proxyType': 'manual', 'httpProxy': '{}:{}'.format(addr, port), 'sslProxy': '{}:{}'.format(addr, port), } } if 'exclude_hosts' in seleniumwire_options: # Only pass noProxy when we have a value to pass config['proxy']['noProxy'] = seleniumwire_options['exclude_hosts'] config['acceptInsecureCerts'] = True return config
def __init__(self, *args, seleniumwire_options=None, **kwargs): """Initialise a new Firefox WebDriver instance. Args: seleniumwire_options: The seleniumwire options dictionary. """ if seleniumwire_options is None: seleniumwire_options = {} self.proxy = backend.create( addr=seleniumwire_options.pop('addr'), port=seleniumwire_options.get('port', 0), options=seleniumwire_options ) if seleniumwire_options.get('auto_config', True): capabilities = kwargs.get('desired_capabilities') if capabilities is None: capabilities = DesiredCapabilities.FIREFOX capabilities = self._configure(capabilities, seleniumwire_options) kwargs['desired_capabilities'] = capabilities super().__init__(*args, **kwargs)
def standalone_proxy(port=0, addr='127.0.0.1'): b = backend.create(port=int(port), addr=addr, options={ 'standalone': True, 'verify_ssl': False, }) # Configure shutdown handlers signal.signal(signal.SIGTERM, lambda *_: b.shutdown()) signal.signal(signal.SIGINT, lambda *_: b.shutdown())
def __init__(self, seleniumwire_options=None, *args, **kwargs): """Initialise a new Edge WebDriver instance. Args: seleniumwire_options: The seleniumwire options dictionary. """ if seleniumwire_options is None: seleniumwire_options = {} # Edge does not support automatic proxy configuration through the # DesiredCapabilities API, and thus has to be configured manually. # Whatever port number is chosen for that manual configuration has to # be passed in the options. assert 'port' in seleniumwire_options, 'You must set a port number in the seleniumwire_options' self.proxy = backend.create(port=seleniumwire_options.pop('port', 0), options=seleniumwire_options) super().__init__(*args, **kwargs)
def setUpClass(cls): options = {'backend': os.environ.get('SW_TEST_BACKEND', 'default')} cls.backend = backend.create(options=options) cls.configure_proxy(*cls.backend.address()[:2]) cls.httpbin = testutils.get_httpbin()
def setUpClass(cls): options = {'backend': os.environ.get('SW_TEST_BACKEND', 'default')} cls.backend = backend.create(options=options) cls._configure_proxy(*cls.backend.address())
def setUpClass(cls): cls.backend = backend.create() cls.configure_proxy(*cls.backend.address()[:2]) cls.httpbin = testutils.Httpbin( ) if os.name != 'nt' else 'https://httpbin.org'