Polish seleniumrunner, use work from ERP5

parent 9603db97
This diff is collapsed.
...@@ -61,7 +61,8 @@ class Recipe(BaseSlapRecipe): ...@@ -61,7 +61,8 @@ class Recipe(BaseSlapRecipe):
base_url = self.parameter_dict['url'], base_url = self.parameter_dict['url'],
browser_argument_list = [], browser_argument_list = [],
user = self.parameter_dict['user'], user = self.parameter_dict['user'],
password = self.parameter_dict['password']) password = self.parameter_dict['password'],
etc_directory = self.etc_directory)
# Check wanted browser XXX-Cedric not yet used but can be useful # Check wanted browser XXX-Cedric not yet used but can be useful
#if self.parameter_dict.get('browser', None) is None: #if self.parameter_dict.get('browser', None) is None:
......
...@@ -48,6 +48,7 @@ IMAGE_RE = re.compile('<img[^>]*?>') ...@@ -48,6 +48,7 @@ IMAGE_RE = re.compile('<img[^>]*?>')
TEST_ERROR_TITLE_RE = re.compile('(?:error.gif.*?>|title status_failed"><td[^>]*>)([^>]*?)</td></tr>', re.S) TEST_ERROR_TITLE_RE = re.compile('(?:error.gif.*?>|title status_failed"><td[^>]*>)([^>]*?)</td></tr>', re.S)
TEST_RESULT_RE = re.compile('<div style="padding-top: 10px;">\s*<p>\s*' TEST_RESULT_RE = re.compile('<div style="padding-top: 10px;">\s*<p>\s*'
'<img.*?</div>\s.*?</div>\s*', re.S) '<img.*?</div>\s.*?</div>\s*', re.S)
DURATION_RE = re.compile('<th[^>]*>Elapsed time \(sec\)</th>\n\s*<td[^>]*>([^<]*)')
TEST_ERROR_RESULT_RE = re.compile('.*(?:error.gif|title status_failed).*', re.S) TEST_ERROR_RESULT_RE = re.compile('.*(?:error.gif|title status_failed).*', re.S)
...@@ -113,7 +114,7 @@ class ERP5TestReportHandler: ...@@ -113,7 +114,7 @@ class ERP5TestReportHandler:
) )
self.connection_helper = ConnectionHelper(url) self.connection_helper = ConnectionHelper(url)
self.suite_name = suite_name self.suite_name = suite_name
self.test_id = "20111026-18C84076DE29E8" self.test_id = "20111025-1F0BF8263511D4"
def reportStart(self): def reportStart(self):
# report that test is running # report that test is running
...@@ -125,62 +126,41 @@ class ERP5TestReportHandler: ...@@ -125,62 +126,41 @@ class ERP5TestReportHandler:
def reportFinished(self, out_file): def reportFinished(self, out_file):
# make file parsable by erp5_test_results # make file parsable by erp5_test_results
out_file, success, failure, duration, error_title_list = self.processResult( out_file, success, failure, duration = self.processResult(out_file)
out_file)
#tempout = tempfile.mkstemp()[1]
#templog = tempfile.mkstemp()[1]
#log_lines = open(out_file, 'r').readlines()
#tl = open(templog, 'w')
#tl.write(TB_SEP + '\n')
#for log_line in log_lines:
# starts = log_line.startswith
# if starts('Ran') or starts('FAILED') or starts('OK') or starts(TB_SEP):
# continue
# if starts('ERROR: ') or starts('FAIL: '):
# tl.write('internal-test: ' + log_line)
# continue
# tl.write(log_line)
#
#tl.write("----------------------------------------------------------------------\n")
#tl.write('Ran %s test in %.2fs\n' % (test_count, duration))
#if success:
# tl.write('OK\n')
#else:
# tl.write('FAILED (failures=%s)\n' % failure)
#tl.write(TB_SEP + '\n')
# XXX-Cedric : make correct display in test_result_module
tempcmd = tempfile.mkstemp()[1]
tempcmd2 = tempfile.mkstemp()[1]
tempout = tempfile.mkstemp()[1]
templog = tempfile.mkstemp()[1]
tl = open(templog, 'w')
tl.write(TB_SEP + '\n')
tl.write(out_file)
tl.write("----------------------------------------------------------------------\n")
tl.write('Ran 1 test in %.2fs\n' % duration)
if success:
tl.write('OK\n')
else:
tl.write('FAILED (failures=1)\n')
tl.write(TB_SEP + '\n')
tl.close()
open(tempcmd, 'w').write(""" %s""" % self.suite_name)
# create nice zip archive # create nice zip archive
tempzip = tempfile.mkstemp()[1] tempzip = tempfile.mkstemp()[1]
zip = zipfile.ZipFile(tempzip, 'w') zip = zipfile.ZipFile(tempzip, 'w')
zip.write(tempout, '%s/001/stdout' % self.suite_name)
# temperr is dummy zip.write(templog, '%s/001/stderr' % self.suite_name)
temperr = tempfile.mkstemp()[1] zip.write(tempcmd, '%s/001/cmdline' % self.suite_name)
open(temperr, 'w') zip.close()
i = 1 os.unlink(templog)
test_case_list = [dict(name="first", log="OK\n"), dict(name="second", log="FAILED (failures=1)\n")]
for test_case in test_case_list:
tempcmd = tempfile.mkstemp()[1]
tempout = tempfile.mkstemp()[1]
open(tempcmd, 'w').write(test_case['name'])
open(tempout, 'w').write(test_case['log'])
#XXX-Cedric : support cases for more than 9 test cases
zip.write(tempcmd, '%s/00%s/cmdline' % (self.suite_name, i))
zip.write(tempout, '%s/00%s/stderr' % (self.suite_name, i))
zip.write(temperr, '%s/00%s/stdout' % (self.suite_name, i))
os.unlink(tempcmd) os.unlink(tempcmd)
os.unlink(tempout) os.unlink(tempout)
i = i + 1 os.unlink(tempcmd2)
zip.close()
os.unlink(temperr)
# post it to ERP5 # post it to ERP5
self.connection_helper.POST('TestResultModule_reportCompleted', dict( self.connection_helper.POST('TestResultModule_reportCompleted',
test_report_id=self.test_id), dict(test_report_id=self.test_id), file_list=[('filepath', tempzip)])
file_list=[('filepath', tempzip)]
)
import pdb; pdb.set_trace()
os.unlink(tempzip) os.unlink(tempzip)
def processResult(self, out_file): def processResult(self, out_file):
...@@ -189,9 +169,7 @@ class ERP5TestReportHandler: ...@@ -189,9 +169,7 @@ class ERP5TestReportHandler:
failure_amount = TEST_FAILURE_RE.search(file_content).group(1) failure_amount = TEST_FAILURE_RE.search(file_content).group(1)
error_title_list = [re.compile('\s+').sub(' ', x).strip() error_title_list = [re.compile('\s+').sub(' ', x).strip()
for x in TEST_ERROR_TITLE_RE.findall(file_content)] for x in TEST_ERROR_TITLE_RE.findall(file_content)]
# XXX-Cedric : duration duration = DURATION_RE.search(file_content).group(1)
duration = 0
detail = '' detail = ''
for test_result in TEST_RESULT_RE.findall(file_content): for test_result in TEST_RESULT_RE.findall(file_content):
if TEST_ERROR_RESULT_RE.match(test_result): if TEST_ERROR_RESULT_RE.match(test_result):
...@@ -206,6 +184,4 @@ class ERP5TestReportHandler: ...@@ -206,6 +184,4 @@ class ERP5TestReportHandler:
</head> </head>
<body>%s</body> <body>%s</body>
</html>''' % detail </html>''' % detail
return detail, int(sucess_amount), int(failure_amount), float(duration)
return detail, int(sucess_amount), int(failure_amount), duration, \
error_title_list
...@@ -26,9 +26,10 @@ ...@@ -26,9 +26,10 @@
############################################################################# #############################################################################
from erp5functionaltestreporthandler import ERP5TestReportHandler from erp5functionaltestreporthandler import ERP5TestReportHandler
from ERP5TypeFunctionalTestCase import Xvfb, Firefox, TimeoutError
from time import sleep from time import sleep
import time
import os import os
from subprocess import Popen, PIPE
import urllib2 import urllib2
def run(args): def run(args):
...@@ -37,6 +38,9 @@ def run(args): ...@@ -37,6 +38,9 @@ def run(args):
test_url = assembleTestUrl(config['base_url'], config['suite_name'], test_url = assembleTestUrl(config['base_url'], config['suite_name'],
config['user'], config['password']) config['user'], config['password'])
# There is no test that can take more them 24 hours
timeout = 2.0 * 60 * 60
while True: while True:
erp5_report = ERP5TestReportHandler(config['test_suite_master_url'], erp5_report = ERP5TestReportHandler(config['test_suite_master_url'],
config['project'] + '@' + config['suite_name']) config['project'] + '@' + config['suite_name'])
...@@ -45,32 +49,46 @@ def run(args): ...@@ -45,32 +49,46 @@ def run(args):
config['base_url'], config['user'], config['password'])) config['base_url'], config['user'], config['password']))
# TODO assert getresult is None # TODO assert getresult is None
#XXX-Cedric : clean firefox data (so that it does not load previous session)
#xvfb = Popen([config['xvfb_binary'], config['display']], stdout=PIPE) #xvfb = Popen([config['xvfb_binary'], config['display']], stdout=PIPE)
#os.environ['DISPLAY'] = config['display'] #os.environ['DISPLAY'] = config['display']
#sleep(10) #sleep(10)
#
command = [] #command = []
command.append(config['browser_binary']) #command.append(config['browser_binary'])
for browser_argument in config['browser_argument_list']: #for browser_argument in config['browser_argument_list']:
command.append(browser_argument) # command.append(browser_argument)
command.append(test_url) #command.append(test_url)
browser = Popen(command, stdout=PIPE) #browser = Popen(command, stdout=PIPE)
#
#erp5_report.reportStart()
#
## Wait for test to be finished
#while getStatus(config['base_url']) is '':
# sleep(10)
os.environ['DISPLAY'] = config['display']
xvfb = Xvfb(config['xvfb_binary'], config['etc_directory'])
profile_dir = os.path.join(config['etc_directory'], 'profile')
browser = Firefox(config['browser_binary'], profile_dir, config['base_url'])
try:
start = time.time()
xvfb.run()
profile_dir = os.path.join(config['etc_directory'], 'profile')
browser.run(test_url , xvfb.display)
erp5_report.reportStart() erp5_report.reportStart()
# Wait for test to be finished
while getStatus(config['base_url']) is '': while getStatus(config['base_url']) is '':
sleep(1) #10 time.sleep(10)
if (time.time() - start) > float(timeout):
import pdb; pdb.set_trace() raise TimeoutError("Test took more them %s seconds" % timeout)
except TimeoutError:
continue
finally:
browser.quit()
xvfb.quit()
erp5_report.reportFinished(getStatus(config['base_url']).encode("utf-8", erp5_report.reportFinished(getStatus(config['base_url']).encode("utf-8",
"replace")) "replace"))
browser.kill()
#terminateXvfb(xvfb, config['display'])
print("Test finished and report sent, sleeping.") print("Test finished and report sent, sleeping.")
sleep(3600) sleep(3600)
...@@ -108,8 +126,8 @@ def assembleTestUrl(base_url, suite_name, user, password): ...@@ -108,8 +126,8 @@ def assembleTestUrl(base_url, suite_name, user, password):
base_url, suite_name, base_url, user, password) base_url, suite_name, base_url, user, password)
return test_url return test_url
def terminateXvfb(process, display): #def terminateXvfb(process, display):
process.kill() # process.kill()
lock_filepath = '/tmp/.X%s-lock' % display.replace(":", "") # lock_filepath = '/tmp/.X%s-lock' % display.replace(":", "")
if os.path.exists(lock_filepath): # if os.path.exists(lock_filepath):
os.system('rm %s' % lock_filepath) # os.system('rm %s' % lock_filepath)
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