Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Laurent S
erp5
Commits
303caa3b
Commit
303caa3b
authored
May 11, 2017
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "ERP5Type/tests: process test result with xml parser"
This reverts commit
814afaf3
.
parent
bbd34edd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
49 deletions
+36
-49
product/ERP5Type/tests/ERP5TypeFunctionalTestCase.py
product/ERP5Type/tests/ERP5TypeFunctionalTestCase.py
+36
-49
No files found.
product/ERP5Type/tests/ERP5TypeFunctionalTestCase.py
View file @
303caa3b
...
...
@@ -40,13 +40,21 @@ from zExceptions.ExceptionFormatter import format_exception
from
Products.ERP5Type.tests.ERP5TypeTestCase
import
ERP5TypeTestCase
,
\
_getConversionServerDict
from
Products.ERP5Type.Utils
import
stopProcess
,
PR_SET_PDEATHSIG
from
lxml
import
etree
from
lxml.html
import
builder
as
E
from
selenium
import
webdriver
from
selenium.webdriver.common.by
import
By
from
selenium.webdriver.support.ui
import
WebDriverWait
from
selenium.webdriver.support
import
expected_conditions
as
EC
from
selenium.webdriver.firefox.firefox_binary
import
FirefoxBinary
# REGEX FOR ZELENIUM TESTS
TEST_PASS_RE
=
re
.
compile
(
'<th[^>]*>Tests passed</th>
\
n
\
s*<
t
d[^>]*>([^<]*)'
)
TEST_FAILURE_RE
=
re
.
compile
(
'<th[^>]*>Tests failed</th>
\
n
\
s*<
t
d[^>]*>([^<]*)'
)
IMAGE_RE
=
re
.
compile
(
'<img[^>]*?>'
)
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*'
'<img.*?</div>
\
s.*?</di
v
>
\
s*
'
, re.S)
TEST_ERROR_RESULT_RE = re.compile('
.
*
(
?
:
error
.
gif
|
title
status_failed
).
*
', re.S)
EXPECTED_FAILURE_RE = re.compile('
.
*
expected
failure
.
*
', re.I)
ZELENIUM_BASE_URL = "%s/portal_tests/%s/core/TestRunner.html?test=../test_suite_html&auto=on&resultsUrl=../postResults&__ac_name=%s&__ac_password=%s"
...
...
@@ -155,10 +163,8 @@ class FunctionalTestRunner:
firefox_driver = firefox_bin.replace("firefox-slapos", "geckodriver")
firefox_capabilities = webdriver.common.desired_capabilities.DesiredCapabilities.FIREFOX
firefox_capabilities['
marionette
'] = True
browser
=
webdriver
.
Firefox
(
capabilities
=
firefox_capabilities
,
executable_path
=
firefox_driver
,
firefox_binary
=
FirefoxBinary
(
firefox_bin
))
firefox_capabilities['
binary
'] = firefox_bin
browser = webdriver.Firefox(capabilities=firefox_capabilities, executable_path=firefox_driver)
start_time = time.time()
browser.get(self._getTestURL())
...
...
@@ -174,49 +180,30 @@ class FunctionalTestRunner:
WebDriverWait(browser, self.timeout).until(EC.presence_of_element_located((
By.XPATH, '
//
td
[
@
id
=
"testRuns"
and
contains
(
text
(),
"%i"
)]
' % test_count
)))
self
.
execution_duration
=
round
(
time
.
time
()
-
start_time
,
2
)
html_parser
=
etree
.
HTMLParser
(
recover
=
True
)
iframe
=
etree
.
fromstring
(
browser
.
execute_script
(
"return document.getElementById('testSuiteFrame').contentDocument.querySelector('html').innerHTML"
).
encode
(
'UTF-8'
),
html_parser
)
browser
.
quit
()
finally:
xvfb.quit()
return
iframe
def
processResult
(
self
,
iframe
):
tbody
=
iframe
.
xpath
(
'.//body/table/tbody'
)[
0
]
tr_count
=
failure_amount
=
expected_failure_amount
=
0
error_title_list
=
[]
detail
=
""
for
tr
in
tbody
:
if
tr_count
:
# First td is the main title
test_name
=
tr
[
0
][
0
].
text
error
=
False
if
len
(
tr
)
==
1
:
# Test was not executed
failure
+=
1
detail
+=
'Test '
+
test_name
+
' not executed'
error_title_list
.
append
(
test_name
)
else
:
test_table
=
tr
[
1
].
xpath
(
'.//table'
)[
0
]
status
=
tr
.
attrib
.
get
(
'class'
)
if
'status_failed'
in
status
:
if
etree
.
tostring
(
test_table
).
find
(
"expected failure"
)
!=
-
1
:
expected_failure_amount
+=
1
else
:
failure_amount
+=
1
error_title_list
.
append
(
test_name
)
detail_element
=
E
.
DIV
()
detail_element
.
append
(
E
.
DIV
(
E
.
P
(
test_name
),
E
.
BR
,
test_table
))
detail
+=
etree
.
tostring
(
detail_element
)
tr_count
+=
1
sucess_amount
=
tr_count
-
1
-
failure_amount
-
expected_failure_amount
def processResult(self):
file_content = self.getStatus().encode("utf-8", "replace")
sucess_amount = int(TEST_PASS_RE.search(file_content).group(1))
failure_amount = int(TEST_FAILURE_RE.search(file_content).group(1))
error_title_list = [re.compile('
\
s
+
').sub('
', x).strip()
for x in TEST_ERROR_TITLE_RE.findall(file_content)]
is_expected_failure = lambda x: EXPECTED_FAILURE_RE.match(x)
expected_failure_amount = len(filter(is_expected_failure, error_title_list))
# Remove expected failures from list
error_title_list = filter(lambda x: not is_expected_failure(x), error_title_list)
failure_amount -= expected_failure_amount
detail = ''
for test_result in TEST_RESULT_RE.findall(file_content):
if TEST_ERROR_RESULT_RE.match(test_result):
detail += test_result
detail = IMAGE_RE.sub('', detail)
if detail:
detail = IMAGE_RE.sub('', detail)
detail = '''<html>
<head>
<style type="text/css">tr.status_failed { background-color:red };</style>
...
...
@@ -307,7 +294,7 @@ class ERP5TypeFunctionalTestCase(ERP5TypeTestCase):
debug = self.foreground or os.environ.get("erp5_debug_mode")
error = None
try:
iframe
=
self
.
runner
.
test
(
debug
=
debug
)
self.runner.test(debug=debug)
except TimeoutError, e:
error = repr(e)
self._verboseErrorLog(20)
...
...
@@ -319,7 +306,7 @@ class ERP5TypeFunctionalTestCase(ERP5TypeTestCase):
self._verboseErrorLog(20)
detail, success, failure,
\
expected_failure
,
error_title_list
=
self
.
runner
.
processResult
(
iframe
)
expected_failure, error_title_list = self.runner.processResult()
self.logMessage("-" * 79)
total = success + failure + expected_failure
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment