Created
March 3, 2011 09:39
-
-
Save dnedbaylo/852560 to your computer and use it in GitHub Desktop.
PersistentWebdriver
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from selenium import webdriver | |
from selenium.webdriver.remote.remote_connection import RemoteConnection | |
from selenium.webdriver.remote.errorhandler import ErrorHandler | |
from selenium.webdriver.remote.command import Command | |
class PersistentWebdriver (webdriver.Remote): | |
def __init__(self, session_id=None, browser_name=''): | |
command_executor='http://localhost:4444/wd/hub' | |
platform = version = '' | |
javascript_enabled = True | |
self.command_executor = command_executor | |
if type(self.command_executor) is str: | |
self.command_executor = RemoteConnection(command_executor) | |
self.command_executor._commands['GET_SESSION'] = ('GET', '/session/$sessionId') | |
self.session_id = session_id | |
self.capabilities = {} | |
self.error_handler = ErrorHandler() | |
if session_id: | |
self.connect_to_session( | |
browser_name=browser_name, | |
platform=platform, | |
version=version, | |
javascript_enabled=javascript_enabled | |
) | |
else: | |
self.start_session( | |
browser_name=browser_name, | |
platform=platform, | |
version=version, | |
javascript_enabled=javascript_enabled | |
) | |
def connect_to_session(self, browser_name, platform, version, javascript_enabled): | |
response = self.execute('GET_SESSION', { | |
'desiredCapabilities': { | |
'browserName': browser_name, | |
'platform': platform or 'ANY', | |
'version': version or '', | |
'javascriptEnabled': javascript_enabled | |
}, | |
'sessionId': self.session_id | |
}) | |
self.session_id = response['sessionId'] | |
self.capabilities = response['value'] |
sorry, not really, i am not .net developer.
Could you please provide an example on how to instantiate this class? Does it still works, on current versions (2 years is quite a time)? I would be incredible grateful if you could. Thanks.
could you please provide an example
I am quite new to Selenium and Java Programming, can you please provide a example how to instantiate this class in selenium
Hello, based on you class I made some changes directly on webriver.py and finally achieved reuse the session on browser.
/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py
axelPalmerin/personal@fabddb3
Ej.
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
runDriver = sys.argv[1]
sessionId = sys.argv[2]
def setBrowser():
if eval(runDriver):
webdriver = w.Remote(command_executor='http://localhost:4444/wd/hub',
desired_capabilities=DesiredCapabilities.CHROME,
)
else:
webdriver = w.Remote(command_executor='http://localhost:4444/wd/hub',
desired_capabilities=DesiredCapabilities.CHROME,
session_id=sessionId)
url = webdriver.command_executor._url
session_id = webdriver.session_id
print url
print session_id
return webdriver
Amazing !!!
hey is this really working ?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey I am using webDriver in .net platform. Could you please suggest me the implementation of PersistentWebdriver Class which would run in .net ?