本文整理汇总了Python中remote_connection.RemoteConnection类的典型用法代码示例。如果您正苦于以下问题:Python RemoteConnection类的具体用法?Python RemoteConnection怎么用?Python RemoteConnection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RemoteConnection类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, command_executor, browser_name, platform, version='',
javascript_enabled=True):
"""Create a new driver that will issue commands using the wire protocol.
Args:
command_executor - Either a command.CommandExecutor object or a string
that specifies the URL of a remote server to send commands to.
browser_name - A string indicating which browser to request a new
session for from the remote server. Should be one of
{mobile safari|firefox|internet explorer|htmlunit|chrome}.
platform - A string indicating the desired platform to request from
the remote server. Should be one of
{WINDOWS|XP|VISTA|MAC|LINUX|UNIX|ANY}.
version - A string indicating a specific browser version to request,
or an empty string ot use any available browser. Defaults to the
empty string.
javascript_enabled - Whether the requested browser should support
JavaScript. Defaults to True.
"""
self.command_executor = command_executor
if type(self.command_executor) is str:
self.command_executor = RemoteConnection(command_executor)
self.session_id = None
self.capabilities = {}
self.error_handler = ErrorHandler()
self.start_client()
self.start_session(browser_name=browser_name,
platform=platform,
version=version,
javascript_enabled=javascript_enabled)
示例2: __init__
def __init__(self, command_executor='http://localhost:4444/wd/hub',
desired_capabilities = None,
browser_profile=None):
"""Create a new driver that will issue commands using the wire protocol.
Args:
command_executor - Either a command.CommandExecutor object or a string
that specifies the URL of a remote server to send commands to.
desired_capabilities - Dictionary holding predefined values for starting
a browser
browser_profile: A browser profile directory as a Base64-encoded
zip file. Only used if Firefox is requested.
"""
if desired_capabilities is None:
raise WebDriverException(" Desired Capabilities can't be None")
self.command_executor = command_executor
if type(self.command_executor) is str:
self.command_executor = RemoteConnection(command_executor)
self.session_id = None
self.capabilities = {}
self.error_handler = ErrorHandler()
self.start_client()
self.start_session(desired_capabilities, browser_profile)
示例3: __init__
def __init__(self, command_executor='http://127.0.0.1:4444/wd/hub',
desired_capabilities=None, browser_profile=None, proxy=None):
"""
Create a new driver that will issue commands using the wire protocol.
:Args:
- command_executor - Either a command.CommandExecutor object or a string that specifies the URL of a remote server to send commands to.
- desired_capabilities - Dictionary holding predefined values for starting a browser
- browser_profile - A selenium.webdriver.firefox.firefox_profile.FirefoxProfile object. Only used if Firefox is requested.
"""
if desired_capabilities is None:
raise WebDriverException("Desired Capabilities can't be None")
if not isinstance(desired_capabilities, dict):
raise WebDriverException("Desired Capabilities must be a dictionary")
if proxy is not None:
proxy.add_to_capabilities(desired_capabilities)
self.command_executor = command_executor
if type(self.command_executor) is str or type(self.command_executor) is unicode:
self.command_executor = RemoteConnection(command_executor)
self._is_remote = True
self.session_id = None
self.capabilities = {}
self.error_handler = ErrorHandler()
self.start_client()
self.start_session(desired_capabilities, browser_profile)
示例4: __init__
def __init__(self,server,clientType,tid,version='6.0'):
#版本不一样,支持的命令是不一样的
#self.clientRsphandler=RspHandler() # result 非0全部抛异常
#self.paramChecker=
#self.rsp_handler=RspHandler()
#日志模块
#self.LOG=
self._host=server
self._version=version
self._clientType=clientType
self._tid=tid
self._headers={"version":self._version,"tid":self._tid,"clientType":self._clientType}
self.command_executor=RemoteConnection(server,self._headers)
示例5: WebDriver
class WebDriver(object):
"""
Controls a browser by sending commands to a remote server.
This server is expected to be running the WebDriver wire protocol as defined
here: http://code.google.com/p/selenium/wiki/JsonWireProtocol
:Attributes:
- command_executor - The command.CommandExecutor object used to execute commands.
- error_handler - errorhandler.ErrorHandler object used to verify that the server did not return an error.
- session_id - The session ID to send with every command.
- capabilities - A dictionary of capabilities of the underlying browser for this instance's session.
"""
def __init__(self, command_executor='http://127.0.0.1:4444/wd/hub',
desired_capabilities=None, browser_profile=None):
"""
Create a new driver that will issue commands using the wire protocol.
:Args:
- command_executor - Either a command.CommandExecutor object or a string that specifies the URL of a remote server to send commands to.
- desired_capabilities - Dictionary holding predefined values for starting a browser
- browser_profile - A selenium.webdriver.firefox.firefox_profile.FirefoxProfile object. Only used if Firefox is requested.
"""
if desired_capabilities is None:
raise WebDriverException("Desired Capabilities can't be None")
self.command_executor = command_executor
if type(self.command_executor) is str:
self.command_executor = RemoteConnection(command_executor)
self.session_id = None
self.capabilities = {}
self.error_handler = ErrorHandler()
self.start_client()
self.start_session(desired_capabilities, browser_profile)
@property
def name(self):
"""Returns the name of the underlying browser for this instance.
:Usage:
- driver.name
"""
if 'browserName' in self.capabilities:
return self.capabilities['browserName']
else:
raise KeyError('browserName not specified in session capabilities')
def start_client(self):
"""
Called before starting a new session. This method may be overridden
to define custom startup behavior.
"""
pass
def stop_client(self):
"""
Called after executing a quit command. This method may be overridden
to define custom shutdown behavior.
"""
pass
def start_session(self, desired_capabilities, browser_profile=None):
"""
Creates a new session with the desired capabilities.
:Args:
- browser_name - The name of the browser to request.
- version - Which browser version to request.
- platform - Which platform to request the browser on.
- javascript_enabled - Whether the new session should support JavaScript.
- browser_profile - A selenium.webdriver.firefox.firefox_profile.FirefoxProfile object. Only used if Firefox is requested.
"""
if browser_profile:
desired_capabilities['firefox_profile'] = browser_profile.encoded
response = self.execute(Command.NEW_SESSION, {
'desiredCapabilities': desired_capabilities,
})
self.session_id = response['sessionId']
self.capabilities = response['value']
def _wrap_value(self, value):
if isinstance(value, dict):
converted = {}
for key, val in value.items():
converted[key] = self._wrap_value(val)
return converted
elif isinstance(value, WebElement):
return {'ELEMENT': value.id}
elif isinstance(value, list):
return list(self._wrap_value(item) for item in value)
else:
return value
def create_web_element(self, element_id):
"""
Creates a web element with the specified element_id.
"""
return WebElement(self, element_id)
def _unwrap_value(self, value):
if isinstance(value, dict) and 'ELEMENT' in value:
#.........这里部分代码省略.........
示例6: HecomMockClient
class HecomMockClient(object):
def __init__(self,server,clientType,tid,version='6.0'):
#版本不一样,支持的命令是不一样的
#self.clientRsphandler=RspHandler() # result 非0全部抛异常
#self.paramChecker=
#self.rsp_handler=RspHandler()
#日志模块
#self.LOG=
self._host=server
self._version=version
self._clientType=clientType
self._tid=tid
self._headers={"version":self._version,"tid":self._tid,"clientType":self._clientType}
self.command_executor=RemoteConnection(server,self._headers)
def handle_response(self,rsp,exceptcode= '0'):
if rsp.status_code!=200 :
rsp.raise_for_status()
#判断是非为json数据
try:
jsonRsp=rsp.json()
except:
raise RuntimeError( "decode json failed")
else:
logging.info('Got Response : %s' % jsonRsp)
if jsonRsp['result']!= exceptcode :
raise RuntimeError("command execute failed: %s return resultcode %s desc %s" % (self.currentCommand,jsonRsp['result'],jsonRsp['desc']))
return jsonRsp
def login(self,telPhone,pwd):
#要把header中的sessionid存下来
m=hashlib.md5()
m.update(pwd)
pwd=m.hexdigest()
account={"telPhone":telPhone,"password":pwd}
rsp = self.execute(Command.LOGIN,userStr=account)
jsonRsp = self.handle_response(Command.LOGIN,rsp)
#rsp.raise_for_status()
if jsonRsp.has_key('data') :
self._accountInfo=jsonRsp['data']
#print self._accountInfo
logging.info('accountInfo %s ' % (self._accountInfo))
self._headers["entCode"]=self._accountInfo["entCode"]
self._headers["loginId"]=self._accountInfo["imLoginId"]
self._headers["uid"]=self._accountInfo["uid"]
self._headers["sessionId"]=self._accountInfo["sessionId"]
self.command_executor.setHeaders(self._headers)
logging.info('headers change %s' % (self._headers))
return self._accountInfo
raise RuntimeError("get accountInfo Failed" )
return jsonRsp
#self.command_executor.setHeader(self._header)
#测试通过
def logout(self,apiArgs):
rsp =self.execute(Command.LOGOUT,userStr=apiArgs)
return self.handle_response(rsp)
def verificationPhone(self, apiArgs):
rsp =self.execute(Command.VERIFICATION_PHONE,userStr=apiArgs)
return self.handle_response(rsp,exceptcode='3')
def registerUser(self, apiArgs):
rsp =self.execute(Command.REGISTER_USER,userStr=apiArgs)
return self.handle_response(rsp)
def registerEnt(self, apiArgs):
rsp =self.execute(Command.REGISTER_ENT,userStr=apiArgs)
return self.handle_response(rsp)
def updateEnt(self, apiArgs):
rsp =self.execute(Command.UPDATE_ENT,userStr=apiArgs)
return self.handle_response(rsp)
def getEntDetail(self, apiArgs):
rsp =self.execute(Command.GET_ENT_DETAIL,userStr=apiArgs)
return self.handle_response(rsp)
def joinEnt(self, apiArgs):
rsp =self.execute(Command.JOIN_ENT,userStr=apiArgs)
return self.handle_response(rsp)
def examineJoinUser(self, apiArgs):
rsp =self.execute(Command.EXAMINE_JOIN_USER,userStr=apiArgs)
return self.handle_response(rsp)
def removeUser(self, apiArgs):
rsp =self.execute(Command.REMOVE_USER,userStr=apiArgs)
return self.handle_response(rsp)
def addDept(self, apiArgs):
rsp =self.execute(Command.ADD_DEPT,userStr=apiArgs)
#.........这里部分代码省略.........
示例7: WebDriver
class WebDriver(object):
"""Controls a browser by sending commands to a remote server.
This server is expected to be running the WebDriver wire protocol as defined
here:
http://code.google.com/p/selenium/wiki/JsonWireProtocol
Attributes:
command_executor - The command.CommandExecutor object used to execute
commands.
error_handler - errorhandler.ErrorHandler object used to verify that the
server did not return an error.
session_id - The session ID to send with every command.
capabilities - A dictionary of capabilities of the underlying browser for
this instance's session.
"""
def __init__(self, command_executor='http://localhost:4444/wd/hub',
desired_capabilities = None,
browser_profile=None):
"""Create a new driver that will issue commands using the wire protocol.
Args:
command_executor - Either a command.CommandExecutor object or a string
that specifies the URL of a remote server to send commands to.
desired_capabilities - Dictionary holding predefined values for starting
a browser
browser_profile: A browser profile directory as a Base64-encoded
zip file. Only used if Firefox is requested.
"""
if desired_capabilities is None:
raise WebDriverException(" Desired Capabilities can't be None")
self.command_executor = command_executor
if type(self.command_executor) is str:
self.command_executor = RemoteConnection(command_executor)
self.session_id = None
self.capabilities = {}
self.error_handler = ErrorHandler()
self.start_client()
self.start_session(desired_capabilities, browser_profile)
@property
def name(self):
"""Returns the name of the underlying browser for this instance."""
if 'browserName' in self.capabilities:
return self.capabilities['browserName']
else:
raise KeyError('browserName not specified in session capabilities')
def start_client(self):
"""Called before starting a new session.
This method may be overridden to define custom startup behavior.
"""
pass
def stop_client(self):
"""Called after executing a quit command.
This method may be overridden to define custom shutdown behavior.
"""
pass
def start_session(self, desired_capabilities, browser_profile=None):
"""Creates a new session with the desired capabilities.
Args:
browser_name: The name of the browser to request.
version: Which browser version to request.
platform: Which platform to request the browser on.
javascript_enabled: Whether the new session should support JavaScript.
browser_profile: A browser profile directory as a Base64-encoded
zip file. Only used if Firefox is requested.
"""
if browser_profile:
desired_capabilities['firefox_profile'] = browser_profile
response = self.execute(Command.NEW_SESSION, {
'desiredCapabilities': desired_capabilities
})
self.session_id = response['sessionId']
self.capabilities = response['value']
def _wrap_value(self, value):
if isinstance(value, dict):
converted = {}
for key, val in value.items():
converted[key] = self._wrap_value(val)
return converted
elif isinstance(value, WebElement):
return {'ELEMENT': value.id}
elif isinstance(value, list):
return list(self._wrap_value(item) for item in value)
else:
return value
def create_web_element(self, element_id):
#.........这里部分代码省略.........
示例8: WebDriver
class WebDriver(object):
"""Controls a browser by sending commands to a remote server.
This server is expected to be running the WebDriver wire protocol as defined
here:
http://code.google.com/p/selenium/wiki/JsonWireProtocol
Attributes:
command_executor - The command.CommandExecutor object used to execute
commands.
error_handler - errorhandler.ErrorHandler object used to verify that the
server did not return an error.
session_id - The session ID to send with every command.
capabilities - A dictionary of capabilities of the underlying browser for
this instance's session.
"""
def __init__(self, command_executor, browser_name, platform, version='',
javascript_enabled=True):
"""Create a new driver that will issue commands using the wire protocol.
Args:
command_executor - Either a command.CommandExecutor object or a string
that specifies the URL of a remote server to send commands to.
browser_name - A string indicating which browser to request a new
session for from the remote server. Should be one of
{mobile safari|firefox|internet explorer|htmlunit|chrome}.
platform - A string indicating the desired platform to request from
the remote server. Should be one of
{WINDOWS|XP|VISTA|MAC|LINUX|UNIX|ANY}.
version - A string indicating a specific browser version to request,
or an empty string ot use any available browser. Defaults to the
empty string.
javascript_enabled - Whether the requested browser should support
JavaScript. Defaults to True.
"""
self.command_executor = command_executor
if type(self.command_executor) is str:
self.command_executor = RemoteConnection(command_executor)
self.session_id = None
self.capabilities = {}
self.error_handler = ErrorHandler()
self.start_client()
self.start_session(browser_name=browser_name,
platform=platform,
version=version,
javascript_enabled=javascript_enabled)
@property
def name(self):
"""Returns the name of the underlying browser for this instance."""
if 'browserName' in self.capabilities:
return self.capabilities['browserName']
else:
raise KeyError('browserName not specified in session capabilities')
def start_client(self):
"""Called before starting a new session.
This method may be overridden to define custom startup behavior.
"""
pass
def stop_client(self):
"""Called after executing a quit command.
This method may be overridden to define custom shutdown behavior.
"""
pass
def start_session(self, browser_name, platform=None, version=None,
javascript_enabled=False):
"""Creates a new session with the desired capabilities.
Args:
browser_name: The name of the browser to request.
version: Which browser version to request.
platform: Which platform to request the browser on.
javascript_enabled: Whether the new session should support JavaScript.
"""
response = self._execute(Command.NEW_SESSION, {
'desiredCapabilities': {
'browserName': browser_name,
'platform': platform or 'ANY',
'version': version or '',
'javascriptEnabled': javascript_enabled
}
})
self.session_id = response['sessionId']
self.capabilities = response['value']
def _wrap_value(self, value):
if isinstance(value, dict):
converted = {}
for key, val in value.items():
converted[key] = self._wrap_value(val)
return converted
elif isinstance(value, WebElement):
#.........这里部分代码省略.........
示例9: WebDriver
class WebDriver(object):
"""Controls a browser by sending commands to a remote server.
This server is expected to be running the WebDriver wire protocol as defined
here: http://code.google.com/p/selenium/wiki/JsonWireProtocol
Attributes:
command_executor - The command.CommandExecutor object used to execute
commands.
error_handler - errorhandler.ErrorHandler object used to verify that the
server did not return an error.
session_id - The session ID to send with every command.
capabilities - A dictionary of capabilities of the underlying browser for
this instance's session."""
def __init__(
self, command_executor="http://127.0.0.1:4444/wd/hub", desired_capabilities=None, browser_profile=None
):
"""Create a new driver that will issue commands using the wire protocol.
Args:
command_executor - Either a command.CommandExecutor object or a string
that specifies the URL of a remote server to send commands to.
desired_capabilities - Dictionary holding predefined values for starting
a browser
browser_profile: A browser profile directory as a Base64-encoded
zip file. Only used if Firefox is requested.
"""
if desired_capabilities is None:
raise WebDriverException("Desired Capabilities can't be None")
self.command_executor = command_executor
if type(self.command_executor) is str:
self.command_executor = RemoteConnection(command_executor)
self.session_id = None
self.capabilities = {}
self.error_handler = ErrorHandler()
self.start_client()
self.start_session(desired_capabilities, browser_profile)
@property
def name(self):
"""Returns the name of the underlying browser for this instance.
Usage:
driver.name
"""
if "browserName" in self.capabilities:
return self.capabilities["browserName"]
else:
raise KeyError("browserName not specified in session capabilities")
def start_client(self):
"""Called before starting a new session. This method may be overridden
to define custom startup behavior."""
pass
def stop_client(self):
"""Called after executing a quit command. This method may be overridden
to define custom shutdown behavior."""
pass
def start_session(self, desired_capabilities, browser_profile=None):
"""Creates a new session with the desired capabilities.
Args:
browser_name: The name of the browser to request.
version: Which browser version to request.
platform: Which platform to request the browser on.
javascript_enabled: Whether the new session should support JavaScript.
browser_profile: A browser profile directory as a Base64-encoded
zip file. Only used if Firefox is requested.
"""
if browser_profile:
desired_capabilities["firefox_profile"] = browser_profile.encoded
response = self.execute(Command.NEW_SESSION, {"desiredCapabilities": desired_capabilities})
self.session_id = response["sessionId"]
self.capabilities = response["value"]
def _wrap_value(self, value):
if isinstance(value, dict):
converted = {}
for key, val in value.items():
converted[key] = self._wrap_value(val)
return converted
elif isinstance(value, WebElement):
return {"ELEMENT": value.id}
elif isinstance(value, list):
return list(self._wrap_value(item) for item in value)
else:
return value
def create_web_element(self, element_id):
"""Creates a web element with the specified element_id."""
return WebElement(self, element_id)
def _unwrap_value(self, value):
if isinstance(value, dict) and "ELEMENT" in value:
return self.create_web_element(value["ELEMENT"])
elif isinstance(value, list):
return list(self._unwrap_value(item) for item in value)
else:
return value
def execute(self, driver_command, params=None):
#.........这里部分代码省略.........
示例10: WebDriver
class WebDriver(object):
"""Controls a browser by sending commands to a remote server.
This server is expected to be running the WebDriver wire protocol as defined
here:
http://code.google.com/p/selenium/wiki/JsonWireProtocol
Attributes:
command_executor - The command.CommandExecutor object used to execute
commands.
error_handler - errorhandler.ErrorHandler object used to verify that the
server did not return an error.
session_id - The session ID to send with every command.
capabilities - A dictionary of capabilities of the underlying browser for
this instance's session.
"""
def __init__(self, command_executor, browser_name, platform, version="", javascript_enabled=True):
"""Create a new driver that will issue commands using the wire protocol.
Args:
command_executor - Either a command.CommandExecutor object or a string
that specifies the URL of a remote server to send commands to.
browser_name - A string indicating which browser to request a new
session for from the remote server. Should be one of
{mobile safari|firefox|internet explorer|htmlunit|chrome}.
platform - A string indicating the desired platform to request from
the remote server. Should be one of
{WINDOWS|XP|VISTA|MAC|LINUX|UNIX|ANY}.
version - A string indicating a specific browser version to request,
or an empty string ot use any available browser. Defaults to the
empty string.
javascript_enabled - Whether the requested browser should support
JavaScript. Defaults to True.
"""
self.command_executor = command_executor
if type(self.command_executor) is str:
self.command_executor = RemoteConnection(command_executor)
self.session_id = None
self.capabilities = {}
self.error_handler = ErrorHandler()
self.start_client()
self.start_session(
browser_name=browser_name, platform=platform, version=version, javascript_enabled=javascript_enabled
)
@property
def name(self):
"""Returns the name of the underlying browser for this instance."""
if "browserName" in self.capabilities:
return self.capabilities["browserName"]
else:
raise KeyError("browserName not specified in session capabilities")
def start_client(self):
"""Called before starting a new session.
This method may be overridden to define custom startup behavior.
"""
pass
def stop_client(self):
"""Called after executing a quit command.
This method may be overridden to define custom shutdown behavior.
"""
pass
def start_session(self, browser_name, platform=None, version=None, javascript_enabled=False):
"""Creates a new session with the desired capabilities.
Args:
browser_name: The name of the browser to request.
version: Which browser version to request.
platform: Which platform to request the browser on.
javascript_enabled: Whether the new session should support JavaScript.
"""
response = self.execute(
Command.NEW_SESSION,
{
"desiredCapabilities": {
"browserName": browser_name,
"platform": platform or "ANY",
"version": version or "",
"javascriptEnabled": javascript_enabled,
}
},
)
self.session_id = response["sessionId"]
self.capabilities = response["value"]
def _wrap_value(self, value):
if isinstance(value, dict):
converted = {}
for key, val in value.items():
converted[key] = self._wrap_value(val)
return converted
elif isinstance(value, WebElement):
#.........这里部分代码省略.........