Skip to content

Commit

Permalink
[py] Added socksVersion field in proxy class (#6983)
Browse files Browse the repository at this point in the history
  • Loading branch information
singh811 authored and lmtierney committed Jun 20, 2019
1 parent f61e76b commit 7c302be
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
24 changes: 24 additions & 0 deletions py/selenium/webdriver/common/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class Proxy(object):
socksProxy = ''
socksUsername = ''
socksPassword = ''
socksVersion = None

def __init__(self, raw=None):
"""
Expand Down Expand Up @@ -106,6 +107,8 @@ def __init__(self, raw=None):
self.socks_username = raw['socksUsername']
if 'socksPassword' in raw and raw['socksPassword'] is not None:
self.socks_password = raw['socksPassword']
if 'socksVersion' in raw and raw['socksVersion'] is not None:
self.socks_version = raw['socksVersion']

@property
def proxy_type(self):
Expand Down Expand Up @@ -300,6 +303,25 @@ def socks_password(self, value):
self.proxyType = ProxyType.MANUAL
self.socksPassword = value

@property
def socks_version(self):
"""
Returns socks proxy version setting.
"""
return self.socksVersion

@socks_version.setter
def socks_version(self, value):
"""
Sets socks proxy version setting.
:Args:
- value: The socks proxy version value.
"""
self._verify_proxy_type_compatibility(ProxyType.MANUAL)
self.proxyType = ProxyType.MANUAL
self.socksVersion = value

def _verify_proxy_type_compatibility(self, compatibleProxy):
if self.proxyType != ProxyType.UNSPECIFIED and self.proxyType != compatibleProxy:
raise Exception(" Specified proxy type (%s) not compatible with current setting (%s)" % (compatibleProxy, self.proxyType))
Expand Down Expand Up @@ -331,4 +353,6 @@ def add_to_capabilities(self, capabilities):
proxy_caps['socksUsername'] = self.socksUsername
if self.socksPassword:
proxy_caps['socksPassword'] = self.socksPassword
if self.socksVersion:
proxy_caps['socksVersion'] = self.socksVersion
capabilities['proxy'] = proxy_caps
4 changes: 4 additions & 0 deletions py/test/selenium/webdriver/common/proxy_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
'socksProxy': 'socks.proxy:65555',
'socksUsername': 'test',
'socksPassword': 'test',
'socksVersion': 5,
}

PAC_PROXY = {
Expand All @@ -48,6 +49,7 @@ def testCanAddManualProxyToDesiredCapabilities():
proxy.socksProxy = MANUAL_PROXY['socksProxy']
proxy.socksUsername = MANUAL_PROXY['socksUsername']
proxy.socksPassword = MANUAL_PROXY['socksPassword']
proxy.socksVersion = MANUAL_PROXY['socksVersion']

desired_capabilities = {}
proxy.add_to_capabilities(desired_capabilities)
Expand Down Expand Up @@ -105,6 +107,7 @@ def testCanInitManualProxy():
assert MANUAL_PROXY['socksProxy'] == proxy.socksProxy
assert MANUAL_PROXY['socksUsername'] == proxy.socksUsername
assert MANUAL_PROXY['socksPassword'] == proxy.socksPassword
assert MANUAL_PROXY['socksVersion'] == proxy.socksVersion


def testCanInitAutodetectProxy():
Expand All @@ -131,6 +134,7 @@ def testCanInitEmptyProxy():
assert '' == proxy.socksPassword
assert proxy.auto_detect is False
assert '' == proxy.proxy_autoconfig_url
assert proxy.socks_version is None

desired_capabilities = {}
proxy.add_to_capabilities(desired_capabilities)
Expand Down

0 comments on commit 7c302be

Please sign in to comment.