Refactor seleniumrunner to work without having to delete any zope object.

parent b71717b0
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
# #
############################################################################# #############################################################################
from datetime import datetime
from erp5functionaltestreporthandler import ERP5TestReportHandler from erp5functionaltestreporthandler import ERP5TestReportHandler
from ERP5TypeFunctionalTestCase import Xvfb, Firefox, TimeoutError from ERP5TypeFunctionalTestCase import Xvfb, Firefox, TimeoutError
from time import sleep from time import sleep
...@@ -44,42 +45,34 @@ def run(args): ...@@ -44,42 +45,34 @@ def run(args):
while True: while True:
erp5_report = ERP5TestReportHandler(config['test_report_instance_url'], erp5_report = ERP5TestReportHandler(config['test_report_instance_url'],
config['project'] + '@' + config['suite_name']) config['project'] + '@' + config['suite_name'])
# Clean old test results if any
openUrl('%s/TestTool_cleanUpTestResults?__ac_name=%s&__ac_password=%s' % (
config['base_url'], config['user'], config['password']))
try: try:
if getStatus(config['base_url']) is not '': os.environ['DISPLAY'] = config['display']
print("ERROR : Impossible to clean old test result(s)") xvfb = Xvfb(config['etc_directory'], config['xvfb_binary'])
else: profile_dir = os.path.join(config['etc_directory'], 'profile')
# Environment is ready, we launch test. browser = Firefox(profile_dir, config['base_url'], config['browser_binary'])
os.environ['DISPLAY'] = config['display'] try:
xvfb = Xvfb(config['etc_directory'], config['xvfb_binary']) start = time.time()
xvfb.run()
profile_dir = os.path.join(config['etc_directory'], 'profile') profile_dir = os.path.join(config['etc_directory'], 'profile')
browser = Firefox(profile_dir, config['base_url'], config['browser_binary']) browser.run(test_url , xvfb.display)
try: erp5_report.reportStart()
start = time.time() while not isTestFinished(config['base_url']):
xvfb.run() time.sleep(10)
profile_dir = os.path.join(config['etc_directory'], 'profile') print("Test not finished yet.")
browser.run(test_url , xvfb.display) if (time.time() - start) > float(timeout):
erp5_report.reportStart() raise TimeoutError("Test took more than %s seconds" % timeout)
while getStatus(config['base_url']) is '': except TimeoutError:
time.sleep(10) continue
if (time.time() - start) > float(timeout): finally:
raise TimeoutError("Test took more them %s seconds" % timeout) browser.quit()
except TimeoutError: xvfb.quit()
continue print("Test has finished and Firefox has been killed.")
finally:
browser.quit() erp5_report.reportFinished(getStatus(config['base_url']).encode("utf-8",
xvfb.quit() "replace"))
erp5_report.reportFinished(getStatus(config['base_url']).encode("utf-8",
"replace")) print("Test finished and report sent, sleeping.")
# Clean test results for next test
openUrl('%s/TestTool_cleanUpTestResults?__ac_name=%s&__ac_password=%s' % (
config['base_url'], config['user'], config['password']))
print("Test finished and report sent, sleeping.")
except urllib2.URLError, urlError: except urllib2.URLError, urlError:
print "Error: %s" % urlError.msg print "Error: %s" % urlError.msg
sleep(3600) sleep(3600)
...@@ -99,12 +92,29 @@ def openUrl(url): ...@@ -99,12 +92,29 @@ def openUrl(url):
f.close() f.close()
return file_content return file_content
def isTestFinished(url):
"""Fetch latest report. If report has been created less than 60 seconds ago,
it must be the current one.
Return true if test is finished, else return false.
"""
latest_report = openUrl('%s/portal_tests/TestTool_getLatestReportId/' % url)
if latest_report is '':
return False
latest_report_date = latest_report[7:]
time_delta = datetime.now() - \
datetime.strptime(latest_report_date, '%Y%m%d_%H%M%S' )
if time_delta.days is not 0:
return False
if time_delta.seconds < 120:
return True
return False
def getStatus(url): def getStatus(url):
try: try:
# Try 5 times. # Try 5 times.
for i in range(5): for i in range(5):
try: try:
status = openUrl('%s/portal_tests/TestTool_getResults' % (url)) status = openUrl('%s/portal_tests/TestTool_getResults/' % (url))
break break
except urllib2.URLError, urlError: except urllib2.URLError, urlError:
if i is 4: raise if i is 4: raise
...@@ -123,4 +133,4 @@ def assembleTestUrl(base_url, suite_name, user, password): ...@@ -123,4 +133,4 @@ def assembleTestUrl(base_url, suite_name, user, password):
test_url = "%s/%s/core/TestRunner.html?test=../test_suite_html&"\ test_url = "%s/%s/core/TestRunner.html?test=../test_suite_html&"\
"resultsUrl=%s/postResults&auto=on&__ac_name=%s&__ac_password=%s" % ( "resultsUrl=%s/postResults&auto=on&__ac_name=%s&__ac_password=%s" % (
base_url, suite_name, base_url, user, password) base_url, suite_name, base_url, user, password)
return test_url return test_url
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment