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
Labels
Merge Requests
138
Merge Requests
138
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
Jobs
Commits
Open sidebar
nexedi
erp5
Commits
3798990c
Commit
3798990c
authored
Mar 31, 2017
by
Vincent Bechu
Committed by
Klaus Wölfel
Sep 07, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ERP5Type/tests: process test result with xml parser
parent
0ed32340
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
36 deletions
+49
-36
product/ERP5Type/tests/ERP5TypeFunctionalTestCase.py
product/ERP5Type/tests/ERP5TypeFunctionalTestCase.py
+49
-36
No files found.
product/ERP5Type/tests/ERP5TypeFunctionalTestCase.py
View file @
3798990c
...
@@ -40,21 +40,13 @@ from zExceptions.ExceptionFormatter import format_exception
...
@@ -40,21 +40,13 @@ from zExceptions.ExceptionFormatter import format_exception
from
Products.ERP5Type.tests.ERP5TypeTestCase
import
ERP5TypeTestCase
,
\
from
Products.ERP5Type.tests.ERP5TypeTestCase
import
ERP5TypeTestCase
,
\
_getConversionServerDict
_getConversionServerDict
from
Products.ERP5Type.Utils
import
stopProcess
,
PR_SET_PDEATHSIG
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
import
webdriver
from
selenium.webdriver.common.by
import
By
from
selenium.webdriver.common.by
import
By
from
selenium.webdriver.support.ui
import
WebDriverWait
from
selenium.webdriver.support.ui
import
WebDriverWait
from
selenium.webdriver.support
import
expected_conditions
as
EC
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"
ZELENIUM_BASE_URL
=
"%s/portal_tests/%s/core/TestRunner.html?test=../test_suite_html&auto=on&resultsUrl=../postResults&__ac_name=%s&__ac_password=%s"
...
@@ -162,8 +154,10 @@ class FunctionalTestRunner:
...
@@ -162,8 +154,10 @@ class FunctionalTestRunner:
firefox_driver
=
firefox_bin
.
replace
(
"firefox-slapos"
,
"geckodriver"
)
firefox_driver
=
firefox_bin
.
replace
(
"firefox-slapos"
,
"geckodriver"
)
firefox_capabilities
=
webdriver
.
common
.
desired_capabilities
.
DesiredCapabilities
.
FIREFOX
firefox_capabilities
=
webdriver
.
common
.
desired_capabilities
.
DesiredCapabilities
.
FIREFOX
firefox_capabilities
[
'marionette'
]
=
True
firefox_capabilities
[
'marionette'
]
=
True
firefox_capabilities['
binary
'] = firefox_bin
browser
=
webdriver
.
Firefox
(
browser = webdriver.Firefox(capabilities=firefox_capabilities, executable_path=firefox_driver)
capabilities
=
firefox_capabilities
,
executable_path
=
firefox_driver
,
firefox_binary
=
FirefoxBinary
(
firefox_bin
))
start_time
=
time
.
time
()
start_time
=
time
.
time
()
browser
.
get
(
self
.
_getTestURL
())
browser
.
get
(
self
.
_getTestURL
())
...
@@ -179,30 +173,49 @@ class FunctionalTestRunner:
...
@@ -179,30 +173,49 @@ class FunctionalTestRunner:
WebDriverWait
(
browser
,
self
.
timeout
).
until
(
EC
.
presence_of_element_located
((
WebDriverWait
(
browser
,
self
.
timeout
).
until
(
EC
.
presence_of_element_located
((
By
.
XPATH
,
'//td[@id="testRuns" and contains(text(), "%i")]'
%
test_count
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
:
finally
:
xvfb
.
quit
()
xvfb
.
quit
()
return
iframe
def processResult(self):
file_content = self.getStatus().encode("utf-8", "replace")
def
processResult
(
self
,
iframe
):
sucess_amount = int(TEST_PASS_RE.search(file_content).group(1))
tbody
=
iframe
.
xpath
(
'.//body/table/tbody'
)[
0
]
failure_amount = int(TEST_FAILURE_RE.search(file_content).group(1))
tr_count
=
failure_amount
=
expected_failure_amount
=
0
error_title_list = [re.compile('
\
s
+
').sub('
', x).strip()
error_title_list
=
[]
for x in TEST_ERROR_TITLE_RE.findall(file_content)]
detail
=
""
for
tr
in
tbody
:
is_expected_failure = lambda x: EXPECTED_FAILURE_RE.match(x)
if
tr_count
:
expected_failure_amount = len(filter(is_expected_failure, error_title_list))
# First td is the main title
# Remove expected failures from list
test_name
=
tr
[
0
][
0
].
text
error_title_list = filter(lambda x: not is_expected_failure(x), error_title_list)
error
=
False
failure_amount -= expected_failure_amount
if
len
(
tr
)
==
1
:
# Test was not executed
detail = ''
failure
+=
1
for test_result in TEST_RESULT_RE.findall(file_content):
detail
+=
'Test '
+
test_name
+
' not executed'
if TEST_ERROR_RESULT_RE.match(test_result):
error_title_list
.
append
(
test_name
)
detail += test_result
else
:
test_table
=
tr
[
1
].
xpath
(
'.//table'
)[
0
]
detail = IMAGE_RE.sub('', detail)
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
if
detail
:
if
detail
:
detail = IMAGE_RE.sub('', detail)
detail
=
'''<html>
detail
=
'''<html>
<head>
<head>
<style type="text/css">tr.status_failed { background-color:red };</style>
<style type="text/css">tr.status_failed { background-color:red };</style>
...
@@ -292,7 +305,7 @@ class ERP5TypeFunctionalTestCase(ERP5TypeTestCase):
...
@@ -292,7 +305,7 @@ class ERP5TypeFunctionalTestCase(ERP5TypeTestCase):
debug
=
self
.
foreground
or
os
.
environ
.
get
(
"erp5_debug_mode"
)
debug
=
self
.
foreground
or
os
.
environ
.
get
(
"erp5_debug_mode"
)
error
=
None
error
=
None
try
:
try
:
self.runner.test(debug=debug)
iframe
=
self
.
runner
.
test
(
debug
=
debug
)
except
TimeoutError
,
e
:
except
TimeoutError
,
e
:
error
=
repr
(
e
)
error
=
repr
(
e
)
self
.
_verboseErrorLog
(
20
)
self
.
_verboseErrorLog
(
20
)
...
@@ -304,7 +317,7 @@ class ERP5TypeFunctionalTestCase(ERP5TypeTestCase):
...
@@ -304,7 +317,7 @@ class ERP5TypeFunctionalTestCase(ERP5TypeTestCase):
self
.
_verboseErrorLog
(
20
)
self
.
_verboseErrorLog
(
20
)
detail
,
success
,
failure
,
\
detail
,
success
,
failure
,
\
expected_failure, error_title_list = self.runner.processResult()
expected_failure
,
error_title_list
=
self
.
runner
.
processResult
(
iframe
)
self
.
logMessage
(
"-"
*
79
)
self
.
logMessage
(
"-"
*
79
)
total
=
success
+
failure
+
expected_failure
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